|
| 1 | +//go:build go1.18 |
| 2 | +// +build go1.18 |
| 3 | + |
| 4 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 5 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 6 | + |
| 7 | +package armiotcentral_test |
| 8 | + |
| 9 | +import ( |
| 10 | + "context" |
| 11 | + "fmt" |
| 12 | + "testing" |
| 13 | + |
| 14 | + "github.com/Azure/azure-sdk-for-go/sdk/azcore" |
| 15 | + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" |
| 16 | + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" |
| 17 | + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" |
| 18 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" |
| 19 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/iotcentral/armiotcentral" |
| 20 | + "github.com/stretchr/testify/suite" |
| 21 | +) |
| 22 | + |
| 23 | +type IotcentralTestSuite struct { |
| 24 | + suite.Suite |
| 25 | + |
| 26 | + ctx context.Context |
| 27 | + cred azcore.TokenCredential |
| 28 | + options *arm.ClientOptions |
| 29 | + armEndpoint string |
| 30 | + resourceName string |
| 31 | + location string |
| 32 | + resourceGroupName string |
| 33 | + subscriptionId string |
| 34 | +} |
| 35 | + |
| 36 | +func (testsuite *IotcentralTestSuite) SetupSuite() { |
| 37 | + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/iotcentral/armiotcentral/testdata") |
| 38 | + |
| 39 | + testsuite.ctx = context.Background() |
| 40 | + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) |
| 41 | + testsuite.armEndpoint = "https://management.azure.com" |
| 42 | + testsuite.resourceName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "resource", 14, true) |
| 43 | + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") |
| 44 | + testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") |
| 45 | + testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") |
| 46 | + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) |
| 47 | + testsuite.Require().NoError(err) |
| 48 | + testsuite.resourceGroupName = *resourceGroup.Name |
| 49 | +} |
| 50 | + |
| 51 | +func (testsuite *IotcentralTestSuite) TearDownSuite() { |
| 52 | + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) |
| 53 | + testsuite.Require().NoError(err) |
| 54 | + testutil.StopRecording(testsuite.T()) |
| 55 | +} |
| 56 | + |
| 57 | +func TestIotcentralTestSuite(t *testing.T) { |
| 58 | + suite.Run(t, new(IotcentralTestSuite)) |
| 59 | +} |
| 60 | + |
| 61 | +// Microsoft.IoTCentral/iotApps/{resourceName} |
| 62 | +func (testsuite *IotcentralTestSuite) TestApps() { |
| 63 | + var err error |
| 64 | + // From step Apps_CheckNameAvailability |
| 65 | + fmt.Println("Call operation: Apps_CheckNameAvailability") |
| 66 | + appsClient, err := armiotcentral.NewAppsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) |
| 67 | + testsuite.Require().NoError(err) |
| 68 | + _, err = appsClient.CheckNameAvailability(testsuite.ctx, armiotcentral.OperationInputs{ |
| 69 | + Name: to.Ptr("myiotcentralapp"), |
| 70 | + Type: to.Ptr("IoTApps"), |
| 71 | + }, nil) |
| 72 | + testsuite.Require().NoError(err) |
| 73 | + |
| 74 | + // From step Apps_CreateOrUpdate |
| 75 | + fmt.Println("Call operation: Apps_CreateOrUpdate") |
| 76 | + appsClientCreateOrUpdateResponsePoller, err := appsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, armiotcentral.App{ |
| 77 | + Location: to.Ptr(testsuite.location), |
| 78 | + Identity: &armiotcentral.SystemAssignedServiceIdentity{ |
| 79 | + Type: to.Ptr(armiotcentral.SystemAssignedServiceIdentityTypeSystemAssigned), |
| 80 | + }, |
| 81 | + Properties: &armiotcentral.AppProperties{ |
| 82 | + DisplayName: to.Ptr("My IoT Central App"), |
| 83 | + Subdomain: to.Ptr("my-iotcentral-app"), |
| 84 | + Template: to. Ptr( "[email protected]"), |
| 85 | + }, |
| 86 | + SKU: &armiotcentral.AppSKUInfo{ |
| 87 | + Name: to.Ptr(armiotcentral.AppSKUST2), |
| 88 | + }, |
| 89 | + }, nil) |
| 90 | + testsuite.Require().NoError(err) |
| 91 | + _, err = testutil.PollForTest(testsuite.ctx, appsClientCreateOrUpdateResponsePoller) |
| 92 | + testsuite.Require().NoError(err) |
| 93 | + |
| 94 | + // From step Apps_ListBySubscription |
| 95 | + fmt.Println("Call operation: Apps_ListBySubscription") |
| 96 | + appsClientNewListBySubscriptionPager := appsClient.NewListBySubscriptionPager(nil) |
| 97 | + for appsClientNewListBySubscriptionPager.More() { |
| 98 | + _, err := appsClientNewListBySubscriptionPager.NextPage(testsuite.ctx) |
| 99 | + testsuite.Require().NoError(err) |
| 100 | + break |
| 101 | + } |
| 102 | + |
| 103 | + // From step Apps_ListByResourceGroup |
| 104 | + fmt.Println("Call operation: Apps_ListByResourceGroup") |
| 105 | + appsClientNewListByResourceGroupPager := appsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) |
| 106 | + for appsClientNewListByResourceGroupPager.More() { |
| 107 | + _, err := appsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) |
| 108 | + testsuite.Require().NoError(err) |
| 109 | + break |
| 110 | + } |
| 111 | + |
| 112 | + // From step Apps_Get |
| 113 | + fmt.Println("Call operation: Apps_Get") |
| 114 | + _, err = appsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, nil) |
| 115 | + testsuite.Require().NoError(err) |
| 116 | + |
| 117 | + // From step Apps_Update |
| 118 | + fmt.Println("Call operation: Apps_Update") |
| 119 | + appsClientUpdateResponsePoller, err := appsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, armiotcentral.AppPatch{ |
| 120 | + Identity: &armiotcentral.SystemAssignedServiceIdentity{ |
| 121 | + Type: to.Ptr(armiotcentral.SystemAssignedServiceIdentityTypeSystemAssigned), |
| 122 | + }, |
| 123 | + Properties: &armiotcentral.AppProperties{ |
| 124 | + DisplayName: to.Ptr("My IoT Central App 2"), |
| 125 | + }, |
| 126 | + }, nil) |
| 127 | + testsuite.Require().NoError(err) |
| 128 | + _, err = testutil.PollForTest(testsuite.ctx, appsClientUpdateResponsePoller) |
| 129 | + testsuite.Require().NoError(err) |
| 130 | + |
| 131 | + // From step Apps_CheckSubdomainAvailability |
| 132 | + fmt.Println("Call operation: Apps_CheckSubdomainAvailability") |
| 133 | + _, err = appsClient.CheckSubdomainAvailability(testsuite.ctx, armiotcentral.OperationInputs{ |
| 134 | + Name: to.Ptr("myiotcentralapp"), |
| 135 | + Type: to.Ptr("IoTApps"), |
| 136 | + }, nil) |
| 137 | + testsuite.Require().NoError(err) |
| 138 | + |
| 139 | + // From step Apps_ListTemplates |
| 140 | + fmt.Println("Call operation: Apps_ListTemplates") |
| 141 | + appsClientNewListTemplatesPager := appsClient.NewListTemplatesPager(nil) |
| 142 | + for appsClientNewListTemplatesPager.More() { |
| 143 | + _, err := appsClientNewListTemplatesPager.NextPage(testsuite.ctx) |
| 144 | + testsuite.Require().NoError(err) |
| 145 | + break |
| 146 | + } |
| 147 | + |
| 148 | + // From step Apps_Delete |
| 149 | + fmt.Println("Call operation: Apps_Delete") |
| 150 | + appsClientDeleteResponsePoller, err := appsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.resourceName, nil) |
| 151 | + testsuite.Require().NoError(err) |
| 152 | + _, err = testutil.PollForTest(testsuite.ctx, appsClientDeleteResponsePoller) |
| 153 | + testsuite.Require().NoError(err) |
| 154 | +} |
| 155 | + |
| 156 | +// Microsoft.IoTCentral/operations |
| 157 | +func (testsuite *IotcentralTestSuite) TestOperations() { |
| 158 | + var err error |
| 159 | + // From step Operations_List |
| 160 | + fmt.Println("Call operation: Operations_List") |
| 161 | + operationsClient, err := armiotcentral.NewOperationsClient(testsuite.cred, testsuite.options) |
| 162 | + testsuite.Require().NoError(err) |
| 163 | + operationsClientNewListPager := operationsClient.NewListPager(nil) |
| 164 | + for operationsClientNewListPager.More() { |
| 165 | + _, err := operationsClientNewListPager.NextPage(testsuite.ctx) |
| 166 | + testsuite.Require().NoError(err) |
| 167 | + break |
| 168 | + } |
| 169 | +} |
0 commit comments