diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 500a17566..dd9e6e56e 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -210,14 +210,14 @@ importers: version: 0.5.21 devDependencies: '@azure-tools/cadl-ranch': - specifier: ~0.15.0 - version: 0.15.0(@typespec/versioning@0.61.0) + specifier: ~0.16.0 + version: 0.16.0(@typespec/versioning@0.61.0) '@azure-tools/cadl-ranch-expect': specifier: ~0.15.5 version: 0.15.5(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0) '@azure-tools/cadl-ranch-specs': - specifier: 0.38.0 - version: 0.38.0(@azure-tools/cadl-ranch-expect@0.15.5)(@azure-tools/typespec-azure-core@0.47.0)(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0)(@typespec/xml@0.61.0) + specifier: 0.39.0 + version: 0.39.0(@azure-tools/cadl-ranch-expect@0.15.5)(@azure-tools/typespec-azure-core@0.47.0)(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0)(@typespec/xml@0.61.0) '@azure-tools/typespec-autorest': specifier: '>=0.47.0 <1.0.0' version: 0.47.0(@azure-tools/typespec-azure-core@0.47.0)(@azure-tools/typespec-azure-resource-manager@0.47.1)(@azure-tools/typespec-client-generator-core@0.47.4)(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/openapi@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0) @@ -423,8 +423,8 @@ packages: '@typespec/versioning': 0.61.0(@typespec/compiler@0.61.2) dev: true - /@azure-tools/cadl-ranch-specs@0.38.0(@azure-tools/cadl-ranch-expect@0.15.5)(@azure-tools/typespec-azure-core@0.47.0)(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0)(@typespec/xml@0.61.0): - resolution: {integrity: sha512-AbOpERFpxYGmfFcSxDQl7ZeBy6FHEWFgqqw8FBRaugtVbeAj9BfUOPfc/OSEGNQmEIrzZJpH1N974JqhmKtKYg==} + /@azure-tools/cadl-ranch-specs@0.39.0(@azure-tools/cadl-ranch-expect@0.15.5)(@azure-tools/typespec-azure-core@0.47.0)(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0)(@typespec/xml@0.61.0): + resolution: {integrity: sha512-twJYI4Bj8Me+5Cll5LbeF9WXFJah/ry6oNgTXAdz/77BiXwS/oSu33SUJUo1P3ZKiqnQEyGWSkyMCVxEM+7GJw==} engines: {node: '>=16.0.0'} peerDependencies: '@azure-tools/cadl-ranch-expect': ~0.15.5 @@ -435,7 +435,7 @@ packages: '@typespec/versioning': ~0.61.0 '@typespec/xml': ~0.61.0 dependencies: - '@azure-tools/cadl-ranch': 0.15.0(@typespec/versioning@0.61.0) + '@azure-tools/cadl-ranch': 0.16.0(@typespec/versioning@0.61.0) '@azure-tools/cadl-ranch-api': 0.5.0 '@azure-tools/cadl-ranch-expect': 0.15.5(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0)(@typespec/versioning@0.61.0) '@azure-tools/typespec-azure-core': 0.47.0(@typespec/compiler@0.61.2)(@typespec/http@0.61.0)(@typespec/rest@0.61.0) @@ -451,8 +451,8 @@ packages: - supports-color dev: true - /@azure-tools/cadl-ranch@0.15.0(@typespec/versioning@0.61.0): - resolution: {integrity: sha512-RU8AktXgCW7tuZF5yE2JCQdqY51qp5YJ8bvF82/M1tNwkN8GTxSXde3rBMyYnXJRd/DQUxaCqFMbwX1MgFBWFA==} + /@azure-tools/cadl-ranch@0.16.0(@typespec/versioning@0.61.0): + resolution: {integrity: sha512-/+gzNzL9/mPm4SH+euuq9cX6Hnnbcz2xywtwFm3j6uiMHzFn5n9lm6ls9s0Mw2691sjVQ9Idokmb65wmQbkYmg==} engines: {node: '>=16.0.0'} hasBin: true dependencies: diff --git a/packages/typespec-go/.scripts/tspcompile.js b/packages/typespec-go/.scripts/tspcompile.js index 3b2579eb0..20c07a0ca 100644 --- a/packages/typespec-go/.scripts/tspcompile.js +++ b/packages/typespec-go/.scripts/tspcompile.js @@ -29,7 +29,7 @@ const cadlRanch = { 'azurepagegroup': ['azure/core/page'], 'corescalargroup': ['azure/core/scalar'], 'commonpropsgroup': ['azure/resource-manager/common-properties'], - //'resources': ['azure/resource-manager/models/resources'], // TODO: https://github.com/Azure/typespec-azure/issues/1709 + 'resources': ['azure/resource-manager/resources'], //'traitsgroup': ['azure/core/traits'], // requires union support 'xmsclientreqidgroup': ['azure/special-headers/client-request-id'], 'naminggroup': ['client/naming'], diff --git a/packages/typespec-go/package.json b/packages/typespec-go/package.json index d9d225576..fcc5a8f8a 100644 --- a/packages/typespec-go/package.json +++ b/packages/typespec-go/package.json @@ -46,9 +46,9 @@ "homepage": "https://github.com/Azure/autorest.go#readme", "readme": "https://github.com/Azure/autorest.go/blob/main/readme.md", "devDependencies": { - "@azure-tools/cadl-ranch": "~0.15.0", + "@azure-tools/cadl-ranch": "~0.16.0", "@azure-tools/cadl-ranch-expect": "~0.15.5", - "@azure-tools/cadl-ranch-specs": "0.38.0", + "@azure-tools/cadl-ranch-specs": "0.39.0", "@azure-tools/typespec-autorest": ">=0.47.0 <1.0.0", "@azure-tools/typespec-azure-core": ">=0.47.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.47.0 <1.0.0", diff --git a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/internaloperation_client_test.go b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/internaloperation_client_test.go index 718903806..dccaadd1a 100644 --- a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/internaloperation_client_test.go +++ b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/internaloperation_client_test.go @@ -14,29 +14,29 @@ import ( func TestInternalOperationClient_internalDecoratorInInternal(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessInternalOperationClient().internalDecoratorInInternal(context.Background(), "foo", nil) + resp, err := client.NewAccessInternalOperationClient().internalDecoratorInInternal(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, internalDecoratorModelInInternal{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.internalDecoratorModelInInternal) } func TestInternalOperationClient_noDecoratorInInternal(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessInternalOperationClient().noDecoratorInInternal(context.Background(), "foo", nil) + resp, err := client.NewAccessInternalOperationClient().noDecoratorInInternal(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, noDecoratorModelInInternal{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.noDecoratorModelInInternal) } func TestInternalOperationClient_publicDecoratorInInternal(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessInternalOperationClient().publicDecoratorInInternal(context.Background(), "foo", nil) + resp, err := client.NewAccessInternalOperationClient().publicDecoratorInInternal(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, PublicDecoratorModelInInternal{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.PublicDecoratorModelInInternal) } diff --git a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/publicoperation_client_test.go b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/publicoperation_client_test.go index 138f1aa3c..6b1a466e0 100644 --- a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/publicoperation_client_test.go +++ b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/publicoperation_client_test.go @@ -14,19 +14,19 @@ import ( func TestPublicOperationClient_NoDecoratorInPublic(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessPublicOperationClient().NoDecoratorInPublic(context.Background(), "foo", nil) + resp, err := client.NewAccessPublicOperationClient().NoDecoratorInPublic(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, NoDecoratorModelInPublic{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.NoDecoratorModelInPublic) } func TestPublicOperationClient_PublicDecoratorInPublic(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessPublicOperationClient().PublicDecoratorInPublic(context.Background(), "foo", nil) + resp, err := client.NewAccessPublicOperationClient().PublicDecoratorInPublic(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, PublicDecoratorModelInPublic{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.PublicDecoratorModelInPublic) } diff --git a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/relativemodelinoperation_client_test.go b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/relativemodelinoperation_client_test.go index bac179b97..442cef07d 100644 --- a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/relativemodelinoperation_client_test.go +++ b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/relativemodelinoperation_client_test.go @@ -14,7 +14,7 @@ import ( func TestRelativeModelInOperationClient_discriminator(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessRelativeModelInOperationClient().discriminator(context.Background(), "anything", nil) + resp, err := client.NewAccessRelativeModelInOperationClient().discriminator(context.Background(), "real", nil) require.NoError(t, err) require.Equal(t, &realModel{ Kind: to.Ptr("real"), @@ -25,7 +25,7 @@ func TestRelativeModelInOperationClient_discriminator(t *testing.T) { func TestRelativeModelInOperationClient_operation(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessRelativeModelInOperationClient().operation(context.Background(), "anything", nil) + resp, err := client.NewAccessRelativeModelInOperationClient().operation(context.Background(), "Madge", nil) require.NoError(t, err) require.Equal(t, outerModel{ Name: to.Ptr("Madge"), diff --git a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/sharedmodelinoperation_client_test.go b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/sharedmodelinoperation_client_test.go index 44397fdf2..3d7abbdbf 100644 --- a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/sharedmodelinoperation_client_test.go +++ b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/sharedmodelinoperation_client_test.go @@ -14,19 +14,19 @@ import ( func TestSharedModelInOperationClient_internalMethod(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessSharedModelInOperationClient().internalMethod(context.Background(), "foo", nil) + resp, err := client.NewAccessSharedModelInOperationClient().internalMethod(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, SharedModel{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.SharedModel) } func TestSharedModelInOperationClient_Public(t *testing.T) { client, err := NewAccessClient(nil) require.NoError(t, err) - resp, err := client.NewAccessSharedModelInOperationClient().Public(context.Background(), "foo", nil) + resp, err := client.NewAccessSharedModelInOperationClient().Public(context.Background(), "sample", nil) require.NoError(t, err) require.Equal(t, SharedModel{ - Name: to.Ptr("foo"), + Name: to.Ptr("sample"), }, resp.SharedModel) } diff --git a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/zz_accessrelativemodelinoperation_client.go b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/zz_accessrelativemodelinoperation_client.go index 926be3c1f..bdc6c9555 100644 --- a/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/zz_accessrelativemodelinoperation_client.go +++ b/packages/typespec-go/test/cadlranch/azure/client-generator-core/accessgroup/zz_accessrelativemodelinoperation_client.go @@ -18,11 +18,11 @@ type AccessRelativeModelInOperationClient struct { internal *azcore.Client } -// discriminator - Expected query parameter: kind= +// discriminator - Expected query parameter: kind= "real" // Expected response body: // ```json // { -// "name": , +// "name": "Madge", // "kind": "real" // } // ``` @@ -74,14 +74,14 @@ func (client *AccessRelativeModelInOperationClient) discriminatorHandleResponse( return result, nil } -// operation - Expected query parameter: name= +// operation - Expected query parameter: name="Madge" // Expected response body: // ```json // { -// "name": , +// "name": "Madge", // "inner": // { -// "name": +// "name": "Madge" // } // } // ``` diff --git a/packages/typespec-go/test/cadlranch/azure/client-generator-core/coreusagegroup/zz_usagemodelinoperation_client.go b/packages/typespec-go/test/cadlranch/azure/client-generator-core/coreusagegroup/zz_usagemodelinoperation_client.go index fe189ebc8..1b11335e1 100644 --- a/packages/typespec-go/test/cadlranch/azure/client-generator-core/coreusagegroup/zz_usagemodelinoperation_client.go +++ b/packages/typespec-go/test/cadlranch/azure/client-generator-core/coreusagegroup/zz_usagemodelinoperation_client.go @@ -21,7 +21,7 @@ type UsageModelInOperationClient struct { // InputToInputOutput - Expected body parameter: // ```json // { -// "name": +// "name": "Madge" // } // ``` // If the operation fails it returns an *azcore.ResponseError type. @@ -72,7 +72,7 @@ func (client *UsageModelInOperationClient) inputToInputOutputCreateRequest(ctx c // ```json // { // "result": { -// "name": +// "name": "Madge" // } // } // ``` @@ -128,7 +128,7 @@ func (client *UsageModelInOperationClient) modelInReadOnlyPropertyHandleResponse // OutputToInputOutput - Expected response body: // ```json // { -// "name": +// "name": "Madge" // } // ``` // If the operation fails it returns an *azcore.ResponseError type. diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/nestedproxyresources_client_test.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/nestedproxyresources_client_test.go deleted file mode 100644 index bdfe8d82d..000000000 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/nestedproxyresources_client_test.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package resources_test - -import ( - "net/http" - "resources" - "testing" - "time" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/stretchr/testify/require" -) - -var ( - validNestedResource = resources.NestedProxyResource{ - ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested"), - Name: to.Ptr("nested"), - Type: to.Ptr("Azure.ResourceManager.Models.Resources/topLevelTrackedResources/top/nestedProxyResources"), - Properties: &resources.NestedProxyResourceProperties{ - Description: to.Ptr("valid"), - ProvisioningState: to.Ptr(resources.ProvisioningStateSucceeded), - }, - SystemData: &resources.SystemData{ - CreatedBy: to.Ptr("AzureSDK"), - CreatedByType: to.Ptr(resources.CreatedByTypeUser), - CreatedAt: to.Ptr(time.Now()), - LastModifiedBy: to.Ptr("AzureSDK"), - LastModifiedAt: to.Ptr(time.Now()), - LastModifiedByType: to.Ptr(resources.CreatedByTypeUser), - }, - } -) - -func TestNestedProxyResourcesClient_Get(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - nestedProxyResourcesClientGetResponse, err := clientFactory.NewNestedProxyResourcesClient().Get( - ctx, - "test-rg", - "top", - "nested", - nil, - ) - require.NoError(t, err) - require.Equal(t, *validNestedResource.ID, *nestedProxyResourcesClientGetResponse.ID) - require.Equal(t, *validNestedResource.Name, *nestedProxyResourcesClientGetResponse.Name) - require.Equal(t, *validNestedResource.Type, *nestedProxyResourcesClientGetResponse.Type) -} - -func TestNestedProxyResourcesClient_CreateOrReplase(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - nestedProxyResourcesClientCreateOrReplaceResponsePoller, err := clientFactory.NewNestedProxyResourcesClient().BeginCreateOrReplace( - ctx, - "test-rg", - "top", - "nested", - resources.NestedProxyResource{ - Properties: &resources.NestedProxyResourceProperties{ - Description: to.Ptr("valid"), - }, - }, - nil, - ) - require.NoError(t, err) - nestedProxyResourcesClientCreateOrReplaceResponse, err := nestedProxyResourcesClientCreateOrReplaceResponsePoller.PollUntilDone(ctx, nil) - require.NoError(t, err) - require.Equal(t, *validNestedResource.ID, *nestedProxyResourcesClientCreateOrReplaceResponse.ID) - require.Equal(t, *validNestedResource.Name, *nestedProxyResourcesClientCreateOrReplaceResponse.Name) - require.Equal(t, *validNestedResource.Type, *nestedProxyResourcesClientCreateOrReplaceResponse.Type) - require.Equal(t, *validNestedResource.Properties.Description, *nestedProxyResourcesClientCreateOrReplaceResponse.Properties.Description) -} - -func TestNestedProxyResourcesClient_BeginUpdate(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - nestedProxyResourcesClientUpdateResponsePoller, err := clientFactory.NewNestedProxyResourcesClient().BeginUpdate( - ctx, - "test-rg", - "top", - "nested", - resources.NestedProxyResource{ - Properties: &resources.NestedProxyResourceProperties{ - Description: to.Ptr("valid2"), - }, - }, - nil, - ) - require.NoError(t, err) - nestedProxyResourcesClientUpdateResponse, err := nestedProxyResourcesClientUpdateResponsePoller.PollUntilDone(ctx, nil) - require.NoError(t, err) - require.Equal(t, *validNestedResource.ID, *nestedProxyResourcesClientUpdateResponse.ID) - require.Equal(t, *validNestedResource.Name, *nestedProxyResourcesClientUpdateResponse.Name) - require.Equal(t, *validNestedResource.Type, *nestedProxyResourcesClientUpdateResponse.Type) - require.Equal(t, "valid2", *nestedProxyResourcesClientUpdateResponse.Properties.Description) -} - -func TestNestedProxyResourcesClient_BeginDelete(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - nestedProxyResourcesClientDeleteResponsePoller, err := clientFactory.NewNestedProxyResourcesClient().BeginDelete(ctx, "test-rg", "top", "nested", nil) - require.NoError(t, err) - nestedProxyResourcesClientDeleteResponse, err := nestedProxyResourcesClientDeleteResponsePoller.Poll(ctx) - require.NoError(t, err) - require.Equal(t, http.StatusNoContent, nestedProxyResourcesClientDeleteResponse.StatusCode) -} - -func TestNestedProxyResourcesClient_NewListByTopLevelTrackedResourcePager(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - nestedProxyResourcesClientListByTopLevelTrackedResourceResponsePager := clientFactory.NewNestedProxyResourcesClient().NewListByTopLevelTrackedResourcePager("test-rg", "top", nil) - require.True(t, nestedProxyResourcesClientListByTopLevelTrackedResourceResponsePager.More()) - nestedProxyResourcesClientListByTopLevelTrackedResourceResponse, err := nestedProxyResourcesClientListByTopLevelTrackedResourceResponsePager.NextPage(ctx) - require.NoError(t, err) - require.Len(t, nestedProxyResourcesClientListByTopLevelTrackedResourceResponse.Value, 1) - require.Equal(t, *validNestedResource.ID, *nestedProxyResourcesClientListByTopLevelTrackedResourceResponse.Value[0].ID) - require.Equal(t, *validNestedResource.Name, *nestedProxyResourcesClientListByTopLevelTrackedResourceResponse.Value[0].Name) - require.Equal(t, *validNestedResource.Type, *nestedProxyResourcesClientListByTopLevelTrackedResourceResponse.Value[0].Type) -} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/topleveltrackedresources_client_test.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/topleveltrackedresources_client_test.go deleted file mode 100644 index 687cc9cd0..000000000 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/topleveltrackedresources_client_test.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package resources_test - -import ( - "fmt" - "net/http" - "testing" - "time" - - "resources" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/stretchr/testify/require" -) - -var ( - validTopLevelResource = resources.TopLevelTrackedResource{ - ID: to.Ptr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/top", subscriptionIdExpected, resourceGroupExpected)), - Name: to.Ptr("top"), - Type: to.Ptr("Azure.ResourceManager.Models.Resources/topLevelTrackedResources"), - Location: to.Ptr("eastus"), - Properties: &resources.TopLevelTrackedResourceProperties{ - Description: to.Ptr("valid"), - ProvisioningState: to.Ptr(resources.ProvisioningStateSucceeded), - }, - SystemData: &resources.SystemData{ - CreatedBy: to.Ptr("AzureSDK"), - CreatedByType: to.Ptr(resources.CreatedByTypeUser), - CreatedAt: to.Ptr(time.Now()), - LastModifiedBy: to.Ptr("AzureSDK"), - LastModifiedAt: to.Ptr(time.Now()), - LastModifiedByType: to.Ptr(resources.CreatedByTypeUser), - }, - } -) - -func TestTopLevelTrackedResourcesClient_Get(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - topLevelTrackedResourcesClientGetResponse, err := clientFactory.NewTopLevelTrackedResourcesClient().Get( - ctx, - "test-rg", - "top", - nil, - ) - require.NoError(t, err) - require.Equal(t, *validTopLevelResource.ID, *topLevelTrackedResourcesClientGetResponse.ID) - require.Equal(t, *validTopLevelResource.Name, *topLevelTrackedResourcesClientGetResponse.Name) - require.Equal(t, *validTopLevelResource.Type, *topLevelTrackedResourcesClientGetResponse.Type) -} - -func TestTopLevelTrackedResourcesClient_CreateOrReplace(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - topLevelTrackedResourcesClientCreateOrReplaceResponsePoller, err := clientFactory.NewTopLevelTrackedResourcesClient().BeginCreateOrReplace( - ctx, - "test-rg", - "top", - resources.TopLevelTrackedResource{ - Location: to.Ptr("eastus"), - Properties: &resources.TopLevelTrackedResourceProperties{ - Description: to.Ptr("valid"), - }, - }, - nil, - ) - require.NoError(t, err) - topLevelTrackedResourcesClientCreateOrReplaceResponse, err := topLevelTrackedResourcesClientCreateOrReplaceResponsePoller.PollUntilDone(ctx, nil) - require.NoError(t, err) - require.Equal(t, *validTopLevelResource.ID, *topLevelTrackedResourcesClientCreateOrReplaceResponse.ID) - require.Equal(t, *validTopLevelResource.Name, *topLevelTrackedResourcesClientCreateOrReplaceResponse.Name) - require.Equal(t, *validTopLevelResource.Type, *topLevelTrackedResourcesClientCreateOrReplaceResponse.Type) - require.Equal(t, *validTopLevelResource.Location, *topLevelTrackedResourcesClientCreateOrReplaceResponse.Location) - require.Equal(t, *validTopLevelResource.Properties.Description, *topLevelTrackedResourcesClientCreateOrReplaceResponse.Properties.Description) -} - -func TestTopLevelTrackedResourcesClient_BeginUpdate(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - topLevelTrackedResourcesClientUpdateResponsePoller, err := clientFactory.NewTopLevelTrackedResourcesClient().BeginUpdate( - ctx, - "test-rg", - "top", - resources.TopLevelTrackedResource{ - Properties: &resources.TopLevelTrackedResourceProperties{ - Description: to.Ptr("valid2"), - }, - }, - nil, - ) - require.NoError(t, err) - topLevelTrackedResourcesClientUpdateResponse, err := topLevelTrackedResourcesClientUpdateResponsePoller.PollUntilDone(ctx, nil) - require.NoError(t, err) - require.Equal(t, *validTopLevelResource.ID, *topLevelTrackedResourcesClientUpdateResponse.ID) - require.Equal(t, *validTopLevelResource.Name, *topLevelTrackedResourcesClientUpdateResponse.Name) - require.Equal(t, *validTopLevelResource.Type, *topLevelTrackedResourcesClientUpdateResponse.Type) - require.Equal(t, *validTopLevelResource.Location, *topLevelTrackedResourcesClientUpdateResponse.Location) - require.Equal(t, "valid2", *topLevelTrackedResourcesClientUpdateResponse.Properties.Description) -} - -func TestTopLevelTrackedResourcesClient_BeginDelete(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - topLevelTrackedResourcesClientDeleteResponsePoller, err := clientFactory.NewTopLevelTrackedResourcesClient().BeginDelete( - ctx, - "test-rg", - "top", - nil, - ) - require.NoError(t, err) - topLevelTrackedResourcesClientDeleteResponse, err := topLevelTrackedResourcesClientDeleteResponsePoller.Poll(ctx) - require.NoError(t, err) - require.Equal(t, http.StatusNoContent, topLevelTrackedResourcesClientDeleteResponse.StatusCode) -} - -func TestTopLevelTrackedResourcesClient_NewListByResourceGroupPager(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - topLevelTrackedResourcesClientListByResourceGroupResponsePager := clientFactory.NewTopLevelTrackedResourcesClient().NewListByResourceGroupPager("test-rg", nil) - require.True(t, topLevelTrackedResourcesClientListByResourceGroupResponsePager.More()) - topLevelTrackedResourcesClientListByResourceGroupResponse, err := topLevelTrackedResourcesClientListByResourceGroupResponsePager.NextPage(ctx) - require.NoError(t, err) - require.Len(t, topLevelTrackedResourcesClientListByResourceGroupResponse.Value, 1) - require.Equal(t, *validTopLevelResource.ID, *topLevelTrackedResourcesClientListByResourceGroupResponse.Value[0].ID) - require.Equal(t, *validTopLevelResource.Name, *topLevelTrackedResourcesClientListByResourceGroupResponse.Value[0].Name) - require.Equal(t, *validTopLevelResource.Type, *topLevelTrackedResourcesClientListByResourceGroupResponse.Value[0].Type) - require.Equal(t, *validTopLevelResource.Location, *topLevelTrackedResourcesClientListByResourceGroupResponse.Value[0].Location) -} - -func TestTopLevelTrackedResourcesClient_NewListBySubscriptionPager(t *testing.T) { - t.Skip("https://github.com/Azure/typespec-azure/issues/1709") - TopLevelTrackedResourcesClientListBySubscriptionResponsePager := clientFactory.NewTopLevelTrackedResourcesClient().NewListBySubscriptionPager(nil) - require.True(t, TopLevelTrackedResourcesClientListBySubscriptionResponsePager.More()) - TopLevelTrackedResourcesClientListBySubscriptionResponse, err := TopLevelTrackedResourcesClientListBySubscriptionResponsePager.NextPage(ctx) - require.NoError(t, err) - require.Len(t, TopLevelTrackedResourcesClientListBySubscriptionResponse.Value, 1) - require.Equal(t, *validTopLevelResource.ID, *TopLevelTrackedResourcesClientListBySubscriptionResponse.Value[0].ID) - require.Equal(t, *validTopLevelResource.Name, *TopLevelTrackedResourcesClientListBySubscriptionResponse.Value[0].Name) - require.Equal(t, *validTopLevelResource.Type, *TopLevelTrackedResourcesClientListBySubscriptionResponse.Value[0].Type) - require.Equal(t, *validTopLevelResource.Location, *TopLevelTrackedResourcesClientListBySubscriptionResponse.Value[0].Location) -} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_options.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_options.go deleted file mode 100644 index 3c6fd2135..000000000 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_options.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. - -package resources - -// NestedProxyResourcesClientBeginCreateOrReplaceOptions contains the optional parameters for the NestedProxyResourcesClient.BeginCreateOrReplace -// method. -type NestedProxyResourcesClientBeginCreateOrReplaceOptions struct { - // Resumes the long-running operation from the provided token. - ResumeToken string -} - -// NestedProxyResourcesClientBeginDeleteOptions contains the optional parameters for the NestedProxyResourcesClient.BeginDelete -// method. -type NestedProxyResourcesClientBeginDeleteOptions struct { - // Resumes the long-running operation from the provided token. - ResumeToken string -} - -// NestedProxyResourcesClientBeginUpdateOptions contains the optional parameters for the NestedProxyResourcesClient.BeginUpdate -// method. -type NestedProxyResourcesClientBeginUpdateOptions struct { - // Resumes the long-running operation from the provided token. - ResumeToken string -} - -// NestedProxyResourcesClientGetOptions contains the optional parameters for the NestedProxyResourcesClient.Get method. -type NestedProxyResourcesClientGetOptions struct { - // placeholder for future optional parameters -} - -// NestedProxyResourcesClientListByTopLevelTrackedResourceOptions contains the optional parameters for the NestedProxyResourcesClient.NewListByTopLevelTrackedResourcePager -// method. -type NestedProxyResourcesClientListByTopLevelTrackedResourceOptions struct { - // placeholder for future optional parameters -} - -// TopLevelTrackedResourcesClientActionSyncOptions contains the optional parameters for the TopLevelTrackedResourcesClient.ActionSync -// method. -type TopLevelTrackedResourcesClientActionSyncOptions struct { - // placeholder for future optional parameters -} - -// TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions contains the optional parameters for the TopLevelTrackedResourcesClient.BeginCreateOrReplace -// method. -type TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions struct { - // Resumes the long-running operation from the provided token. - ResumeToken string -} - -// TopLevelTrackedResourcesClientBeginDeleteOptions contains the optional parameters for the TopLevelTrackedResourcesClient.BeginDelete -// method. -type TopLevelTrackedResourcesClientBeginDeleteOptions struct { - // Resumes the long-running operation from the provided token. - ResumeToken string -} - -// TopLevelTrackedResourcesClientBeginUpdateOptions contains the optional parameters for the TopLevelTrackedResourcesClient.BeginUpdate -// method. -type TopLevelTrackedResourcesClientBeginUpdateOptions struct { - // Resumes the long-running operation from the provided token. - ResumeToken string -} - -// TopLevelTrackedResourcesClientGetOptions contains the optional parameters for the TopLevelTrackedResourcesClient.Get method. -type TopLevelTrackedResourcesClientGetOptions struct { - // placeholder for future optional parameters -} - -// TopLevelTrackedResourcesClientListByResourceGroupOptions contains the optional parameters for the TopLevelTrackedResourcesClient.NewListByResourceGroupPager -// method. -type TopLevelTrackedResourcesClientListByResourceGroupOptions struct { - // placeholder for future optional parameters -} - -// TopLevelTrackedResourcesClientListBySubscriptionOptions contains the optional parameters for the TopLevelTrackedResourcesClient.NewListBySubscriptionPager -// method. -type TopLevelTrackedResourcesClientListBySubscriptionOptions struct { - // placeholder for future optional parameters -} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_responses.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_responses.go deleted file mode 100644 index caf165130..000000000 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_responses.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. - -package resources - -// NestedProxyResourcesClientCreateOrReplaceResponse contains the response from method NestedProxyResourcesClient.BeginCreateOrReplace. -type NestedProxyResourcesClientCreateOrReplaceResponse struct { - // Nested child of Top Level Tracked Resource. - NestedProxyResource -} - -// NestedProxyResourcesClientDeleteResponse contains the response from method NestedProxyResourcesClient.BeginDelete. -type NestedProxyResourcesClientDeleteResponse struct { - // placeholder for future response values -} - -// NestedProxyResourcesClientGetResponse contains the response from method NestedProxyResourcesClient.Get. -type NestedProxyResourcesClientGetResponse struct { - // Nested child of Top Level Tracked Resource. - NestedProxyResource -} - -// NestedProxyResourcesClientListByTopLevelTrackedResourceResponse contains the response from method NestedProxyResourcesClient.NewListByTopLevelTrackedResourcePager. -type NestedProxyResourcesClientListByTopLevelTrackedResourceResponse struct { - // The response of a NestedProxyResource list operation. - NestedProxyResourceListResult -} - -// NestedProxyResourcesClientUpdateResponse contains the response from method NestedProxyResourcesClient.BeginUpdate. -type NestedProxyResourcesClientUpdateResponse struct { - // Nested child of Top Level Tracked Resource. - NestedProxyResource -} - -// TopLevelTrackedResourcesClientActionSyncResponse contains the response from method TopLevelTrackedResourcesClient.ActionSync. -type TopLevelTrackedResourcesClientActionSyncResponse struct { - // placeholder for future response values -} - -// TopLevelTrackedResourcesClientCreateOrReplaceResponse contains the response from method TopLevelTrackedResourcesClient.BeginCreateOrReplace. -type TopLevelTrackedResourcesClientCreateOrReplaceResponse struct { - // Concrete tracked resource types can be created by aliasing this type using a specific property type. - TopLevelTrackedResource -} - -// TopLevelTrackedResourcesClientDeleteResponse contains the response from method TopLevelTrackedResourcesClient.BeginDelete. -type TopLevelTrackedResourcesClientDeleteResponse struct { - // placeholder for future response values -} - -// TopLevelTrackedResourcesClientGetResponse contains the response from method TopLevelTrackedResourcesClient.Get. -type TopLevelTrackedResourcesClientGetResponse struct { - // Concrete tracked resource types can be created by aliasing this type using a specific property type. - TopLevelTrackedResource -} - -// TopLevelTrackedResourcesClientListByResourceGroupResponse contains the response from method TopLevelTrackedResourcesClient.NewListByResourceGroupPager. -type TopLevelTrackedResourcesClientListByResourceGroupResponse struct { - // The response of a TopLevelTrackedResource list operation. - TopLevelTrackedResourceListResult -} - -// TopLevelTrackedResourcesClientListBySubscriptionResponse contains the response from method TopLevelTrackedResourcesClient.NewListBySubscriptionPager. -type TopLevelTrackedResourcesClientListBySubscriptionResponse struct { - // The response of a TopLevelTrackedResource list operation. - TopLevelTrackedResourceListResult -} - -// TopLevelTrackedResourcesClientUpdateResponse contains the response from method TopLevelTrackedResourcesClient.BeginUpdate. -type TopLevelTrackedResourcesClientUpdateResponse struct { - // Concrete tracked resource types can be created by aliasing this type using a specific property type. - TopLevelTrackedResource -} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_internal.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_internal.go similarity index 100% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_internal.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_internal.go diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_nestedproxyresources_server.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_nested_server.go similarity index 68% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_nestedproxyresources_server.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_nested_server.go index eda1e8fca..8bb88e351 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_nestedproxyresources_server.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_nested_server.go @@ -18,54 +18,54 @@ import ( "resources" ) -// NestedProxyResourcesServer is a fake server for instances of the resources.NestedProxyResourcesClient type. -type NestedProxyResourcesServer struct { - // BeginCreateOrReplace is the fake for method NestedProxyResourcesClient.BeginCreateOrReplace +// NestedServer is a fake server for instances of the resources.NestedClient type. +type NestedServer struct { + // BeginCreateOrReplace is the fake for method NestedClient.BeginCreateOrReplace // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated - BeginCreateOrReplace func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource resources.NestedProxyResource, options *resources.NestedProxyResourcesClientBeginCreateOrReplaceOptions) (resp azfake.PollerResponder[resources.NestedProxyResourcesClientCreateOrReplaceResponse], errResp azfake.ErrorResponder) + BeginCreateOrReplace func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource resources.NestedProxyResource, options *resources.NestedClientBeginCreateOrReplaceOptions) (resp azfake.PollerResponder[resources.NestedClientCreateOrReplaceResponse], errResp azfake.ErrorResponder) - // BeginDelete is the fake for method NestedProxyResourcesClient.BeginDelete + // BeginDelete is the fake for method NestedClient.BeginDelete // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent - BeginDelete func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *resources.NestedProxyResourcesClientBeginDeleteOptions) (resp azfake.PollerResponder[resources.NestedProxyResourcesClientDeleteResponse], errResp azfake.ErrorResponder) + BeginDelete func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *resources.NestedClientBeginDeleteOptions) (resp azfake.PollerResponder[resources.NestedClientDeleteResponse], errResp azfake.ErrorResponder) - // Get is the fake for method NestedProxyResourcesClient.Get + // Get is the fake for method NestedClient.Get // HTTP status codes to indicate success: http.StatusOK - Get func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *resources.NestedProxyResourcesClientGetOptions) (resp azfake.Responder[resources.NestedProxyResourcesClientGetResponse], errResp azfake.ErrorResponder) + Get func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *resources.NestedClientGetOptions) (resp azfake.Responder[resources.NestedClientGetResponse], errResp azfake.ErrorResponder) - // NewListByTopLevelTrackedResourcePager is the fake for method NestedProxyResourcesClient.NewListByTopLevelTrackedResourcePager + // NewListByTopLevelTrackedResourcePager is the fake for method NestedClient.NewListByTopLevelTrackedResourcePager // HTTP status codes to indicate success: http.StatusOK - NewListByTopLevelTrackedResourcePager func(resourceGroupName string, topLevelTrackedResourceName string, options *resources.NestedProxyResourcesClientListByTopLevelTrackedResourceOptions) (resp azfake.PagerResponder[resources.NestedProxyResourcesClientListByTopLevelTrackedResourceResponse]) + NewListByTopLevelTrackedResourcePager func(resourceGroupName string, topLevelTrackedResourceName string, options *resources.NestedClientListByTopLevelTrackedResourceOptions) (resp azfake.PagerResponder[resources.NestedClientListByTopLevelTrackedResourceResponse]) - // BeginUpdate is the fake for method NestedProxyResourcesClient.BeginUpdate + // BeginUpdate is the fake for method NestedClient.BeginUpdate // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted - BeginUpdate func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties resources.NestedProxyResource, options *resources.NestedProxyResourcesClientBeginUpdateOptions) (resp azfake.PollerResponder[resources.NestedProxyResourcesClientUpdateResponse], errResp azfake.ErrorResponder) + BeginUpdate func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties resources.NestedProxyResource, options *resources.NestedClientBeginUpdateOptions) (resp azfake.PollerResponder[resources.NestedClientUpdateResponse], errResp azfake.ErrorResponder) } -// NewNestedProxyResourcesServerTransport creates a new instance of NestedProxyResourcesServerTransport with the provided implementation. -// The returned NestedProxyResourcesServerTransport instance is connected to an instance of resources.NestedProxyResourcesClient via the +// NewNestedServerTransport creates a new instance of NestedServerTransport with the provided implementation. +// The returned NestedServerTransport instance is connected to an instance of resources.NestedClient via the // azcore.ClientOptions.Transporter field in the client's constructor parameters. -func NewNestedProxyResourcesServerTransport(srv *NestedProxyResourcesServer) *NestedProxyResourcesServerTransport { - return &NestedProxyResourcesServerTransport{ +func NewNestedServerTransport(srv *NestedServer) *NestedServerTransport { + return &NestedServerTransport{ srv: srv, - beginCreateOrReplace: newTracker[azfake.PollerResponder[resources.NestedProxyResourcesClientCreateOrReplaceResponse]](), - beginDelete: newTracker[azfake.PollerResponder[resources.NestedProxyResourcesClientDeleteResponse]](), - newListByTopLevelTrackedResourcePager: newTracker[azfake.PagerResponder[resources.NestedProxyResourcesClientListByTopLevelTrackedResourceResponse]](), - beginUpdate: newTracker[azfake.PollerResponder[resources.NestedProxyResourcesClientUpdateResponse]](), + beginCreateOrReplace: newTracker[azfake.PollerResponder[resources.NestedClientCreateOrReplaceResponse]](), + beginDelete: newTracker[azfake.PollerResponder[resources.NestedClientDeleteResponse]](), + newListByTopLevelTrackedResourcePager: newTracker[azfake.PagerResponder[resources.NestedClientListByTopLevelTrackedResourceResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[resources.NestedClientUpdateResponse]](), } } -// NestedProxyResourcesServerTransport connects instances of resources.NestedProxyResourcesClient to instances of NestedProxyResourcesServer. -// Don't use this type directly, use NewNestedProxyResourcesServerTransport instead. -type NestedProxyResourcesServerTransport struct { - srv *NestedProxyResourcesServer - beginCreateOrReplace *tracker[azfake.PollerResponder[resources.NestedProxyResourcesClientCreateOrReplaceResponse]] - beginDelete *tracker[azfake.PollerResponder[resources.NestedProxyResourcesClientDeleteResponse]] - newListByTopLevelTrackedResourcePager *tracker[azfake.PagerResponder[resources.NestedProxyResourcesClientListByTopLevelTrackedResourceResponse]] - beginUpdate *tracker[azfake.PollerResponder[resources.NestedProxyResourcesClientUpdateResponse]] +// NestedServerTransport connects instances of resources.NestedClient to instances of NestedServer. +// Don't use this type directly, use NewNestedServerTransport instead. +type NestedServerTransport struct { + srv *NestedServer + beginCreateOrReplace *tracker[azfake.PollerResponder[resources.NestedClientCreateOrReplaceResponse]] + beginDelete *tracker[azfake.PollerResponder[resources.NestedClientDeleteResponse]] + newListByTopLevelTrackedResourcePager *tracker[azfake.PagerResponder[resources.NestedClientListByTopLevelTrackedResourceResponse]] + beginUpdate *tracker[azfake.PollerResponder[resources.NestedClientUpdateResponse]] } -// Do implements the policy.Transporter interface for NestedProxyResourcesServerTransport. -func (n *NestedProxyResourcesServerTransport) Do(req *http.Request) (*http.Response, error) { +// Do implements the policy.Transporter interface for NestedServerTransport. +func (n *NestedServerTransport) Do(req *http.Request) (*http.Response, error) { rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) method, ok := rawMethod.(string) if !ok { @@ -75,27 +75,33 @@ func (n *NestedProxyResourcesServerTransport) Do(req *http.Request) (*http.Respo return n.dispatchToMethodFake(req, method) } -func (n *NestedProxyResourcesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { +func (n *NestedServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { resultChan := make(chan result) defer close(resultChan) go func() { + var intercepted bool var res result - switch method { - case "NestedProxyResourcesClient.BeginCreateOrReplace": - res.resp, res.err = n.dispatchBeginCreateOrReplace(req) - case "NestedProxyResourcesClient.BeginDelete": - res.resp, res.err = n.dispatchBeginDelete(req) - case "NestedProxyResourcesClient.Get": - res.resp, res.err = n.dispatchGet(req) - case "NestedProxyResourcesClient.NewListByTopLevelTrackedResourcePager": - res.resp, res.err = n.dispatchNewListByTopLevelTrackedResourcePager(req) - case "NestedProxyResourcesClient.BeginUpdate": - res.resp, res.err = n.dispatchBeginUpdate(req) - default: - res.err = fmt.Errorf("unhandled API %s", method) + if nestedServerTransportInterceptor != nil { + res.resp, res.err, intercepted = nestedServerTransportInterceptor.Do(req) } + if !intercepted { + switch method { + case "NestedClient.BeginCreateOrReplace": + res.resp, res.err = n.dispatchBeginCreateOrReplace(req) + case "NestedClient.BeginDelete": + res.resp, res.err = n.dispatchBeginDelete(req) + case "NestedClient.Get": + res.resp, res.err = n.dispatchGet(req) + case "NestedClient.NewListByTopLevelTrackedResourcePager": + res.resp, res.err = n.dispatchNewListByTopLevelTrackedResourcePager(req) + case "NestedClient.BeginUpdate": + res.resp, res.err = n.dispatchBeginUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + } select { case resultChan <- res: case <-req.Context().Done(): @@ -110,13 +116,13 @@ func (n *NestedProxyResourcesServerTransport) dispatchToMethodFake(req *http.Req } } -func (n *NestedProxyResourcesServerTransport) dispatchBeginCreateOrReplace(req *http.Request) (*http.Response, error) { +func (n *NestedServerTransport) dispatchBeginCreateOrReplace(req *http.Request) (*http.Response, error) { if n.srv.BeginCreateOrReplace == nil { return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrReplace not implemented")} } beginCreateOrReplace := n.beginCreateOrReplace.get(req) if beginCreateOrReplace == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 4 { @@ -162,13 +168,13 @@ func (n *NestedProxyResourcesServerTransport) dispatchBeginCreateOrReplace(req * return resp, nil } -func (n *NestedProxyResourcesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { +func (n *NestedServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if n.srv.BeginDelete == nil { return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } beginDelete := n.beginDelete.get(req) if beginDelete == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 4 { @@ -210,11 +216,11 @@ func (n *NestedProxyResourcesServerTransport) dispatchBeginDelete(req *http.Requ return resp, nil } -func (n *NestedProxyResourcesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { +func (n *NestedServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if n.srv.Get == nil { return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 4 { @@ -247,13 +253,13 @@ func (n *NestedProxyResourcesServerTransport) dispatchGet(req *http.Request) (*h return resp, nil } -func (n *NestedProxyResourcesServerTransport) dispatchNewListByTopLevelTrackedResourcePager(req *http.Request) (*http.Response, error) { +func (n *NestedServerTransport) dispatchNewListByTopLevelTrackedResourcePager(req *http.Request) (*http.Response, error) { if n.srv.NewListByTopLevelTrackedResourcePager == nil { return nil, &nonRetriableError{errors.New("fake for method NewListByTopLevelTrackedResourcePager not implemented")} } newListByTopLevelTrackedResourcePager := n.newListByTopLevelTrackedResourcePager.get(req) if newListByTopLevelTrackedResourcePager == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -270,7 +276,7 @@ func (n *NestedProxyResourcesServerTransport) dispatchNewListByTopLevelTrackedRe resp := n.srv.NewListByTopLevelTrackedResourcePager(resourceGroupNameParam, topLevelTrackedResourceNameParam, nil) newListByTopLevelTrackedResourcePager = &resp n.newListByTopLevelTrackedResourcePager.add(req, newListByTopLevelTrackedResourcePager) - server.PagerResponderInjectNextLinks(newListByTopLevelTrackedResourcePager, req, func(page *resources.NestedProxyResourcesClientListByTopLevelTrackedResourceResponse, createLink func() string) { + server.PagerResponderInjectNextLinks(newListByTopLevelTrackedResourcePager, req, func(page *resources.NestedClientListByTopLevelTrackedResourceResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) }) } @@ -288,13 +294,13 @@ func (n *NestedProxyResourcesServerTransport) dispatchNewListByTopLevelTrackedRe return resp, nil } -func (n *NestedProxyResourcesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { +func (n *NestedServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if n.srv.BeginUpdate == nil { return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } beginUpdate := n.beginUpdate.get(req) if beginUpdate == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/nestedProxyResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 4 { @@ -339,3 +345,9 @@ func (n *NestedProxyResourcesServerTransport) dispatchBeginUpdate(req *http.Requ return resp, nil } + +// set this to conditionally intercept incoming requests to NestedServerTransport +var nestedServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_server_factory.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_server_factory.go similarity index 62% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_server_factory.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_server_factory.go index db7defae1..2b0f93152 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_server_factory.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_server_factory.go @@ -15,11 +15,14 @@ import ( // ServerFactory is a fake server for instances of the resources.ClientFactory type. type ServerFactory struct { - // NestedProxyResourcesServer contains the fakes for client NestedProxyResourcesClient - NestedProxyResourcesServer NestedProxyResourcesServer + // NestedServer contains the fakes for client NestedClient + NestedServer NestedServer - // TopLevelTrackedResourcesServer contains the fakes for client TopLevelTrackedResourcesClient - TopLevelTrackedResourcesServer TopLevelTrackedResourcesServer + // SingletonServer contains the fakes for client SingletonClient + SingletonServer SingletonServer + + // TopLevelServer contains the fakes for client TopLevelClient + TopLevelServer TopLevelServer } // NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. @@ -34,10 +37,11 @@ func NewServerFactoryTransport(srv *ServerFactory) *ServerFactoryTransport { // ServerFactoryTransport connects instances of resources.ClientFactory to instances of ServerFactory. // Don't use this type directly, use NewServerFactoryTransport instead. type ServerFactoryTransport struct { - srv *ServerFactory - trMu sync.Mutex - trNestedProxyResourcesServer *NestedProxyResourcesServerTransport - trTopLevelTrackedResourcesServer *TopLevelTrackedResourcesServerTransport + srv *ServerFactory + trMu sync.Mutex + trNestedServer *NestedServerTransport + trSingletonServer *SingletonServerTransport + trTopLevelServer *TopLevelServerTransport } // Do implements the policy.Transporter interface for ServerFactoryTransport. @@ -53,16 +57,15 @@ func (s *ServerFactoryTransport) Do(req *http.Request) (*http.Response, error) { var err error switch client { - case "NestedProxyResourcesClient": - initServer(s, &s.trNestedProxyResourcesServer, func() *NestedProxyResourcesServerTransport { - return NewNestedProxyResourcesServerTransport(&s.srv.NestedProxyResourcesServer) - }) - resp, err = s.trNestedProxyResourcesServer.Do(req) - case "TopLevelTrackedResourcesClient": - initServer(s, &s.trTopLevelTrackedResourcesServer, func() *TopLevelTrackedResourcesServerTransport { - return NewTopLevelTrackedResourcesServerTransport(&s.srv.TopLevelTrackedResourcesServer) - }) - resp, err = s.trTopLevelTrackedResourcesServer.Do(req) + case "NestedClient": + initServer(s, &s.trNestedServer, func() *NestedServerTransport { return NewNestedServerTransport(&s.srv.NestedServer) }) + resp, err = s.trNestedServer.Do(req) + case "SingletonClient": + initServer(s, &s.trSingletonServer, func() *SingletonServerTransport { return NewSingletonServerTransport(&s.srv.SingletonServer) }) + resp, err = s.trSingletonServer.Do(req) + case "TopLevelClient": + initServer(s, &s.trTopLevelServer, func() *TopLevelServerTransport { return NewTopLevelServerTransport(&s.srv.TopLevelServer) }) + resp, err = s.trTopLevelServer.Do(req) default: err = fmt.Errorf("unhandled client %s", client) } diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_singleton_server.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_singleton_server.go new file mode 100644 index 000000000..39fa6566a --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_singleton_server.go @@ -0,0 +1,256 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "net/http" + "net/url" + "regexp" + "resources" +) + +// SingletonServer is a fake server for instances of the resources.SingletonClient type. +type SingletonServer struct { + // BeginCreateOrUpdate is the fake for method SingletonClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, resource resources.SingletonTrackedResource, options *resources.SingletonClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[resources.SingletonClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // GetByResourceGroup is the fake for method SingletonClient.GetByResourceGroup + // HTTP status codes to indicate success: http.StatusOK + GetByResourceGroup func(ctx context.Context, resourceGroupName string, options *resources.SingletonClientGetByResourceGroupOptions) (resp azfake.Responder[resources.SingletonClientGetByResourceGroupResponse], errResp azfake.ErrorResponder) + + // NewListByResourceGroupPager is the fake for method SingletonClient.NewListByResourceGroupPager + // HTTP status codes to indicate success: http.StatusOK + NewListByResourceGroupPager func(resourceGroupName string, options *resources.SingletonClientListByResourceGroupOptions) (resp azfake.PagerResponder[resources.SingletonClientListByResourceGroupResponse]) + + // Update is the fake for method SingletonClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, resourceGroupName string, properties resources.SingletonTrackedResource, options *resources.SingletonClientUpdateOptions) (resp azfake.Responder[resources.SingletonClientUpdateResponse], errResp azfake.ErrorResponder) +} + +// NewSingletonServerTransport creates a new instance of SingletonServerTransport with the provided implementation. +// The returned SingletonServerTransport instance is connected to an instance of resources.SingletonClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewSingletonServerTransport(srv *SingletonServer) *SingletonServerTransport { + return &SingletonServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[resources.SingletonClientCreateOrUpdateResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[resources.SingletonClientListByResourceGroupResponse]](), + } +} + +// SingletonServerTransport connects instances of resources.SingletonClient to instances of SingletonServer. +// Don't use this type directly, use NewSingletonServerTransport instead. +type SingletonServerTransport struct { + srv *SingletonServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[resources.SingletonClientCreateOrUpdateResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[resources.SingletonClientListByResourceGroupResponse]] +} + +// Do implements the policy.Transporter interface for SingletonServerTransport. +func (s *SingletonServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return s.dispatchToMethodFake(req, method) +} + +func (s *SingletonServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if singletonServerTransportInterceptor != nil { + res.resp, res.err, intercepted = singletonServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "SingletonClient.BeginCreateOrUpdate": + res.resp, res.err = s.dispatchBeginCreateOrUpdate(req) + case "SingletonClient.GetByResourceGroup": + res.resp, res.err = s.dispatchGetByResourceGroup(req) + case "SingletonClient.NewListByResourceGroupPager": + res.resp, res.err = s.dispatchNewListByResourceGroupPager(req) + case "SingletonClient.Update": + res.resp, res.err = s.dispatchUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (s *SingletonServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if s.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := s.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/singletonTrackedResources/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[resources.SingletonTrackedResource](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + s.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + s.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + s.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (s *SingletonServerTransport) dispatchGetByResourceGroup(req *http.Request) (*http.Response, error) { + if s.srv.GetByResourceGroup == nil { + return nil, &nonRetriableError{errors.New("fake for method GetByResourceGroup not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/singletonTrackedResources/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.GetByResourceGroup(req.Context(), resourceGroupNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SingletonTrackedResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (s *SingletonServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { + if s.srv.NewListByResourceGroupPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} + } + newListByResourceGroupPager := s.newListByResourceGroupPager.get(req) + if newListByResourceGroupPager == nil { + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/singletonTrackedResources` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + resp := s.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) + newListByResourceGroupPager = &resp + s.newListByResourceGroupPager.add(req, newListByResourceGroupPager) + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *resources.SingletonClientListByResourceGroupResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListByResourceGroupPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + s.newListByResourceGroupPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListByResourceGroupPager) { + s.newListByResourceGroupPager.remove(req) + } + return resp, nil +} + +func (s *SingletonServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if s.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/singletonTrackedResources/default` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[resources.SingletonTrackedResource](req) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := s.srv.Update(req.Context(), resourceGroupNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).SingletonTrackedResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to SingletonServerTransport +var singletonServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_time_rfc3339.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_time_rfc3339.go similarity index 100% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_time_rfc3339.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_time_rfc3339.go diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_topleveltrackedresources_server.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_toplevel_server.go similarity index 67% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_topleveltrackedresources_server.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_toplevel_server.go index 16f1cedef..26bb9909f 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/fake/zz_topleveltrackedresources_server.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/fake/zz_toplevel_server.go @@ -18,64 +18,64 @@ import ( "resources" ) -// TopLevelTrackedResourcesServer is a fake server for instances of the resources.TopLevelTrackedResourcesClient type. -type TopLevelTrackedResourcesServer struct { - // ActionSync is the fake for method TopLevelTrackedResourcesClient.ActionSync +// TopLevelServer is a fake server for instances of the resources.TopLevelClient type. +type TopLevelServer struct { + // ActionSync is the fake for method TopLevelClient.ActionSync // HTTP status codes to indicate success: http.StatusNoContent - ActionSync func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, body resources.NotificationDetails, options *resources.TopLevelTrackedResourcesClientActionSyncOptions) (resp azfake.Responder[resources.TopLevelTrackedResourcesClientActionSyncResponse], errResp azfake.ErrorResponder) + ActionSync func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, body resources.NotificationDetails, options *resources.TopLevelClientActionSyncOptions) (resp azfake.Responder[resources.TopLevelClientActionSyncResponse], errResp azfake.ErrorResponder) - // BeginCreateOrReplace is the fake for method TopLevelTrackedResourcesClient.BeginCreateOrReplace + // BeginCreateOrReplace is the fake for method TopLevelClient.BeginCreateOrReplace // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated - BeginCreateOrReplace func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource resources.TopLevelTrackedResource, options *resources.TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions) (resp azfake.PollerResponder[resources.TopLevelTrackedResourcesClientCreateOrReplaceResponse], errResp azfake.ErrorResponder) + BeginCreateOrReplace func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource resources.TopLevelTrackedResource, options *resources.TopLevelClientBeginCreateOrReplaceOptions) (resp azfake.PollerResponder[resources.TopLevelClientCreateOrReplaceResponse], errResp azfake.ErrorResponder) - // BeginDelete is the fake for method TopLevelTrackedResourcesClient.BeginDelete + // BeginDelete is the fake for method TopLevelClient.BeginDelete // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent - BeginDelete func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *resources.TopLevelTrackedResourcesClientBeginDeleteOptions) (resp azfake.PollerResponder[resources.TopLevelTrackedResourcesClientDeleteResponse], errResp azfake.ErrorResponder) + BeginDelete func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *resources.TopLevelClientBeginDeleteOptions) (resp azfake.PollerResponder[resources.TopLevelClientDeleteResponse], errResp azfake.ErrorResponder) - // Get is the fake for method TopLevelTrackedResourcesClient.Get + // Get is the fake for method TopLevelClient.Get // HTTP status codes to indicate success: http.StatusOK - Get func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *resources.TopLevelTrackedResourcesClientGetOptions) (resp azfake.Responder[resources.TopLevelTrackedResourcesClientGetResponse], errResp azfake.ErrorResponder) + Get func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *resources.TopLevelClientGetOptions) (resp azfake.Responder[resources.TopLevelClientGetResponse], errResp azfake.ErrorResponder) - // NewListByResourceGroupPager is the fake for method TopLevelTrackedResourcesClient.NewListByResourceGroupPager + // NewListByResourceGroupPager is the fake for method TopLevelClient.NewListByResourceGroupPager // HTTP status codes to indicate success: http.StatusOK - NewListByResourceGroupPager func(resourceGroupName string, options *resources.TopLevelTrackedResourcesClientListByResourceGroupOptions) (resp azfake.PagerResponder[resources.TopLevelTrackedResourcesClientListByResourceGroupResponse]) + NewListByResourceGroupPager func(resourceGroupName string, options *resources.TopLevelClientListByResourceGroupOptions) (resp azfake.PagerResponder[resources.TopLevelClientListByResourceGroupResponse]) - // NewListBySubscriptionPager is the fake for method TopLevelTrackedResourcesClient.NewListBySubscriptionPager + // NewListBySubscriptionPager is the fake for method TopLevelClient.NewListBySubscriptionPager // HTTP status codes to indicate success: http.StatusOK - NewListBySubscriptionPager func(options *resources.TopLevelTrackedResourcesClientListBySubscriptionOptions) (resp azfake.PagerResponder[resources.TopLevelTrackedResourcesClientListBySubscriptionResponse]) + NewListBySubscriptionPager func(options *resources.TopLevelClientListBySubscriptionOptions) (resp azfake.PagerResponder[resources.TopLevelClientListBySubscriptionResponse]) - // BeginUpdate is the fake for method TopLevelTrackedResourcesClient.BeginUpdate + // BeginUpdate is the fake for method TopLevelClient.BeginUpdate // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted - BeginUpdate func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties resources.TopLevelTrackedResource, options *resources.TopLevelTrackedResourcesClientBeginUpdateOptions) (resp azfake.PollerResponder[resources.TopLevelTrackedResourcesClientUpdateResponse], errResp azfake.ErrorResponder) + BeginUpdate func(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties resources.TopLevelTrackedResource, options *resources.TopLevelClientBeginUpdateOptions) (resp azfake.PollerResponder[resources.TopLevelClientUpdateResponse], errResp azfake.ErrorResponder) } -// NewTopLevelTrackedResourcesServerTransport creates a new instance of TopLevelTrackedResourcesServerTransport with the provided implementation. -// The returned TopLevelTrackedResourcesServerTransport instance is connected to an instance of resources.TopLevelTrackedResourcesClient via the +// NewTopLevelServerTransport creates a new instance of TopLevelServerTransport with the provided implementation. +// The returned TopLevelServerTransport instance is connected to an instance of resources.TopLevelClient via the // azcore.ClientOptions.Transporter field in the client's constructor parameters. -func NewTopLevelTrackedResourcesServerTransport(srv *TopLevelTrackedResourcesServer) *TopLevelTrackedResourcesServerTransport { - return &TopLevelTrackedResourcesServerTransport{ +func NewTopLevelServerTransport(srv *TopLevelServer) *TopLevelServerTransport { + return &TopLevelServerTransport{ srv: srv, - beginCreateOrReplace: newTracker[azfake.PollerResponder[resources.TopLevelTrackedResourcesClientCreateOrReplaceResponse]](), - beginDelete: newTracker[azfake.PollerResponder[resources.TopLevelTrackedResourcesClientDeleteResponse]](), - newListByResourceGroupPager: newTracker[azfake.PagerResponder[resources.TopLevelTrackedResourcesClientListByResourceGroupResponse]](), - newListBySubscriptionPager: newTracker[azfake.PagerResponder[resources.TopLevelTrackedResourcesClientListBySubscriptionResponse]](), - beginUpdate: newTracker[azfake.PollerResponder[resources.TopLevelTrackedResourcesClientUpdateResponse]](), + beginCreateOrReplace: newTracker[azfake.PollerResponder[resources.TopLevelClientCreateOrReplaceResponse]](), + beginDelete: newTracker[azfake.PollerResponder[resources.TopLevelClientDeleteResponse]](), + newListByResourceGroupPager: newTracker[azfake.PagerResponder[resources.TopLevelClientListByResourceGroupResponse]](), + newListBySubscriptionPager: newTracker[azfake.PagerResponder[resources.TopLevelClientListBySubscriptionResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[resources.TopLevelClientUpdateResponse]](), } } -// TopLevelTrackedResourcesServerTransport connects instances of resources.TopLevelTrackedResourcesClient to instances of TopLevelTrackedResourcesServer. -// Don't use this type directly, use NewTopLevelTrackedResourcesServerTransport instead. -type TopLevelTrackedResourcesServerTransport struct { - srv *TopLevelTrackedResourcesServer - beginCreateOrReplace *tracker[azfake.PollerResponder[resources.TopLevelTrackedResourcesClientCreateOrReplaceResponse]] - beginDelete *tracker[azfake.PollerResponder[resources.TopLevelTrackedResourcesClientDeleteResponse]] - newListByResourceGroupPager *tracker[azfake.PagerResponder[resources.TopLevelTrackedResourcesClientListByResourceGroupResponse]] - newListBySubscriptionPager *tracker[azfake.PagerResponder[resources.TopLevelTrackedResourcesClientListBySubscriptionResponse]] - beginUpdate *tracker[azfake.PollerResponder[resources.TopLevelTrackedResourcesClientUpdateResponse]] +// TopLevelServerTransport connects instances of resources.TopLevelClient to instances of TopLevelServer. +// Don't use this type directly, use NewTopLevelServerTransport instead. +type TopLevelServerTransport struct { + srv *TopLevelServer + beginCreateOrReplace *tracker[azfake.PollerResponder[resources.TopLevelClientCreateOrReplaceResponse]] + beginDelete *tracker[azfake.PollerResponder[resources.TopLevelClientDeleteResponse]] + newListByResourceGroupPager *tracker[azfake.PagerResponder[resources.TopLevelClientListByResourceGroupResponse]] + newListBySubscriptionPager *tracker[azfake.PagerResponder[resources.TopLevelClientListBySubscriptionResponse]] + beginUpdate *tracker[azfake.PollerResponder[resources.TopLevelClientUpdateResponse]] } -// Do implements the policy.Transporter interface for TopLevelTrackedResourcesServerTransport. -func (t *TopLevelTrackedResourcesServerTransport) Do(req *http.Request) (*http.Response, error) { +// Do implements the policy.Transporter interface for TopLevelServerTransport. +func (t *TopLevelServerTransport) Do(req *http.Request) (*http.Response, error) { rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) method, ok := rawMethod.(string) if !ok { @@ -85,31 +85,37 @@ func (t *TopLevelTrackedResourcesServerTransport) Do(req *http.Request) (*http.R return t.dispatchToMethodFake(req, method) } -func (t *TopLevelTrackedResourcesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { resultChan := make(chan result) defer close(resultChan) go func() { + var intercepted bool var res result - switch method { - case "TopLevelTrackedResourcesClient.ActionSync": - res.resp, res.err = t.dispatchActionSync(req) - case "TopLevelTrackedResourcesClient.BeginCreateOrReplace": - res.resp, res.err = t.dispatchBeginCreateOrReplace(req) - case "TopLevelTrackedResourcesClient.BeginDelete": - res.resp, res.err = t.dispatchBeginDelete(req) - case "TopLevelTrackedResourcesClient.Get": - res.resp, res.err = t.dispatchGet(req) - case "TopLevelTrackedResourcesClient.NewListByResourceGroupPager": - res.resp, res.err = t.dispatchNewListByResourceGroupPager(req) - case "TopLevelTrackedResourcesClient.NewListBySubscriptionPager": - res.resp, res.err = t.dispatchNewListBySubscriptionPager(req) - case "TopLevelTrackedResourcesClient.BeginUpdate": - res.resp, res.err = t.dispatchBeginUpdate(req) - default: - res.err = fmt.Errorf("unhandled API %s", method) + if topLevelServerTransportInterceptor != nil { + res.resp, res.err, intercepted = topLevelServerTransportInterceptor.Do(req) } + if !intercepted { + switch method { + case "TopLevelClient.ActionSync": + res.resp, res.err = t.dispatchActionSync(req) + case "TopLevelClient.BeginCreateOrReplace": + res.resp, res.err = t.dispatchBeginCreateOrReplace(req) + case "TopLevelClient.BeginDelete": + res.resp, res.err = t.dispatchBeginDelete(req) + case "TopLevelClient.Get": + res.resp, res.err = t.dispatchGet(req) + case "TopLevelClient.NewListByResourceGroupPager": + res.resp, res.err = t.dispatchNewListByResourceGroupPager(req) + case "TopLevelClient.NewListBySubscriptionPager": + res.resp, res.err = t.dispatchNewListBySubscriptionPager(req) + case "TopLevelClient.BeginUpdate": + res.resp, res.err = t.dispatchBeginUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + } select { case resultChan <- res: case <-req.Context().Done(): @@ -124,11 +130,11 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchToMethodFake(req *http } } -func (t *TopLevelTrackedResourcesServerTransport) dispatchActionSync(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchActionSync(req *http.Request) (*http.Response, error) { if t.srv.ActionSync == nil { return nil, &nonRetriableError{errors.New("fake for method ActionSync not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/actionSync` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/actionSync` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -161,13 +167,13 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchActionSync(req *http.R return resp, nil } -func (t *TopLevelTrackedResourcesServerTransport) dispatchBeginCreateOrReplace(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchBeginCreateOrReplace(req *http.Request) (*http.Response, error) { if t.srv.BeginCreateOrReplace == nil { return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrReplace not implemented")} } beginCreateOrReplace := t.beginCreateOrReplace.get(req) if beginCreateOrReplace == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -209,13 +215,13 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchBeginCreateOrReplace(r return resp, nil } -func (t *TopLevelTrackedResourcesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { if t.srv.BeginDelete == nil { return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} } beginDelete := t.beginDelete.get(req) if beginDelete == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -253,11 +259,11 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchBeginDelete(req *http. return resp, nil } -func (t *TopLevelTrackedResourcesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { if t.srv.Get == nil { return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} } - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -286,13 +292,13 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchGet(req *http.Request) return resp, nil } -func (t *TopLevelTrackedResourcesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { if t.srv.NewListByResourceGroupPager == nil { return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} } newListByResourceGroupPager := t.newListByResourceGroupPager.get(req) if newListByResourceGroupPager == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 2 { @@ -305,7 +311,7 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchNewListByResourceGroup resp := t.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) newListByResourceGroupPager = &resp t.newListByResourceGroupPager.add(req, newListByResourceGroupPager) - server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *resources.TopLevelTrackedResourcesClientListByResourceGroupResponse, createLink func() string) { + server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *resources.TopLevelClientListByResourceGroupResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) }) } @@ -323,13 +329,13 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchNewListByResourceGroup return resp, nil } -func (t *TopLevelTrackedResourcesServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchNewListBySubscriptionPager(req *http.Request) (*http.Response, error) { if t.srv.NewListBySubscriptionPager == nil { return nil, &nonRetriableError{errors.New("fake for method NewListBySubscriptionPager not implemented")} } newListBySubscriptionPager := t.newListBySubscriptionPager.get(req) if newListBySubscriptionPager == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 1 { @@ -338,7 +344,7 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchNewListBySubscriptionP resp := t.srv.NewListBySubscriptionPager(nil) newListBySubscriptionPager = &resp t.newListBySubscriptionPager.add(req, newListBySubscriptionPager) - server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *resources.TopLevelTrackedResourcesClientListBySubscriptionResponse, createLink func() string) { + server.PagerResponderInjectNextLinks(newListBySubscriptionPager, req, func(page *resources.TopLevelClientListBySubscriptionResponse, createLink func() string) { page.NextLink = to.Ptr(createLink()) }) } @@ -356,13 +362,13 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchNewListBySubscriptionP return resp, nil } -func (t *TopLevelTrackedResourcesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { +func (t *TopLevelServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { if t.srv.BeginUpdate == nil { return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} } beginUpdate := t.beginUpdate.get(req) if beginUpdate == nil { - const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Models\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + const regexStr = `/subscriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Azure\.ResourceManager\.Resources/topLevelTrackedResources/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` regex := regexp.MustCompile(regexStr) matches := regex.FindStringSubmatch(req.URL.EscapedPath()) if matches == nil || len(matches) < 3 { @@ -403,3 +409,9 @@ func (t *TopLevelTrackedResourcesServerTransport) dispatchBeginUpdate(req *http. return resp, nil } + +// set this to conditionally intercept incoming requests to TopLevelServerTransport +var topLevelServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/go.mod b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/go.mod similarity index 68% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/go.mod rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/go.mod index bf3688225..248547097 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/go.mod +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/go.mod @@ -3,7 +3,7 @@ module resources go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 github.com/stretchr/testify v1.9.0 ) @@ -11,7 +11,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/text v0.18.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/go.sum b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/go.sum similarity index 72% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/go.sum rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/go.sum index fbfceb4f2..26467d48e 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/go.sum +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/go.sum @@ -1,5 +1,5 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0 h1:nyQWyZvwGTvunIMxi1Y9uXkcyr+I7TeNrr/foo4Kpk8= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0/go.mod h1:l38EPgmsp71HHLq9j7De57JcKOWPyhrsW1Awm1JS6K0= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0/go.mod h1:YL1xnZ6QejvQHWJrX/AvhFl4WW4rqHVoKspWNVwFk0M= github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -11,10 +11,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/nested_client_test.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/nested_client_test.go new file mode 100644 index 000000000..21be3374a --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/nested_client_test.go @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package resources_test + +import ( + "net/http" + "resources" + "testing" + "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/stretchr/testify/require" +) + +var ( + validNestedResource = resources.NestedProxyResource{ + ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top/nestedProxyResources/nested"), + Name: to.Ptr("nested"), + Type: to.Ptr("Azure.ResourceManager.Resources/topLevelTrackedResources/top/nestedProxyResources"), + Properties: &resources.NestedProxyResourceProperties{ + Description: to.Ptr("valid"), + ProvisioningState: to.Ptr(resources.ProvisioningStateSucceeded), + }, + SystemData: &resources.SystemData{ + CreatedBy: to.Ptr("AzureSDK"), + CreatedByType: to.Ptr(resources.CreatedByTypeUser), + CreatedAt: to.Ptr(time.Now()), + LastModifiedBy: to.Ptr("AzureSDK"), + LastModifiedAt: to.Ptr(time.Now()), + LastModifiedByType: to.Ptr(resources.CreatedByTypeUser), + }, + } +) + +func TestNestedClient_Get(t *testing.T) { + nestedClientGetResponse, err := clientFactory.NewNestedClient().Get( + ctx, + "test-rg", + "top", + "nested", + nil, + ) + require.NoError(t, err) + require.Equal(t, *validNestedResource.ID, *nestedClientGetResponse.ID) + require.Equal(t, *validNestedResource.Name, *nestedClientGetResponse.Name) + require.Equal(t, *validNestedResource.Type, *nestedClientGetResponse.Type) + require.Equal(t, *validNestedResource.Properties.Description, *nestedClientGetResponse.Properties.Description) + require.Equal(t, *validNestedResource.Properties.ProvisioningState, *nestedClientGetResponse.Properties.ProvisioningState) +} + +func TestNestedClient_BeginCreateOrReplace(t *testing.T) { + nestedClientCreateOrReplaceResponsePoller, err := clientFactory.NewNestedClient().BeginCreateOrReplace( + ctx, + "test-rg", + "top", + "nested", + resources.NestedProxyResource{ + Properties: &resources.NestedProxyResourceProperties{ + Description: to.Ptr("valid"), + }, + }, + nil, + ) + require.NoError(t, err) + nestedClientCreateOrReplaceResponse, err := nestedClientCreateOrReplaceResponsePoller.PollUntilDone(ctx, nil) + require.NoError(t, err) + require.Equal(t, *validNestedResource.ID, *nestedClientCreateOrReplaceResponse.ID) + require.Equal(t, *validNestedResource.Name, *nestedClientCreateOrReplaceResponse.Name) + require.Equal(t, *validNestedResource.Type, *nestedClientCreateOrReplaceResponse.Type) + require.Equal(t, *validNestedResource.Properties.Description, *nestedClientCreateOrReplaceResponse.Properties.Description) + require.Equal(t, *validNestedResource.Properties.ProvisioningState, *nestedClientCreateOrReplaceResponse.Properties.ProvisioningState) +} + +func TestNestedClient_BeginUpdate(t *testing.T) { + nestedClientUpdateResponsePoller, err := clientFactory.NewNestedClient().BeginUpdate( + ctx, + "test-rg", + "top", + "nested", + resources.NestedProxyResource{ + Properties: &resources.NestedProxyResourceProperties{ + Description: to.Ptr("valid2"), + }, + }, + nil, + ) + require.NoError(t, err) + nestedClientUpdateResponse, err := nestedClientUpdateResponsePoller.PollUntilDone(ctx, nil) + require.NoError(t, err) + require.Equal(t, *validNestedResource.ID, *nestedClientUpdateResponse.ID) + require.Equal(t, *validNestedResource.Name, *nestedClientUpdateResponse.Name) + require.Equal(t, *validNestedResource.Type, *nestedClientUpdateResponse.Type) + require.Equal(t, "valid2", *nestedClientUpdateResponse.Properties.Description) + require.Equal(t, *validNestedResource.Properties.ProvisioningState, *nestedClientUpdateResponse.Properties.ProvisioningState) +} + +func TestNestedClient_BeginDelete(t *testing.T) { + nestedClientDeleteResponsePoller, err := clientFactory.NewNestedClient().BeginDelete(ctx, "test-rg", "top", "nested", nil) + require.NoError(t, err) + nestedClientDeleteResponse, err := nestedClientDeleteResponsePoller.Poll(ctx) + require.NoError(t, err) + require.Equal(t, http.StatusNoContent, nestedClientDeleteResponse.StatusCode) +} + +func TestNestedClient_NewListByTopLevelTrackedResourcePager(t *testing.T) { + nestedClientListByTopLevelTrackedResourceResponsePager := clientFactory.NewNestedClient().NewListByTopLevelTrackedResourcePager("test-rg", "top", nil) + require.True(t, nestedClientListByTopLevelTrackedResourceResponsePager.More()) + nestedClientListByTopLevelTrackedResourceResponse, err := nestedClientListByTopLevelTrackedResourceResponsePager.NextPage(ctx) + require.NoError(t, err) + require.Len(t, nestedClientListByTopLevelTrackedResourceResponse.Value, 1) + require.Equal(t, *validNestedResource.ID, *nestedClientListByTopLevelTrackedResourceResponse.Value[0].ID) + require.Equal(t, *validNestedResource.Name, *nestedClientListByTopLevelTrackedResourceResponse.Value[0].Name) + require.Equal(t, *validNestedResource.Type, *nestedClientListByTopLevelTrackedResourceResponse.Value[0].Type) + require.Equal(t, *validNestedResource.Properties.Description, *nestedClientListByTopLevelTrackedResourceResponse.Value[0].Properties.Description) + require.Equal(t, *validNestedResource.Properties.ProvisioningState, *nestedClientListByTopLevelTrackedResourceResponse.Value[0].Properties.ProvisioningState) +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/singleton_client_test.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/singleton_client_test.go new file mode 100644 index 000000000..501ca5d36 --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/singleton_client_test.go @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package resources_test + +import ( + "resources" + "testing" + "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/stretchr/testify/require" +) + +var ( + validSingletonResource = resources.SingletonTrackedResource{ + ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/singletonTrackedResources/default"), + Name: to.Ptr("default"), + Type: to.Ptr("Azure.ResourceManager.Resources/singletonTrackedResources"), + Location: to.Ptr("eastus"), + Properties: &resources.SingletonTrackedResourceProperties{ + Description: to.Ptr("valid"), + ProvisioningState: to.Ptr(resources.ProvisioningStateSucceeded), + }, + SystemData: &resources.SystemData{ + CreatedBy: to.Ptr("AzureSDK"), + CreatedByType: to.Ptr(resources.CreatedByTypeUser), + CreatedAt: to.Ptr(time.Now()), + LastModifiedBy: to.Ptr("AzureSDK"), + LastModifiedAt: to.Ptr(time.Now()), + LastModifiedByType: to.Ptr(resources.CreatedByTypeUser), + }, + } +) + +func TestSingletonClient_GetByResourceGroup(t *testing.T) { + singletonClientGetByResourceGroupResponse, err := clientFactory.NewSingletonClient().GetByResourceGroup( + ctx, + "test-rg", + nil, + ) + require.NoError(t, err) + require.Equal(t, *validSingletonResource.ID, *singletonClientGetByResourceGroupResponse.ID) + require.Equal(t, *validSingletonResource.Name, *singletonClientGetByResourceGroupResponse.Name) + require.Equal(t, *validSingletonResource.Type, *singletonClientGetByResourceGroupResponse.Type) + require.Equal(t, *validSingletonResource.Location, *singletonClientGetByResourceGroupResponse.Location) + require.Equal(t, *validSingletonResource.Properties.Description, *singletonClientGetByResourceGroupResponse.Properties.Description) + require.Equal(t, *validSingletonResource.Properties.ProvisioningState, *singletonClientGetByResourceGroupResponse.Properties.ProvisioningState) +} + +func TestSingletonClient_BeginCreateOrUpdate(t *testing.T) { + singletonClientBeginCreateOrUpdatePoller, err := clientFactory.NewSingletonClient().BeginCreateOrUpdate( + ctx, + "test-rg", + resources.SingletonTrackedResource{ + Location: to.Ptr("eastus"), + Properties: &resources.SingletonTrackedResourceProperties{ + Description: to.Ptr("valid"), + }, + }, + nil, + ) + require.NoError(t, err) + singletonClientBeginCreateOrUpdateResponse, err := singletonClientBeginCreateOrUpdatePoller.PollUntilDone(ctx, nil) + require.NoError(t, err) + require.Equal(t, *validSingletonResource.ID, *singletonClientBeginCreateOrUpdateResponse.ID) + require.Equal(t, *validSingletonResource.Name, *singletonClientBeginCreateOrUpdateResponse.Name) + require.Equal(t, *validSingletonResource.Type, *singletonClientBeginCreateOrUpdateResponse.Type) + require.Equal(t, *validSingletonResource.Location, *singletonClientBeginCreateOrUpdateResponse.Location) + require.Equal(t, *validSingletonResource.Properties.Description, *singletonClientBeginCreateOrUpdateResponse.Properties.Description) + require.Equal(t, *validSingletonResource.Properties.ProvisioningState, *singletonClientBeginCreateOrUpdateResponse.Properties.ProvisioningState) +} + +func TestSingletonClient_Update(t *testing.T) { + singletonClientUpdateResponse, err := clientFactory.NewSingletonClient().Update( + ctx, + "test-rg", + resources.SingletonTrackedResource{ + Properties: &resources.SingletonTrackedResourceProperties{ + Description: to.Ptr("valid2"), + }, + }, + nil, + ) + require.NoError(t, err) + require.Equal(t, *validSingletonResource.ID, *singletonClientUpdateResponse.ID) + require.Equal(t, *validSingletonResource.Name, *singletonClientUpdateResponse.Name) + require.Equal(t, *validSingletonResource.Type, *singletonClientUpdateResponse.Type) + require.Equal(t, *validSingletonResource.Location, *singletonClientUpdateResponse.Location) + require.Equal(t, "valid2", *singletonClientUpdateResponse.Properties.Description) + require.Equal(t, *validSingletonResource.Properties.ProvisioningState, *singletonClientUpdateResponse.Properties.ProvisioningState) +} + +func TestSingletonClient_NewListByResourceGroupPager(t *testing.T) { + singletonClientListByResourceGroupResponsePager := clientFactory.NewSingletonClient().NewListByResourceGroupPager("test-rg", nil) + require.True(t, singletonClientListByResourceGroupResponsePager.More()) + singletonClientListByResourceGroupResponse, err := singletonClientListByResourceGroupResponsePager.NextPage(ctx) + require.NoError(t, err) + require.Len(t, singletonClientListByResourceGroupResponse.Value, 1) + require.Equal(t, *validSingletonResource.ID, *singletonClientListByResourceGroupResponse.Value[0].ID) + require.Equal(t, *validSingletonResource.Name, *singletonClientListByResourceGroupResponse.Value[0].Name) + require.Equal(t, *validSingletonResource.Type, *singletonClientListByResourceGroupResponse.Value[0].Type) + require.Equal(t, *validSingletonResource.Location, *singletonClientListByResourceGroupResponse.Value[0].Location) + require.Equal(t, *validSingletonResource.Properties.Description, *singletonClientListByResourceGroupResponse.Value[0].Properties.Description) + require.Equal(t, *validSingletonResource.Properties.ProvisioningState, *singletonClientListByResourceGroupResponse.Value[0].Properties.ProvisioningState) +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/toplevel_client_test.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/toplevel_client_test.go new file mode 100644 index 000000000..76fbf1385 --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/toplevel_client_test.go @@ -0,0 +1,155 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package resources_test + +import ( + "fmt" + "net/http" + "testing" + "time" + + "resources" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/stretchr/testify/require" +) + +var ( + validTopLevelResource = resources.TopLevelTrackedResource{ + ID: to.Ptr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top", subscriptionIdExpected, resourceGroupExpected)), + Name: to.Ptr("top"), + Type: to.Ptr("Azure.ResourceManager.Resources/topLevelTrackedResources"), + Location: to.Ptr("eastus"), + Properties: &resources.TopLevelTrackedResourceProperties{ + Description: to.Ptr("valid"), + ProvisioningState: to.Ptr(resources.ProvisioningStateSucceeded), + }, + SystemData: &resources.SystemData{ + CreatedBy: to.Ptr("AzureSDK"), + CreatedByType: to.Ptr(resources.CreatedByTypeUser), + CreatedAt: to.Ptr(time.Now()), + LastModifiedBy: to.Ptr("AzureSDK"), + LastModifiedAt: to.Ptr(time.Now()), + LastModifiedByType: to.Ptr(resources.CreatedByTypeUser), + }, + } +) + +func TestTopLevelClient_Get(t *testing.T) { + topLevelClientGetResponse, err := clientFactory.NewTopLevelClient().Get( + ctx, + "test-rg", + "top", + nil, + ) + require.NoError(t, err) + require.Equal(t, *validTopLevelResource.ID, *topLevelClientGetResponse.ID) + require.Equal(t, *validTopLevelResource.Name, *topLevelClientGetResponse.Name) + require.Equal(t, *validTopLevelResource.Type, *topLevelClientGetResponse.Type) + require.Equal(t, *validTopLevelResource.Location, *topLevelClientGetResponse.Location) + require.Equal(t, *validTopLevelResource.Properties.Description, *topLevelClientGetResponse.Properties.Description) + require.Equal(t, *validTopLevelResource.Properties.ProvisioningState, *topLevelClientGetResponse.Properties.ProvisioningState) +} + +func TestTopLevelClient_CreateOrReplace(t *testing.T) { + topLevelClientCreateOrReplaceResponsePoller, err := clientFactory.NewTopLevelClient().BeginCreateOrReplace( + ctx, + "test-rg", + "top", + resources.TopLevelTrackedResource{ + Location: to.Ptr("eastus"), + Properties: &resources.TopLevelTrackedResourceProperties{ + Description: to.Ptr("valid"), + }, + }, + nil, + ) + require.NoError(t, err) + topLevelClientCreateOrReplaceResponse, err := topLevelClientCreateOrReplaceResponsePoller.PollUntilDone(ctx, nil) + require.NoError(t, err) + require.Equal(t, *validTopLevelResource.ID, *topLevelClientCreateOrReplaceResponse.ID) + require.Equal(t, *validTopLevelResource.Name, *topLevelClientCreateOrReplaceResponse.Name) + require.Equal(t, *validTopLevelResource.Type, *topLevelClientCreateOrReplaceResponse.Type) + require.Equal(t, *validTopLevelResource.Location, *topLevelClientCreateOrReplaceResponse.Location) + require.Equal(t, *validTopLevelResource.Properties.Description, *topLevelClientCreateOrReplaceResponse.Properties.Description) + require.Equal(t, *validTopLevelResource.Properties.ProvisioningState, *topLevelClientCreateOrReplaceResponse.Properties.ProvisioningState) +} + +func TestTopLevelClient_BeginUpdate(t *testing.T) { + topLevelClientUpdateResponsePoller, err := clientFactory.NewTopLevelClient().BeginUpdate( + ctx, + "test-rg", + "top", + resources.TopLevelTrackedResource{ + Properties: &resources.TopLevelTrackedResourceProperties{ + Description: to.Ptr("valid2"), + }, + }, + nil, + ) + require.NoError(t, err) + topLevelClientUpdateResponse, err := topLevelClientUpdateResponsePoller.PollUntilDone(ctx, nil) + require.NoError(t, err) + require.Equal(t, *validTopLevelResource.ID, *topLevelClientUpdateResponse.ID) + require.Equal(t, *validTopLevelResource.Name, *topLevelClientUpdateResponse.Name) + require.Equal(t, *validTopLevelResource.Type, *topLevelClientUpdateResponse.Type) + require.Equal(t, *validTopLevelResource.Location, *topLevelClientUpdateResponse.Location) + require.Equal(t, "valid2", *topLevelClientUpdateResponse.Properties.Description) + require.Equal(t, *validTopLevelResource.Properties.ProvisioningState, *topLevelClientUpdateResponse.Properties.ProvisioningState) +} + +func TestTopLevelClient_BeginDelete(t *testing.T) { + topLevelClientDeleteResponsePoller, err := clientFactory.NewTopLevelClient().BeginDelete( + ctx, + "test-rg", + "top", + nil, + ) + require.NoError(t, err) + topLevelClientDeleteResponse, err := topLevelClientDeleteResponsePoller.Poll(ctx) + require.NoError(t, err) + require.Equal(t, http.StatusNoContent, topLevelClientDeleteResponse.StatusCode) +} + +func TestTopLevelClient_NewListByResourceGroupPager(t *testing.T) { + topLevelClientListByResourceGroupResponsePager := clientFactory.NewTopLevelClient().NewListByResourceGroupPager("test-rg", nil) + require.True(t, topLevelClientListByResourceGroupResponsePager.More()) + topLevelClientListByResourceGroupResponse, err := topLevelClientListByResourceGroupResponsePager.NextPage(ctx) + require.NoError(t, err) + require.Len(t, topLevelClientListByResourceGroupResponse.Value, 1) + require.Equal(t, *validTopLevelResource.ID, *topLevelClientListByResourceGroupResponse.Value[0].ID) + require.Equal(t, *validTopLevelResource.Name, *topLevelClientListByResourceGroupResponse.Value[0].Name) + require.Equal(t, *validTopLevelResource.Type, *topLevelClientListByResourceGroupResponse.Value[0].Type) + require.Equal(t, *validTopLevelResource.Location, *topLevelClientListByResourceGroupResponse.Value[0].Location) + require.Equal(t, *validTopLevelResource.Properties.Description, *topLevelClientListByResourceGroupResponse.Value[0].Properties.Description) + require.Equal(t, *validTopLevelResource.Properties.ProvisioningState, *topLevelClientListByResourceGroupResponse.Value[0].Properties.ProvisioningState) +} + +func TestTopLevelClient_NewListBySubscriptionPager(t *testing.T) { + TopLevelClientListBySubscriptionResponsePager := clientFactory.NewTopLevelClient().NewListBySubscriptionPager(nil) + require.True(t, TopLevelClientListBySubscriptionResponsePager.More()) + TopLevelClientListBySubscriptionResponse, err := TopLevelClientListBySubscriptionResponsePager.NextPage(ctx) + require.NoError(t, err) + require.Len(t, TopLevelClientListBySubscriptionResponse.Value, 1) + require.Equal(t, *validTopLevelResource.ID, *TopLevelClientListBySubscriptionResponse.Value[0].ID) + require.Equal(t, *validTopLevelResource.Name, *TopLevelClientListBySubscriptionResponse.Value[0].Name) + require.Equal(t, *validTopLevelResource.Type, *TopLevelClientListBySubscriptionResponse.Value[0].Type) + require.Equal(t, *validTopLevelResource.Location, *TopLevelClientListBySubscriptionResponse.Value[0].Location) + require.Equal(t, *validTopLevelResource.Properties.Description, *TopLevelClientListBySubscriptionResponse.Value[0].Properties.Description) + require.Equal(t, *validTopLevelResource.Properties.ProvisioningState, *TopLevelClientListBySubscriptionResponse.Value[0].Properties.ProvisioningState) +} + +func TestTopLevelClient_ActionSync(t *testing.T) { + _, err := clientFactory.NewTopLevelClient().ActionSync( + ctx, + resourceGroupExpected, + "top", + resources.NotificationDetails{ + Message: to.Ptr("Resource action at top level."), + Urgent: to.Ptr(true), + }, + nil, + ) + require.NoError(t, err) +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/utils_test.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/utils_test.go similarity index 100% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/utils_test.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/utils_test.go diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_client_factory.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_client_factory.go similarity index 73% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_client_factory.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_client_factory.go index 071efd743..afe344b4a 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_client_factory.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_client_factory.go @@ -32,17 +32,25 @@ func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, }, nil } -// NewNestedProxyResourcesClient creates a new instance of NestedProxyResourcesClient. -func (c *ClientFactory) NewNestedProxyResourcesClient() *NestedProxyResourcesClient { - return &NestedProxyResourcesClient{ +// NewNestedClient creates a new instance of NestedClient. +func (c *ClientFactory) NewNestedClient() *NestedClient { + return &NestedClient{ subscriptionID: c.subscriptionID, internal: c.internal, } } -// NewTopLevelTrackedResourcesClient creates a new instance of TopLevelTrackedResourcesClient. -func (c *ClientFactory) NewTopLevelTrackedResourcesClient() *TopLevelTrackedResourcesClient { - return &TopLevelTrackedResourcesClient{ +// NewSingletonClient creates a new instance of SingletonClient. +func (c *ClientFactory) NewSingletonClient() *SingletonClient { + return &SingletonClient{ + subscriptionID: c.subscriptionID, + internal: c.internal, + } +} + +// NewTopLevelClient creates a new instance of TopLevelClient. +func (c *ClientFactory) NewTopLevelClient() *TopLevelClient { + return &TopLevelClient{ subscriptionID: c.subscriptionID, internal: c.internal, } diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_constants.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_constants.go similarity index 100% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_constants.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_constants.go diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_models.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_models.go similarity index 71% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_models.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_models.go index a9120d6fb..62441035a 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_models.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_models.go @@ -51,6 +51,49 @@ type NotificationDetails struct { Urgent *bool } +// SingletonTrackedResource - Concrete tracked resource types can be created by aliasing this type using a specific property +// type. +type SingletonTrackedResource struct { + // REQUIRED; The geo-location where the resource lives + Location *string + + // The resource-specific properties for this resource. + Properties *SingletonTrackedResourceProperties + + // Resource tags. + Tags map[string]*string + + // READ-ONLY; The name of the SingletonTrackedResource + Name *string + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// SingletonTrackedResourceListResult - The response of a SingletonTrackedResource list operation. +type SingletonTrackedResourceListResult struct { + // REQUIRED; The SingletonTrackedResource items on this page + Value []*SingletonTrackedResource + + // The link to the next page of items + NextLink *string +} + +// SingletonTrackedResourceProperties - Singleton Arm Resource Properties. +type SingletonTrackedResourceProperties struct { + // The description of the resource. + Description *string + + // READ-ONLY; The status of the last operation. + ProvisioningState *ProvisioningState +} + // SystemData - Metadata pertaining to creation and last modification of the resource. type SystemData struct { // The timestamp of resource creation (UTC). diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_models_serde.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_models_serde.go similarity index 73% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_models_serde.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_models_serde.go index 115ab6d28..b49ffe19a 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_models_serde.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_models_serde.go @@ -147,6 +147,119 @@ func (n *NotificationDetails) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type SingletonTrackedResource. +func (s SingletonTrackedResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", s.ID) + populate(objectMap, "location", s.Location) + populate(objectMap, "name", s.Name) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + populate(objectMap, "tags", s.Tags) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SingletonTrackedResource. +func (s *SingletonTrackedResource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &s.ID) + delete(rawMsg, key) + case "location": + err = unpopulate(val, "Location", &s.Location) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &s.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &s.SystemData) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &s.Tags) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SingletonTrackedResourceListResult. +func (s SingletonTrackedResourceListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SingletonTrackedResourceListResult. +func (s *SingletonTrackedResourceListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &s.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &s.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SingletonTrackedResourceProperties. +func (s SingletonTrackedResourceProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "description", s.Description) + populate(objectMap, "provisioningState", s.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SingletonTrackedResourceProperties. +func (s *SingletonTrackedResourceProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "description": + err = unpopulate(val, "Description", &s.Description) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &s.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type SystemData. func (s SystemData) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_nestedproxyresources_client.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_nested_client.go similarity index 67% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_nestedproxyresources_client.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_nested_client.go index 72ccabe57..083462d65 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_nestedproxyresources_client.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_nested_client.go @@ -16,23 +16,23 @@ import ( "strings" ) -// NestedProxyResourcesClient contains the methods for the NestedProxyResources group. -// Don't use this type directly, use NewNestedProxyResourcesClient() instead. -type NestedProxyResourcesClient struct { +// NestedClient contains the methods for the Nested group. +// Don't use this type directly, use NewNestedClient() instead. +type NestedClient struct { internal *arm.Client subscriptionID string } -// NewNestedProxyResourcesClient creates a new instance of NestedProxyResourcesClient with the specified values. +// NewNestedClient creates a new instance of NestedClient with the specified values. // - subscriptionID - The ID of the target subscription. The value must be an UUID. // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. -func NewNestedProxyResourcesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*NestedProxyResourcesClient, error) { +func NewNestedClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*NestedClient, error) { cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } - client := &NestedProxyResourcesClient{ + client := &NestedClient{ subscriptionID: subscriptionID, internal: cl, } @@ -47,20 +47,20 @@ func NewNestedProxyResourcesClient(subscriptionID string, credential azcore.Toke // - topLevelTrackedResourceName - arm resource name for path // - nextedProxyResourceName - Name of the nested resource. // - resource - Resource create parameters. -// - options - NestedProxyResourcesClientBeginCreateOrReplaceOptions contains the optional parameters for the NestedProxyResourcesClient.BeginCreateOrReplace +// - options - NestedClientBeginCreateOrReplaceOptions contains the optional parameters for the NestedClient.BeginCreateOrReplace // method. -func (client *NestedProxyResourcesClient) BeginCreateOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource NestedProxyResource, options *NestedProxyResourcesClientBeginCreateOrReplaceOptions) (*runtime.Poller[NestedProxyResourcesClientCreateOrReplaceResponse], error) { +func (client *NestedClient) BeginCreateOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource NestedProxyResource, options *NestedClientBeginCreateOrReplaceOptions) (*runtime.Poller[NestedClientCreateOrReplaceResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.createOrReplace(ctx, resourceGroupName, topLevelTrackedResourceName, nextedProxyResourceName, resource, options) if err != nil { return nil, err } - poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NestedProxyResourcesClientCreateOrReplaceResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NestedClientCreateOrReplaceResponse]{ Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[NestedProxyResourcesClientCreateOrReplaceResponse]{ + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[NestedClientCreateOrReplaceResponse]{ Tracer: client.internal.Tracer(), }) } @@ -70,9 +70,9 @@ func (client *NestedProxyResourcesClient) BeginCreateOrReplace(ctx context.Conte // If the operation fails it returns an *azcore.ResponseError type. // // Generated from API version 2023-12-01-preview -func (client *NestedProxyResourcesClient) createOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource NestedProxyResource, options *NestedProxyResourcesClientBeginCreateOrReplaceOptions) (*http.Response, error) { +func (client *NestedClient) createOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource NestedProxyResource, options *NestedClientBeginCreateOrReplaceOptions) (*http.Response, error) { var err error - const operationName = "NestedProxyResourcesClient.BeginCreateOrReplace" + const operationName = "NestedClient.BeginCreateOrReplace" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() @@ -92,8 +92,8 @@ func (client *NestedProxyResourcesClient) createOrReplace(ctx context.Context, r } // createOrReplaceCreateRequest creates the CreateOrReplace request. -func (client *NestedProxyResourcesClient) createOrReplaceCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource NestedProxyResource, _ *NestedProxyResourcesClientBeginCreateOrReplaceOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" +func (client *NestedClient) createOrReplaceCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, resource NestedProxyResource, _ *NestedClientBeginCreateOrReplaceOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -132,20 +132,19 @@ func (client *NestedProxyResourcesClient) createOrReplaceCreateRequest(ctx conte // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path // - nextedProxyResourceName - Name of the nested resource. -// - options - NestedProxyResourcesClientBeginDeleteOptions contains the optional parameters for the NestedProxyResourcesClient.BeginDelete -// method. -func (client *NestedProxyResourcesClient) BeginDelete(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *NestedProxyResourcesClientBeginDeleteOptions) (*runtime.Poller[NestedProxyResourcesClientDeleteResponse], error) { +// - options - NestedClientBeginDeleteOptions contains the optional parameters for the NestedClient.BeginDelete method. +func (client *NestedClient) BeginDelete(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *NestedClientBeginDeleteOptions) (*runtime.Poller[NestedClientDeleteResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.deleteOperation(ctx, resourceGroupName, topLevelTrackedResourceName, nextedProxyResourceName, options) if err != nil { return nil, err } - poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NestedProxyResourcesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NestedClientDeleteResponse]{ Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[NestedProxyResourcesClientDeleteResponse]{ + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[NestedClientDeleteResponse]{ Tracer: client.internal.Tracer(), }) } @@ -155,9 +154,9 @@ func (client *NestedProxyResourcesClient) BeginDelete(ctx context.Context, resou // If the operation fails it returns an *azcore.ResponseError type. // // Generated from API version 2023-12-01-preview -func (client *NestedProxyResourcesClient) deleteOperation(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *NestedProxyResourcesClientBeginDeleteOptions) (*http.Response, error) { +func (client *NestedClient) deleteOperation(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *NestedClientBeginDeleteOptions) (*http.Response, error) { var err error - const operationName = "NestedProxyResourcesClient.BeginDelete" + const operationName = "NestedClient.BeginDelete" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() @@ -177,8 +176,8 @@ func (client *NestedProxyResourcesClient) deleteOperation(ctx context.Context, r } // deleteCreateRequest creates the Delete request. -func (client *NestedProxyResourcesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, _ *NestedProxyResourcesClientBeginDeleteOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" +func (client *NestedClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, _ *NestedClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -213,33 +212,32 @@ func (client *NestedProxyResourcesClient) deleteCreateRequest(ctx context.Contex // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path // - nextedProxyResourceName - Name of the nested resource. -// - options - NestedProxyResourcesClientGetOptions contains the optional parameters for the NestedProxyResourcesClient.Get -// method. -func (client *NestedProxyResourcesClient) Get(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *NestedProxyResourcesClientGetOptions) (NestedProxyResourcesClientGetResponse, error) { +// - options - NestedClientGetOptions contains the optional parameters for the NestedClient.Get method. +func (client *NestedClient) Get(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, options *NestedClientGetOptions) (NestedClientGetResponse, error) { var err error - const operationName = "NestedProxyResourcesClient.Get" + const operationName = "NestedClient.Get" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceGroupName, topLevelTrackedResourceName, nextedProxyResourceName, options) if err != nil { - return NestedProxyResourcesClientGetResponse{}, err + return NestedClientGetResponse{}, err } httpResp, err := client.internal.Pipeline().Do(req) if err != nil { - return NestedProxyResourcesClientGetResponse{}, err + return NestedClientGetResponse{}, err } if !runtime.HasStatusCode(httpResp, http.StatusOK) { err = runtime.NewResponseError(httpResp) - return NestedProxyResourcesClientGetResponse{}, err + return NestedClientGetResponse{}, err } resp, err := client.getHandleResponse(httpResp) return resp, err } // getCreateRequest creates the Get request. -func (client *NestedProxyResourcesClient) getCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, _ *NestedProxyResourcesClientGetOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" +func (client *NestedClient) getCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, _ *NestedClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -268,10 +266,10 @@ func (client *NestedProxyResourcesClient) getCreateRequest(ctx context.Context, } // getHandleResponse handles the Get response. -func (client *NestedProxyResourcesClient) getHandleResponse(resp *http.Response) (NestedProxyResourcesClientGetResponse, error) { - result := NestedProxyResourcesClientGetResponse{} +func (client *NestedClient) getHandleResponse(resp *http.Response) (NestedClientGetResponse, error) { + result := NestedClientGetResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.NestedProxyResource); err != nil { - return NestedProxyResourcesClientGetResponse{}, err + return NestedClientGetResponse{}, err } return result, nil } @@ -281,15 +279,15 @@ func (client *NestedProxyResourcesClient) getHandleResponse(resp *http.Response) // Generated from API version 2023-12-01-preview // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path -// - options - NestedProxyResourcesClientListByTopLevelTrackedResourceOptions contains the optional parameters for the NestedProxyResourcesClient.NewListByTopLevelTrackedResourcePager +// - options - NestedClientListByTopLevelTrackedResourceOptions contains the optional parameters for the NestedClient.NewListByTopLevelTrackedResourcePager // method. -func (client *NestedProxyResourcesClient) NewListByTopLevelTrackedResourcePager(resourceGroupName string, topLevelTrackedResourceName string, options *NestedProxyResourcesClientListByTopLevelTrackedResourceOptions) *runtime.Pager[NestedProxyResourcesClientListByTopLevelTrackedResourceResponse] { - return runtime.NewPager(runtime.PagingHandler[NestedProxyResourcesClientListByTopLevelTrackedResourceResponse]{ - More: func(page NestedProxyResourcesClientListByTopLevelTrackedResourceResponse) bool { +func (client *NestedClient) NewListByTopLevelTrackedResourcePager(resourceGroupName string, topLevelTrackedResourceName string, options *NestedClientListByTopLevelTrackedResourceOptions) *runtime.Pager[NestedClientListByTopLevelTrackedResourceResponse] { + return runtime.NewPager(runtime.PagingHandler[NestedClientListByTopLevelTrackedResourceResponse]{ + More: func(page NestedClientListByTopLevelTrackedResourceResponse) bool { return page.NextLink != nil && len(*page.NextLink) > 0 }, - Fetcher: func(ctx context.Context, page *NestedProxyResourcesClientListByTopLevelTrackedResourceResponse) (NestedProxyResourcesClientListByTopLevelTrackedResourceResponse, error) { - ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "NestedProxyResourcesClient.NewListByTopLevelTrackedResourcePager") + Fetcher: func(ctx context.Context, page *NestedClientListByTopLevelTrackedResourceResponse) (NestedClientListByTopLevelTrackedResourceResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "NestedClient.NewListByTopLevelTrackedResourcePager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -298,7 +296,7 @@ func (client *NestedProxyResourcesClient) NewListByTopLevelTrackedResourcePager( return client.listByTopLevelTrackedResourceCreateRequest(ctx, resourceGroupName, topLevelTrackedResourceName, options) }, nil) if err != nil { - return NestedProxyResourcesClientListByTopLevelTrackedResourceResponse{}, err + return NestedClientListByTopLevelTrackedResourceResponse{}, err } return client.listByTopLevelTrackedResourceHandleResponse(resp) }, @@ -307,8 +305,8 @@ func (client *NestedProxyResourcesClient) NewListByTopLevelTrackedResourcePager( } // listByTopLevelTrackedResourceCreateRequest creates the ListByTopLevelTrackedResource request. -func (client *NestedProxyResourcesClient) listByTopLevelTrackedResourceCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, _ *NestedProxyResourcesClientListByTopLevelTrackedResourceOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources" +func (client *NestedClient) listByTopLevelTrackedResourceCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, _ *NestedClientListByTopLevelTrackedResourceOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -333,10 +331,10 @@ func (client *NestedProxyResourcesClient) listByTopLevelTrackedResourceCreateReq } // listByTopLevelTrackedResourceHandleResponse handles the ListByTopLevelTrackedResource response. -func (client *NestedProxyResourcesClient) listByTopLevelTrackedResourceHandleResponse(resp *http.Response) (NestedProxyResourcesClientListByTopLevelTrackedResourceResponse, error) { - result := NestedProxyResourcesClientListByTopLevelTrackedResourceResponse{} +func (client *NestedClient) listByTopLevelTrackedResourceHandleResponse(resp *http.Response) (NestedClientListByTopLevelTrackedResourceResponse, error) { + result := NestedClientListByTopLevelTrackedResourceResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.NestedProxyResourceListResult); err != nil { - return NestedProxyResourcesClientListByTopLevelTrackedResourceResponse{}, err + return NestedClientListByTopLevelTrackedResourceResponse{}, err } return result, nil } @@ -349,20 +347,19 @@ func (client *NestedProxyResourcesClient) listByTopLevelTrackedResourceHandleRes // - topLevelTrackedResourceName - arm resource name for path // - nextedProxyResourceName - Name of the nested resource. // - properties - The resource properties to be updated. -// - options - NestedProxyResourcesClientBeginUpdateOptions contains the optional parameters for the NestedProxyResourcesClient.BeginUpdate -// method. -func (client *NestedProxyResourcesClient) BeginUpdate(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties NestedProxyResource, options *NestedProxyResourcesClientBeginUpdateOptions) (*runtime.Poller[NestedProxyResourcesClientUpdateResponse], error) { +// - options - NestedClientBeginUpdateOptions contains the optional parameters for the NestedClient.BeginUpdate method. +func (client *NestedClient) BeginUpdate(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties NestedProxyResource, options *NestedClientBeginUpdateOptions) (*runtime.Poller[NestedClientUpdateResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.update(ctx, resourceGroupName, topLevelTrackedResourceName, nextedProxyResourceName, properties, options) if err != nil { return nil, err } - poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NestedProxyResourcesClientUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[NestedClientUpdateResponse]{ Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[NestedProxyResourcesClientUpdateResponse]{ + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[NestedClientUpdateResponse]{ Tracer: client.internal.Tracer(), }) } @@ -372,9 +369,9 @@ func (client *NestedProxyResourcesClient) BeginUpdate(ctx context.Context, resou // If the operation fails it returns an *azcore.ResponseError type. // // Generated from API version 2023-12-01-preview -func (client *NestedProxyResourcesClient) update(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties NestedProxyResource, options *NestedProxyResourcesClientBeginUpdateOptions) (*http.Response, error) { +func (client *NestedClient) update(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties NestedProxyResource, options *NestedClientBeginUpdateOptions) (*http.Response, error) { var err error - const operationName = "NestedProxyResourcesClient.BeginUpdate" + const operationName = "NestedClient.BeginUpdate" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() @@ -394,8 +391,8 @@ func (client *NestedProxyResourcesClient) update(ctx context.Context, resourceGr } // updateCreateRequest creates the Update request. -func (client *NestedProxyResourcesClient) updateCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties NestedProxyResource, _ *NestedProxyResourcesClientBeginUpdateOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" +func (client *NestedClient) updateCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, nextedProxyResourceName string, properties NestedProxyResource, _ *NestedClientBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/nestedProxyResources/{nextedProxyResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_options.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_options.go new file mode 100644 index 000000000..80df66334 --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_options.go @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package resources + +// NestedClientBeginCreateOrReplaceOptions contains the optional parameters for the NestedClient.BeginCreateOrReplace method. +type NestedClientBeginCreateOrReplaceOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// NestedClientBeginDeleteOptions contains the optional parameters for the NestedClient.BeginDelete method. +type NestedClientBeginDeleteOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// NestedClientBeginUpdateOptions contains the optional parameters for the NestedClient.BeginUpdate method. +type NestedClientBeginUpdateOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// NestedClientGetOptions contains the optional parameters for the NestedClient.Get method. +type NestedClientGetOptions struct { + // placeholder for future optional parameters +} + +// NestedClientListByTopLevelTrackedResourceOptions contains the optional parameters for the NestedClient.NewListByTopLevelTrackedResourcePager +// method. +type NestedClientListByTopLevelTrackedResourceOptions struct { + // placeholder for future optional parameters +} + +// SingletonClientBeginCreateOrUpdateOptions contains the optional parameters for the SingletonClient.BeginCreateOrUpdate +// method. +type SingletonClientBeginCreateOrUpdateOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// SingletonClientGetByResourceGroupOptions contains the optional parameters for the SingletonClient.GetByResourceGroup method. +type SingletonClientGetByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// SingletonClientListByResourceGroupOptions contains the optional parameters for the SingletonClient.NewListByResourceGroupPager +// method. +type SingletonClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// SingletonClientUpdateOptions contains the optional parameters for the SingletonClient.Update method. +type SingletonClientUpdateOptions struct { + // placeholder for future optional parameters +} + +// TopLevelClientActionSyncOptions contains the optional parameters for the TopLevelClient.ActionSync method. +type TopLevelClientActionSyncOptions struct { + // placeholder for future optional parameters +} + +// TopLevelClientBeginCreateOrReplaceOptions contains the optional parameters for the TopLevelClient.BeginCreateOrReplace +// method. +type TopLevelClientBeginCreateOrReplaceOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// TopLevelClientBeginDeleteOptions contains the optional parameters for the TopLevelClient.BeginDelete method. +type TopLevelClientBeginDeleteOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// TopLevelClientBeginUpdateOptions contains the optional parameters for the TopLevelClient.BeginUpdate method. +type TopLevelClientBeginUpdateOptions struct { + // Resumes the long-running operation from the provided token. + ResumeToken string +} + +// TopLevelClientGetOptions contains the optional parameters for the TopLevelClient.Get method. +type TopLevelClientGetOptions struct { + // placeholder for future optional parameters +} + +// TopLevelClientListByResourceGroupOptions contains the optional parameters for the TopLevelClient.NewListByResourceGroupPager +// method. +type TopLevelClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// TopLevelClientListBySubscriptionOptions contains the optional parameters for the TopLevelClient.NewListBySubscriptionPager +// method. +type TopLevelClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_responses.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_responses.go new file mode 100644 index 000000000..6774013e4 --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_responses.go @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package resources + +// NestedClientCreateOrReplaceResponse contains the response from method NestedClient.BeginCreateOrReplace. +type NestedClientCreateOrReplaceResponse struct { + // Nested child of Top Level Tracked Resource. + NestedProxyResource +} + +// NestedClientDeleteResponse contains the response from method NestedClient.BeginDelete. +type NestedClientDeleteResponse struct { + // placeholder for future response values +} + +// NestedClientGetResponse contains the response from method NestedClient.Get. +type NestedClientGetResponse struct { + // Nested child of Top Level Tracked Resource. + NestedProxyResource +} + +// NestedClientListByTopLevelTrackedResourceResponse contains the response from method NestedClient.NewListByTopLevelTrackedResourcePager. +type NestedClientListByTopLevelTrackedResourceResponse struct { + // The response of a NestedProxyResource list operation. + NestedProxyResourceListResult +} + +// NestedClientUpdateResponse contains the response from method NestedClient.BeginUpdate. +type NestedClientUpdateResponse struct { + // Nested child of Top Level Tracked Resource. + NestedProxyResource +} + +// SingletonClientCreateOrUpdateResponse contains the response from method SingletonClient.BeginCreateOrUpdate. +type SingletonClientCreateOrUpdateResponse struct { + // Concrete tracked resource types can be created by aliasing this type using a specific property type. + SingletonTrackedResource +} + +// SingletonClientGetByResourceGroupResponse contains the response from method SingletonClient.GetByResourceGroup. +type SingletonClientGetByResourceGroupResponse struct { + // Concrete tracked resource types can be created by aliasing this type using a specific property type. + SingletonTrackedResource +} + +// SingletonClientListByResourceGroupResponse contains the response from method SingletonClient.NewListByResourceGroupPager. +type SingletonClientListByResourceGroupResponse struct { + // The response of a SingletonTrackedResource list operation. + SingletonTrackedResourceListResult +} + +// SingletonClientUpdateResponse contains the response from method SingletonClient.Update. +type SingletonClientUpdateResponse struct { + // Concrete tracked resource types can be created by aliasing this type using a specific property type. + SingletonTrackedResource +} + +// TopLevelClientActionSyncResponse contains the response from method TopLevelClient.ActionSync. +type TopLevelClientActionSyncResponse struct { + // placeholder for future response values +} + +// TopLevelClientCreateOrReplaceResponse contains the response from method TopLevelClient.BeginCreateOrReplace. +type TopLevelClientCreateOrReplaceResponse struct { + // Concrete tracked resource types can be created by aliasing this type using a specific property type. + TopLevelTrackedResource +} + +// TopLevelClientDeleteResponse contains the response from method TopLevelClient.BeginDelete. +type TopLevelClientDeleteResponse struct { + // placeholder for future response values +} + +// TopLevelClientGetResponse contains the response from method TopLevelClient.Get. +type TopLevelClientGetResponse struct { + // Concrete tracked resource types can be created by aliasing this type using a specific property type. + TopLevelTrackedResource +} + +// TopLevelClientListByResourceGroupResponse contains the response from method TopLevelClient.NewListByResourceGroupPager. +type TopLevelClientListByResourceGroupResponse struct { + // The response of a TopLevelTrackedResource list operation. + TopLevelTrackedResourceListResult +} + +// TopLevelClientListBySubscriptionResponse contains the response from method TopLevelClient.NewListBySubscriptionPager. +type TopLevelClientListBySubscriptionResponse struct { + // The response of a TopLevelTrackedResource list operation. + TopLevelTrackedResourceListResult +} + +// TopLevelClientUpdateResponse contains the response from method TopLevelClient.BeginUpdate. +type TopLevelClientUpdateResponse struct { + // Concrete tracked resource types can be created by aliasing this type using a specific property type. + TopLevelTrackedResource +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_singleton_client.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_singleton_client.go new file mode 100644 index 000000000..b72436d6f --- /dev/null +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_singleton_client.go @@ -0,0 +1,300 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package resources + +import ( + "context" + "errors" + "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/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// SingletonClient contains the methods for the Singleton group. +// Don't use this type directly, use NewSingletonClient() instead. +type SingletonClient struct { + internal *arm.Client + subscriptionID string +} + +// NewSingletonClient creates a new instance of SingletonClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewSingletonClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SingletonClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &SingletonClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginCreateOrUpdate - Create a SingletonTrackedResource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-12-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - resource - Resource create parameters. +// - options - SingletonClientBeginCreateOrUpdateOptions contains the optional parameters for the SingletonClient.BeginCreateOrUpdate +// method. +func (client *SingletonClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, resource SingletonTrackedResource, options *SingletonClientBeginCreateOrUpdateOptions) (*runtime.Poller[SingletonClientCreateOrUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.createOrUpdate(ctx, resourceGroupName, resource, options) + if err != nil { + return nil, err + } + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SingletonClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + return poller, err + } else { + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SingletonClientCreateOrUpdateResponse]{ + Tracer: client.internal.Tracer(), + }) + } +} + +// CreateOrUpdate - Create a SingletonTrackedResource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-12-01-preview +func (client *SingletonClient) createOrUpdate(ctx context.Context, resourceGroupName string, resource SingletonTrackedResource, options *SingletonClientBeginCreateOrUpdateOptions) (*http.Response, error) { + var err error + const operationName = "SingletonClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, resource, options) + if err != nil { + return nil, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return nil, err + } + return httpResp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *SingletonClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, resource SingletonTrackedResource, _ *SingletonClientBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/singletonTrackedResources/default" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-12-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, resource); err != nil { + return nil, err + } + return req, nil +} + +// GetByResourceGroup - Get a SingletonTrackedResource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-12-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - options - SingletonClientGetByResourceGroupOptions contains the optional parameters for the SingletonClient.GetByResourceGroup +// method. +func (client *SingletonClient) GetByResourceGroup(ctx context.Context, resourceGroupName string, options *SingletonClientGetByResourceGroupOptions) (SingletonClientGetByResourceGroupResponse, error) { + var err error + const operationName = "SingletonClient.GetByResourceGroup" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.getByResourceGroupCreateRequest(ctx, resourceGroupName, options) + if err != nil { + return SingletonClientGetByResourceGroupResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return SingletonClientGetByResourceGroupResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SingletonClientGetByResourceGroupResponse{}, err + } + resp, err := client.getByResourceGroupHandleResponse(httpResp) + return resp, err +} + +// getByResourceGroupCreateRequest creates the GetByResourceGroup request. +func (client *SingletonClient) getByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *SingletonClientGetByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/singletonTrackedResources/default" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-12-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getByResourceGroupHandleResponse handles the GetByResourceGroup response. +func (client *SingletonClient) getByResourceGroupHandleResponse(resp *http.Response) (SingletonClientGetByResourceGroupResponse, error) { + result := SingletonClientGetByResourceGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SingletonTrackedResource); err != nil { + return SingletonClientGetByResourceGroupResponse{}, err + } + return result, nil +} + +// NewListByResourceGroupPager - List SingletonTrackedResource resources by resource group +// +// Generated from API version 2023-12-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - options - SingletonClientListByResourceGroupOptions contains the optional parameters for the SingletonClient.NewListByResourceGroupPager +// method. +func (client *SingletonClient) NewListByResourceGroupPager(resourceGroupName string, options *SingletonClientListByResourceGroupOptions) *runtime.Pager[SingletonClientListByResourceGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[SingletonClientListByResourceGroupResponse]{ + More: func(page SingletonClientListByResourceGroupResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *SingletonClientListByResourceGroupResponse) (SingletonClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SingletonClient.NewListByResourceGroupPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, nil) + if err != nil { + return SingletonClientListByResourceGroupResponse{}, err + } + return client.listByResourceGroupHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *SingletonClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *SingletonClientListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/singletonTrackedResources" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-12-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *SingletonClient) listByResourceGroupHandleResponse(resp *http.Response) (SingletonClientListByResourceGroupResponse, error) { + result := SingletonClientListByResourceGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SingletonTrackedResourceListResult); err != nil { + return SingletonClientListByResourceGroupResponse{}, err + } + return result, nil +} + +// Update - Update a SingletonTrackedResource +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-12-01-preview +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - properties - The resource properties to be updated. +// - options - SingletonClientUpdateOptions contains the optional parameters for the SingletonClient.Update method. +func (client *SingletonClient) Update(ctx context.Context, resourceGroupName string, properties SingletonTrackedResource, options *SingletonClientUpdateOptions) (SingletonClientUpdateResponse, error) { + var err error + const operationName = "SingletonClient.Update" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.updateCreateRequest(ctx, resourceGroupName, properties, options) + if err != nil { + return SingletonClientUpdateResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return SingletonClientUpdateResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SingletonClientUpdateResponse{}, err + } + resp, err := client.updateHandleResponse(httpResp) + return resp, err +} + +// updateCreateRequest creates the Update request. +func (client *SingletonClient) updateCreateRequest(ctx context.Context, resourceGroupName string, properties SingletonTrackedResource, _ *SingletonClientUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/singletonTrackedResources/default" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-12-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, properties); err != nil { + return nil, err + } + return req, nil +} + +// updateHandleResponse handles the Update response. +func (client *SingletonClient) updateHandleResponse(resp *http.Response) (SingletonClientUpdateResponse, error) { + result := SingletonClientUpdateResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SingletonTrackedResource); err != nil { + return SingletonClientUpdateResponse{}, err + } + return result, nil +} diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_time_rfc3339.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_time_rfc3339.go similarity index 100% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_time_rfc3339.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_time_rfc3339.go diff --git a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_topleveltrackedresources_client.go b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_toplevel_client.go similarity index 64% rename from packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_topleveltrackedresources_client.go rename to packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_toplevel_client.go index 7344aae41..59f4a5fd9 100644 --- a/packages/typespec-go/test/cadlranch/azure/resource-manager/models/resources/zz_topleveltrackedresources_client.go +++ b/packages/typespec-go/test/cadlranch/azure/resource-manager/resources/zz_toplevel_client.go @@ -16,23 +16,23 @@ import ( "strings" ) -// TopLevelTrackedResourcesClient contains the methods for the TopLevelTrackedResources group. -// Don't use this type directly, use NewTopLevelTrackedResourcesClient() instead. -type TopLevelTrackedResourcesClient struct { +// TopLevelClient contains the methods for the TopLevel group. +// Don't use this type directly, use NewTopLevelClient() instead. +type TopLevelClient struct { internal *arm.Client subscriptionID string } -// NewTopLevelTrackedResourcesClient creates a new instance of TopLevelTrackedResourcesClient with the specified values. +// NewTopLevelClient creates a new instance of TopLevelClient with the specified values. // - subscriptionID - The ID of the target subscription. The value must be an UUID. // - credential - used to authorize requests. Usually a credential from azidentity. // - options - pass nil to accept the default values. -func NewTopLevelTrackedResourcesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*TopLevelTrackedResourcesClient, error) { +func NewTopLevelClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*TopLevelClient, error) { cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) if err != nil { return nil, err } - client := &TopLevelTrackedResourcesClient{ + client := &TopLevelClient{ subscriptionID: subscriptionID, internal: cl, } @@ -46,32 +46,31 @@ func NewTopLevelTrackedResourcesClient(subscriptionID string, credential azcore. // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path // - body - The content of the action request -// - options - TopLevelTrackedResourcesClientActionSyncOptions contains the optional parameters for the TopLevelTrackedResourcesClient.ActionSync -// method. -func (client *TopLevelTrackedResourcesClient) ActionSync(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, body NotificationDetails, options *TopLevelTrackedResourcesClientActionSyncOptions) (TopLevelTrackedResourcesClientActionSyncResponse, error) { +// - options - TopLevelClientActionSyncOptions contains the optional parameters for the TopLevelClient.ActionSync method. +func (client *TopLevelClient) ActionSync(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, body NotificationDetails, options *TopLevelClientActionSyncOptions) (TopLevelClientActionSyncResponse, error) { var err error - const operationName = "TopLevelTrackedResourcesClient.ActionSync" + const operationName = "TopLevelClient.ActionSync" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.actionSyncCreateRequest(ctx, resourceGroupName, topLevelTrackedResourceName, body, options) if err != nil { - return TopLevelTrackedResourcesClientActionSyncResponse{}, err + return TopLevelClientActionSyncResponse{}, err } httpResp, err := client.internal.Pipeline().Do(req) if err != nil { - return TopLevelTrackedResourcesClientActionSyncResponse{}, err + return TopLevelClientActionSyncResponse{}, err } if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { err = runtime.NewResponseError(httpResp) - return TopLevelTrackedResourcesClientActionSyncResponse{}, err + return TopLevelClientActionSyncResponse{}, err } - return TopLevelTrackedResourcesClientActionSyncResponse{}, nil + return TopLevelClientActionSyncResponse{}, nil } // actionSyncCreateRequest creates the ActionSync request. -func (client *TopLevelTrackedResourcesClient) actionSyncCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, body NotificationDetails, _ *TopLevelTrackedResourcesClientActionSyncOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/actionSync" +func (client *TopLevelClient) actionSyncCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, body NotificationDetails, _ *TopLevelClientActionSyncOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}/actionSync" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -106,20 +105,20 @@ func (client *TopLevelTrackedResourcesClient) actionSyncCreateRequest(ctx contex // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path // - resource - Resource create parameters. -// - options - TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions contains the optional parameters for the TopLevelTrackedResourcesClient.BeginCreateOrReplace +// - options - TopLevelClientBeginCreateOrReplaceOptions contains the optional parameters for the TopLevelClient.BeginCreateOrReplace // method. -func (client *TopLevelTrackedResourcesClient) BeginCreateOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource TopLevelTrackedResource, options *TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions) (*runtime.Poller[TopLevelTrackedResourcesClientCreateOrReplaceResponse], error) { +func (client *TopLevelClient) BeginCreateOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource TopLevelTrackedResource, options *TopLevelClientBeginCreateOrReplaceOptions) (*runtime.Poller[TopLevelClientCreateOrReplaceResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.createOrReplace(ctx, resourceGroupName, topLevelTrackedResourceName, resource, options) if err != nil { return nil, err } - poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TopLevelTrackedResourcesClientCreateOrReplaceResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TopLevelClientCreateOrReplaceResponse]{ Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TopLevelTrackedResourcesClientCreateOrReplaceResponse]{ + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TopLevelClientCreateOrReplaceResponse]{ Tracer: client.internal.Tracer(), }) } @@ -129,9 +128,9 @@ func (client *TopLevelTrackedResourcesClient) BeginCreateOrReplace(ctx context.C // If the operation fails it returns an *azcore.ResponseError type. // // Generated from API version 2023-12-01-preview -func (client *TopLevelTrackedResourcesClient) createOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource TopLevelTrackedResource, options *TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions) (*http.Response, error) { +func (client *TopLevelClient) createOrReplace(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource TopLevelTrackedResource, options *TopLevelClientBeginCreateOrReplaceOptions) (*http.Response, error) { var err error - const operationName = "TopLevelTrackedResourcesClient.BeginCreateOrReplace" + const operationName = "TopLevelClient.BeginCreateOrReplace" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() @@ -151,8 +150,8 @@ func (client *TopLevelTrackedResourcesClient) createOrReplace(ctx context.Contex } // createOrReplaceCreateRequest creates the CreateOrReplace request. -func (client *TopLevelTrackedResourcesClient) createOrReplaceCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource TopLevelTrackedResource, _ *TopLevelTrackedResourcesClientBeginCreateOrReplaceOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" +func (client *TopLevelClient) createOrReplaceCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, resource TopLevelTrackedResource, _ *TopLevelClientBeginCreateOrReplaceOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -186,20 +185,19 @@ func (client *TopLevelTrackedResourcesClient) createOrReplaceCreateRequest(ctx c // Generated from API version 2023-12-01-preview // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path -// - options - TopLevelTrackedResourcesClientBeginDeleteOptions contains the optional parameters for the TopLevelTrackedResourcesClient.BeginDelete -// method. -func (client *TopLevelTrackedResourcesClient) BeginDelete(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *TopLevelTrackedResourcesClientBeginDeleteOptions) (*runtime.Poller[TopLevelTrackedResourcesClientDeleteResponse], error) { +// - options - TopLevelClientBeginDeleteOptions contains the optional parameters for the TopLevelClient.BeginDelete method. +func (client *TopLevelClient) BeginDelete(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *TopLevelClientBeginDeleteOptions) (*runtime.Poller[TopLevelClientDeleteResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.deleteOperation(ctx, resourceGroupName, topLevelTrackedResourceName, options) if err != nil { return nil, err } - poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TopLevelTrackedResourcesClientDeleteResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TopLevelClientDeleteResponse]{ Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TopLevelTrackedResourcesClientDeleteResponse]{ + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TopLevelClientDeleteResponse]{ Tracer: client.internal.Tracer(), }) } @@ -209,9 +207,9 @@ func (client *TopLevelTrackedResourcesClient) BeginDelete(ctx context.Context, r // If the operation fails it returns an *azcore.ResponseError type. // // Generated from API version 2023-12-01-preview -func (client *TopLevelTrackedResourcesClient) deleteOperation(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *TopLevelTrackedResourcesClientBeginDeleteOptions) (*http.Response, error) { +func (client *TopLevelClient) deleteOperation(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *TopLevelClientBeginDeleteOptions) (*http.Response, error) { var err error - const operationName = "TopLevelTrackedResourcesClient.BeginDelete" + const operationName = "TopLevelClient.BeginDelete" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() @@ -231,8 +229,8 @@ func (client *TopLevelTrackedResourcesClient) deleteOperation(ctx context.Contex } // deleteCreateRequest creates the Delete request. -func (client *TopLevelTrackedResourcesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, _ *TopLevelTrackedResourcesClientBeginDeleteOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" +func (client *TopLevelClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, _ *TopLevelClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -262,33 +260,32 @@ func (client *TopLevelTrackedResourcesClient) deleteCreateRequest(ctx context.Co // Generated from API version 2023-12-01-preview // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path -// - options - TopLevelTrackedResourcesClientGetOptions contains the optional parameters for the TopLevelTrackedResourcesClient.Get -// method. -func (client *TopLevelTrackedResourcesClient) Get(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *TopLevelTrackedResourcesClientGetOptions) (TopLevelTrackedResourcesClientGetResponse, error) { +// - options - TopLevelClientGetOptions contains the optional parameters for the TopLevelClient.Get method. +func (client *TopLevelClient) Get(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, options *TopLevelClientGetOptions) (TopLevelClientGetResponse, error) { var err error - const operationName = "TopLevelTrackedResourcesClient.Get" + const operationName = "TopLevelClient.Get" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, resourceGroupName, topLevelTrackedResourceName, options) if err != nil { - return TopLevelTrackedResourcesClientGetResponse{}, err + return TopLevelClientGetResponse{}, err } httpResp, err := client.internal.Pipeline().Do(req) if err != nil { - return TopLevelTrackedResourcesClientGetResponse{}, err + return TopLevelClientGetResponse{}, err } if !runtime.HasStatusCode(httpResp, http.StatusOK) { err = runtime.NewResponseError(httpResp) - return TopLevelTrackedResourcesClientGetResponse{}, err + return TopLevelClientGetResponse{}, err } resp, err := client.getHandleResponse(httpResp) return resp, err } // getCreateRequest creates the Get request. -func (client *TopLevelTrackedResourcesClient) getCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, _ *TopLevelTrackedResourcesClientGetOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" +func (client *TopLevelClient) getCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, _ *TopLevelClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -313,10 +310,10 @@ func (client *TopLevelTrackedResourcesClient) getCreateRequest(ctx context.Conte } // getHandleResponse handles the Get response. -func (client *TopLevelTrackedResourcesClient) getHandleResponse(resp *http.Response) (TopLevelTrackedResourcesClientGetResponse, error) { - result := TopLevelTrackedResourcesClientGetResponse{} +func (client *TopLevelClient) getHandleResponse(resp *http.Response) (TopLevelClientGetResponse, error) { + result := TopLevelClientGetResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.TopLevelTrackedResource); err != nil { - return TopLevelTrackedResourcesClientGetResponse{}, err + return TopLevelClientGetResponse{}, err } return result, nil } @@ -325,15 +322,15 @@ func (client *TopLevelTrackedResourcesClient) getHandleResponse(resp *http.Respo // // Generated from API version 2023-12-01-preview // - resourceGroupName - The name of the resource group. The name is case insensitive. -// - options - TopLevelTrackedResourcesClientListByResourceGroupOptions contains the optional parameters for the TopLevelTrackedResourcesClient.NewListByResourceGroupPager +// - options - TopLevelClientListByResourceGroupOptions contains the optional parameters for the TopLevelClient.NewListByResourceGroupPager // method. -func (client *TopLevelTrackedResourcesClient) NewListByResourceGroupPager(resourceGroupName string, options *TopLevelTrackedResourcesClientListByResourceGroupOptions) *runtime.Pager[TopLevelTrackedResourcesClientListByResourceGroupResponse] { - return runtime.NewPager(runtime.PagingHandler[TopLevelTrackedResourcesClientListByResourceGroupResponse]{ - More: func(page TopLevelTrackedResourcesClientListByResourceGroupResponse) bool { +func (client *TopLevelClient) NewListByResourceGroupPager(resourceGroupName string, options *TopLevelClientListByResourceGroupOptions) *runtime.Pager[TopLevelClientListByResourceGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[TopLevelClientListByResourceGroupResponse]{ + More: func(page TopLevelClientListByResourceGroupResponse) bool { return page.NextLink != nil && len(*page.NextLink) > 0 }, - Fetcher: func(ctx context.Context, page *TopLevelTrackedResourcesClientListByResourceGroupResponse) (TopLevelTrackedResourcesClientListByResourceGroupResponse, error) { - ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TopLevelTrackedResourcesClient.NewListByResourceGroupPager") + Fetcher: func(ctx context.Context, page *TopLevelClientListByResourceGroupResponse) (TopLevelClientListByResourceGroupResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TopLevelClient.NewListByResourceGroupPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -342,7 +339,7 @@ func (client *TopLevelTrackedResourcesClient) NewListByResourceGroupPager(resour return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) }, nil) if err != nil { - return TopLevelTrackedResourcesClientListByResourceGroupResponse{}, err + return TopLevelClientListByResourceGroupResponse{}, err } return client.listByResourceGroupHandleResponse(resp) }, @@ -351,8 +348,8 @@ func (client *TopLevelTrackedResourcesClient) NewListByResourceGroupPager(resour } // listByResourceGroupCreateRequest creates the ListByResourceGroup request. -func (client *TopLevelTrackedResourcesClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *TopLevelTrackedResourcesClientListByResourceGroupOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources" +func (client *TopLevelClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *TopLevelClientListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -373,10 +370,10 @@ func (client *TopLevelTrackedResourcesClient) listByResourceGroupCreateRequest(c } // listByResourceGroupHandleResponse handles the ListByResourceGroup response. -func (client *TopLevelTrackedResourcesClient) listByResourceGroupHandleResponse(resp *http.Response) (TopLevelTrackedResourcesClientListByResourceGroupResponse, error) { - result := TopLevelTrackedResourcesClientListByResourceGroupResponse{} +func (client *TopLevelClient) listByResourceGroupHandleResponse(resp *http.Response) (TopLevelClientListByResourceGroupResponse, error) { + result := TopLevelClientListByResourceGroupResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.TopLevelTrackedResourceListResult); err != nil { - return TopLevelTrackedResourcesClientListByResourceGroupResponse{}, err + return TopLevelClientListByResourceGroupResponse{}, err } return result, nil } @@ -384,15 +381,15 @@ func (client *TopLevelTrackedResourcesClient) listByResourceGroupHandleResponse( // NewListBySubscriptionPager - List TopLevelTrackedResource resources by subscription ID // // Generated from API version 2023-12-01-preview -// - options - TopLevelTrackedResourcesClientListBySubscriptionOptions contains the optional parameters for the TopLevelTrackedResourcesClient.NewListBySubscriptionPager +// - options - TopLevelClientListBySubscriptionOptions contains the optional parameters for the TopLevelClient.NewListBySubscriptionPager // method. -func (client *TopLevelTrackedResourcesClient) NewListBySubscriptionPager(options *TopLevelTrackedResourcesClientListBySubscriptionOptions) *runtime.Pager[TopLevelTrackedResourcesClientListBySubscriptionResponse] { - return runtime.NewPager(runtime.PagingHandler[TopLevelTrackedResourcesClientListBySubscriptionResponse]{ - More: func(page TopLevelTrackedResourcesClientListBySubscriptionResponse) bool { +func (client *TopLevelClient) NewListBySubscriptionPager(options *TopLevelClientListBySubscriptionOptions) *runtime.Pager[TopLevelClientListBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[TopLevelClientListBySubscriptionResponse]{ + More: func(page TopLevelClientListBySubscriptionResponse) bool { return page.NextLink != nil && len(*page.NextLink) > 0 }, - Fetcher: func(ctx context.Context, page *TopLevelTrackedResourcesClientListBySubscriptionResponse) (TopLevelTrackedResourcesClientListBySubscriptionResponse, error) { - ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TopLevelTrackedResourcesClient.NewListBySubscriptionPager") + Fetcher: func(ctx context.Context, page *TopLevelClientListBySubscriptionResponse) (TopLevelClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "TopLevelClient.NewListBySubscriptionPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -401,7 +398,7 @@ func (client *TopLevelTrackedResourcesClient) NewListBySubscriptionPager(options return client.listBySubscriptionCreateRequest(ctx, options) }, nil) if err != nil { - return TopLevelTrackedResourcesClientListBySubscriptionResponse{}, err + return TopLevelClientListBySubscriptionResponse{}, err } return client.listBySubscriptionHandleResponse(resp) }, @@ -410,8 +407,8 @@ func (client *TopLevelTrackedResourcesClient) NewListBySubscriptionPager(options } // listBySubscriptionCreateRequest creates the ListBySubscription request. -func (client *TopLevelTrackedResourcesClient) listBySubscriptionCreateRequest(ctx context.Context, _ *TopLevelTrackedResourcesClientListBySubscriptionOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources" +func (client *TopLevelClient) listBySubscriptionCreateRequest(ctx context.Context, _ *TopLevelClientListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } @@ -428,10 +425,10 @@ func (client *TopLevelTrackedResourcesClient) listBySubscriptionCreateRequest(ct } // listBySubscriptionHandleResponse handles the ListBySubscription response. -func (client *TopLevelTrackedResourcesClient) listBySubscriptionHandleResponse(resp *http.Response) (TopLevelTrackedResourcesClientListBySubscriptionResponse, error) { - result := TopLevelTrackedResourcesClientListBySubscriptionResponse{} +func (client *TopLevelClient) listBySubscriptionHandleResponse(resp *http.Response) (TopLevelClientListBySubscriptionResponse, error) { + result := TopLevelClientListBySubscriptionResponse{} if err := runtime.UnmarshalAsJSON(resp, &result.TopLevelTrackedResourceListResult); err != nil { - return TopLevelTrackedResourcesClientListBySubscriptionResponse{}, err + return TopLevelClientListBySubscriptionResponse{}, err } return result, nil } @@ -443,20 +440,19 @@ func (client *TopLevelTrackedResourcesClient) listBySubscriptionHandleResponse(r // - resourceGroupName - The name of the resource group. The name is case insensitive. // - topLevelTrackedResourceName - arm resource name for path // - properties - The resource properties to be updated. -// - options - TopLevelTrackedResourcesClientBeginUpdateOptions contains the optional parameters for the TopLevelTrackedResourcesClient.BeginUpdate -// method. -func (client *TopLevelTrackedResourcesClient) BeginUpdate(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties TopLevelTrackedResource, options *TopLevelTrackedResourcesClientBeginUpdateOptions) (*runtime.Poller[TopLevelTrackedResourcesClientUpdateResponse], error) { +// - options - TopLevelClientBeginUpdateOptions contains the optional parameters for the TopLevelClient.BeginUpdate method. +func (client *TopLevelClient) BeginUpdate(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties TopLevelTrackedResource, options *TopLevelClientBeginUpdateOptions) (*runtime.Poller[TopLevelClientUpdateResponse], error) { if options == nil || options.ResumeToken == "" { resp, err := client.update(ctx, resourceGroupName, topLevelTrackedResourceName, properties, options) if err != nil { return nil, err } - poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TopLevelTrackedResourcesClientUpdateResponse]{ + poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TopLevelClientUpdateResponse]{ Tracer: client.internal.Tracer(), }) return poller, err } else { - return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TopLevelTrackedResourcesClientUpdateResponse]{ + return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TopLevelClientUpdateResponse]{ Tracer: client.internal.Tracer(), }) } @@ -466,9 +462,9 @@ func (client *TopLevelTrackedResourcesClient) BeginUpdate(ctx context.Context, r // If the operation fails it returns an *azcore.ResponseError type. // // Generated from API version 2023-12-01-preview -func (client *TopLevelTrackedResourcesClient) update(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties TopLevelTrackedResource, options *TopLevelTrackedResourcesClientBeginUpdateOptions) (*http.Response, error) { +func (client *TopLevelClient) update(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties TopLevelTrackedResource, options *TopLevelClientBeginUpdateOptions) (*http.Response, error) { var err error - const operationName = "TopLevelTrackedResourcesClient.BeginUpdate" + const operationName = "TopLevelClient.BeginUpdate" ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() @@ -488,8 +484,8 @@ func (client *TopLevelTrackedResourcesClient) update(ctx context.Context, resour } // updateCreateRequest creates the Update request. -func (client *TopLevelTrackedResourcesClient) updateCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties TopLevelTrackedResource, _ *TopLevelTrackedResourcesClientBeginUpdateOptions) (*policy.Request, error) { - urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" +func (client *TopLevelClient) updateCreateRequest(ctx context.Context, resourceGroupName string, topLevelTrackedResourceName string, properties TopLevelTrackedResource, _ *TopLevelClientBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/{topLevelTrackedResourceName}" if client.subscriptionID == "" { return nil, errors.New("parameter client.subscriptionID cannot be empty") } diff --git a/packages/typespec-go/test/cadlranch/type/model/inheritance/nodiscgroup/notdiscriminated_client_test.go b/packages/typespec-go/test/cadlranch/type/model/inheritance/nodiscgroup/notdiscriminated_client_test.go index 085170c9f..591dde350 100644 --- a/packages/typespec-go/test/cadlranch/type/model/inheritance/nodiscgroup/notdiscriminated_client_test.go +++ b/packages/typespec-go/test/cadlranch/type/model/inheritance/nodiscgroup/notdiscriminated_client_test.go @@ -43,9 +43,9 @@ func TestNotDiscriminatedClientPutValid(t *testing.T) { client, err := nodiscgroup.NewNotDiscriminatedClient(nil) require.NoError(t, err) myCat := nodiscgroup.Siamese{ - Age: to.Ptr[int32](9), - Name: to.Ptr("Luna"), - Smart: to.Ptr(false), + Age: to.Ptr[int32](32), + Name: to.Ptr("abc"), + Smart: to.Ptr(true), } resp, err := client.PutValid(context.Background(), myCat, nil) require.NoError(t, err)