Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .chronus/changes/add-go-spector-test-2026-6-22-8-25-18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
Comment thread
kazrael2119 marked this conversation as resolved.
Outdated
Comment thread
kazrael2119 marked this conversation as resolved.
Outdated
packages:
- "@azure-tools/typespec-go"
---

[typespec-go] add go spector test cases
8 changes: 8 additions & 0 deletions packages/typespec-go/.scripts/tspcompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ const httpSpecsGroup = {
customgroup: ["authentication/http/custom"],
oauth2group: ["authentication/oauth2"],
unionauthgroup: ["authentication/union"],
// booleangroup: ["encode/boolean"], // emitter bug: @encode(string) on boolean is ignored; bool is serialized as a JSON boolean instead of a string, so the mock rejects the body
bytesgroup: ["encode/bytes"],
datetimegroup: ["encode/datetime", "slice-elements-byval=true"],
durationgroup: ["encode/duration"],
numericgroup: ["encode/numeric"],
basicparamsgroup: ["parameters/basic"],
bodyoptionalgroup: ["parameters/body-optionality"],
bodyrootgroup: ["parameters/body-root"],
collectionfmtgroup: ["parameters/collection-format"],
pathgroup: ["parameters/path"],
querygroup: ["parameters/query"],
spreadgroup: ["parameters/spread"],
contentneggroup: ["payload/content-negotiation"],
//'headgroup': ['payload/head'], // emitter error: unexpected kind string for HeaderMapResponse metadata (HEAD op returning response headers)
jmergepatchgroup: ["payload/json-merge-patch"],
mediatypegroup: ["payload/media-type"],
multipartgroup: ["payload/multipart"],
Expand Down Expand Up @@ -92,10 +95,13 @@ const httpSpecsGroup = {
const azureHttpSpecsGroup = {
accessgroup: ["azure/client-generator-core/access"],
//'alternatetypegroup': ['azure/client-generator-core/alternate-type'],
clientdocgroup: ["azure/client-generator-core/client-doc"],
defaultvaluegroup: ["azure/client-generator-core/client-default-value"],
emptystringgroup: ["azure/client-generator-core/deserialize-empty-string-as-null"],
exactnamegroup: ["azure/client-generator-core/exact-name", "generate-fakes=false"], // fakes reference an unexported model (my_model), so fake generation is disabled for this scenario
Comment thread
kazrael2119 marked this conversation as resolved.
Outdated
flattengroup: ["azure/client-generator-core/flatten-property"],
nextlinkverbgroup: ["azure/client-generator-core/next-link-verb", "slice-elements-byval=true"],
//'responseasboolgroup': ['azure/client-generator-core/response-as-bool'], // emitter error: didn't find HTTP response for kind boolean (@responseAsBool on HEAD)
coreusagegroup: ["azure/client-generator-core/usage"],
overridegroup: ["azure/client-generator-core/override/client.tsp"],
hierarchygroup: ["azure/client-generator-core/hierarchy-building"],
Expand Down Expand Up @@ -135,9 +141,11 @@ const azureHttpSpecsGroup = {
nonresourcegroup: ["azure/resource-manager/non-resource"],
templatesgroup: ["azure/resource-manager/operation-templates"],
largeheadergroup: ["azure/resource-manager/large-header"],
managementgroupgroup: ["azure/resource-manager/management-group"],
methodsubscriptionidgroup: ["/azure/resource-manager/method-subscription-id/client.tsp"],
armmultipleservicegroup: ["/azure/resource-manager/multi-service/client.tsp"],
armmultisharedmodelsgroup: ["/azure/resource-manager/multi-service-shared-models/client.tsp"],
azurecondreqgroup: ["azure/special-headers/conditional-request"],
xmsclientreqidgroup: ["azure/special-headers/client-request-id"],
previewversiongroup: ["azure/versioning/previewVersion", "api-version=2024-12-01-preview"],
previewversiongroupspecificversion: ["azure/versioning/previewVersion", "api-version=2024-06-01"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package clientdocgroup_test

import (
"clientdocgroup"
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestClientDocDocumentationClient_Harvest(t *testing.T) {
client, err := clientdocgroup.NewClientDocClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewClientDocDocumentationClient().Harvest(context.Background(), clientdocgroup.Plant{
Name: to.Ptr("Rose"),
Species: to.Ptr("Rosa"),
}, nil)
require.NoError(t, err)
require.Equal(t, to.Ptr("Rose"), resp.Name)
require.Equal(t, to.Ptr("Rosa"), resp.Species)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package exactnamegroup

import (
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestExactNameEnumValueClient_Send(t *testing.T) {
client, err := NewExactNameClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewExactNameEnumValueClient().Send(context.Background(), EndpointConfig{Protocol: to.Ptr(AgentEndpointProtocolA2A)}, nil)
require.NoError(t, err)
require.Equal(t, to.Ptr(AgentEndpointProtocolA2A), resp.Protocol)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package exactnamegroup

import (
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestExactNameModelClient_Send(t *testing.T) {
client, err := NewExactNameClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewExactNameModelClient().Send(context.Background(), my_model{Name: to.Ptr("test")}, nil)
require.NoError(t, err)
require.Equal(t, to.Ptr("test"), resp.Name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package exactnamegroup

import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

func TestExactNameOperationClient_MyOp(t *testing.T) {
client, err := NewExactNameClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewExactNameOperationClient().myOp(context.Background(), nil)
require.NoError(t, err)
require.Zero(t, resp)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package exactnamegroup

import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

func TestExactNameParameterClient_Send(t *testing.T) {
client, err := NewExactNameClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewExactNameParameterClient().Send(context.Background(), "hello", nil)
require.NoError(t, err)
require.Zero(t, resp)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package exactnamegroup

import (
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestExactNamePropertyClient_Send(t *testing.T) {
client, err := NewExactNameClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewExactNamePropertyClient().Send(context.Background(), ScopedModel{_MyName: to.Ptr("test")}, nil)
require.NoError(t, err)
require.Equal(t, to.Ptr("test"), resp._MyName)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package managementgroupgroup

import (
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestManagementGroupChildResourcesClient_Get(t *testing.T) {
resp, err := clientFactory.NewManagementGroupChildResourcesClient().Get(ctx, managementGroupIDExpected, resourceNameExpected, nil)
require.NoError(t, err)
require.Equal(t, resourceNameExpected, *resp.Name)
require.Equal(t, "valid", *resp.Properties.Description)
require.Equal(t, ProvisioningStateSucceeded, *resp.Properties.ProvisioningState)
}

func TestManagementGroupChildResourcesClient_CreateOrUpdate(t *testing.T) {
poller, err := clientFactory.NewManagementGroupChildResourcesClient().BeginCreateOrUpdate(ctx, managementGroupIDExpected, resourceNameExpected, ManagementGroupChildResource{
Properties: &ManagementGroupChildResourceProperties{
Description: to.Ptr("valid"),
},
}, nil)
require.NoError(t, err)
resp, err := poller.PollUntilDone(ctx, nil)
require.NoError(t, err)
require.Equal(t, resourceNameExpected, *resp.Name)
require.Equal(t, "valid", *resp.Properties.Description)
}

func TestManagementGroupChildResourcesClient_Update(t *testing.T) {
resp, err := clientFactory.NewManagementGroupChildResourcesClient().Update(ctx, managementGroupIDExpected, resourceNameExpected, ManagementGroupChildResource{
Properties: &ManagementGroupChildResourceProperties{
Description: to.Ptr("valid2"),
},
}, nil)
require.NoError(t, err)
require.Equal(t, "valid2", *resp.Properties.Description)
}

func TestManagementGroupChildResourcesClient_Delete(t *testing.T) {
resp, err := clientFactory.NewManagementGroupChildResourcesClient().Delete(ctx, managementGroupIDExpected, resourceNameExpected, nil)
require.NoError(t, err)
require.Zero(t, resp)
}

func TestManagementGroupChildResourcesClient_ListByManagementGroup(t *testing.T) {
pager := clientFactory.NewManagementGroupChildResourcesClient().NewListByManagementGroupPager(managementGroupIDExpected, nil)
require.True(t, pager.More())
page, err := pager.NextPage(ctx)
require.NoError(t, err)
require.Len(t, page.Value, 1)
require.Equal(t, resourceNameExpected, *page.Value[0].Name)
require.Equal(t, "valid", *page.Value[0].Properties.Description)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package managementgroupgroup

import (
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake"
)

var (
ctx context.Context
clientFactory *ClientFactory

managementGroupIDExpected = "test-mg"
resourceNameExpected = "resource"
)

func TestMain(m *testing.M) {
ctx = context.Background()
clientFactory, _ = NewClientFactory(&azfake.TokenCredential{}, &arm.ClientOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloud.Configuration{
Services: map[cloud.ServiceName]cloud.ServiceConfiguration{
cloud.ResourceManager: {
Audience: "fake_audience",
Endpoint: "http://localhost:3000",
},
},
},
InsecureAllowCredentialWithHTTP: true,
},
})

m.Run()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package azurecondreqgroup_test

import (
"azurecondreqgroup"
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestConditionalRequestClient_PostIfMatch(t *testing.T) {
client, err := azurecondreqgroup.NewConditionalRequestClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.PostIfMatch(context.Background(), &azurecondreqgroup.ConditionalRequestClientPostIfMatchOptions{
IfMatch: to.Ptr(azcore.ETag(`"valid"`)),
})
require.NoError(t, err)
require.Zero(t, resp)
}

func TestConditionalRequestClient_PostIfNoneMatch(t *testing.T) {
client, err := azurecondreqgroup.NewConditionalRequestClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.PostIfNoneMatch(context.Background(), &azurecondreqgroup.ConditionalRequestClientPostIfNoneMatchOptions{
IfNoneMatch: to.Ptr(azcore.ETag(`"invalid"`)),
})
require.NoError(t, err)
require.Zero(t, resp)
}

func TestConditionalRequestClient_PostCustomIfMatch(t *testing.T) {
client, err := azurecondreqgroup.NewConditionalRequestClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.PostCustomIfMatch(context.Background(), &azurecondreqgroup.ConditionalRequestClientPostCustomIfMatchOptions{
IfMatch: to.Ptr(azcore.ETag(`"valid"`)),
})
require.NoError(t, err)
require.Zero(t, resp)
}

func TestConditionalRequestClient_PostCustomIfNoneMatch(t *testing.T) {
client, err := azurecondreqgroup.NewConditionalRequestClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.PostCustomIfNoneMatch(context.Background(), &azurecondreqgroup.ConditionalRequestClientPostCustomIfNoneMatchOptions{
IfNoneMatch: to.Ptr(azcore.ETag(`"invalid"`)),
})
require.NoError(t, err)
require.Zero(t, resp)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package durationgroup_test

import (
"context"
"durationgroup"
"testing"

"github.com/stretchr/testify/require"
)

func TestLossyClientIntSeconds(t *testing.T) {
client, err := durationgroup.NewDurationClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewDurationLossyClient().IntSeconds(context.Background(), 36, nil)
require.NoError(t, err)
require.Zero(t, resp)
}

func TestLossyClientIntMilliseconds(t *testing.T) {
client, err := durationgroup.NewDurationClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.NewDurationLossyClient().IntMilliseconds(context.Background(), 36250, nil)
require.NoError(t, err)
require.Zero(t, resp)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package bodyrootgroup_test

import (
"bodyrootgroup"
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/stretchr/testify/require"
)

func TestBodyRootClient_Nested(t *testing.T) {
client, err := bodyrootgroup.NewBodyRootClientWithNoCredential("http://localhost:3000", nil)
require.NoError(t, err)
resp, err := client.Nested(context.Background(), bodyrootgroup.BodyRootModel{
Category: to.Ptr("widget"),
LinkType: to.Ptr("hard"),
WasSuccessful: to.Ptr(true),
}, nil)
require.NoError(t, err)
require.Zero(t, resp)
}
Loading
Loading