-
Notifications
You must be signed in to change notification settings - Fork 83
[typespec-go] add go spector test cases #5017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kazrael2119
wants to merge
3
commits into
Azure:main
Choose a base branch
from
kazrael2119:add-go-spector-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: internal | ||
| packages: | ||
| - "@azure-tools/typespec-go" | ||
| --- | ||
|
|
||
| [typespec-go] add go spector test cases |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...tp-specs/azure/client-generator-core/clientdocgroup/clientdocdocumentation_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
20 changes: 20 additions & 0 deletions
20
...e-http-specs/azure/client-generator-core/exactnamegroup/exactnameenumvalue_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
20 changes: 20 additions & 0 deletions
20
...azure-http-specs/azure/client-generator-core/exactnamegroup/exactnamemodel_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
19 changes: 19 additions & 0 deletions
19
...e-http-specs/azure/client-generator-core/exactnamegroup/exactnameoperation_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
19 changes: 19 additions & 0 deletions
19
...e-http-specs/azure/client-generator-core/exactnamegroup/exactnameparameter_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
20 changes: 20 additions & 0 deletions
20
...re-http-specs/azure/client-generator-core/exactnamegroup/exactnameproperty_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
58 changes: 58 additions & 0 deletions
58
.../azure/resource-manager/managementgroupgroup/managementgroupchildresources_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
41 changes: 41 additions & 0 deletions
41
...pespec-go/test/azure-http-specs/azure/resource-manager/managementgroupgroup/utils_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } |
54 changes: 54 additions & 0 deletions
54
...zure-http-specs/azure/special-headers/azurecondreqgroup/conditionalrequest_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
28 changes: 28 additions & 0 deletions
28
packages/typespec-go/test/http-specs/encode/durationgroup/lossy_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
25 changes: 25 additions & 0 deletions
25
packages/typespec-go/test/http-specs/parameters/bodyrootgroup/bodyroot_client_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's should be an emitter issue, please also comment out this line