Skip to content

Commit 0ad2be3

Browse files
authored
sdk/resourcemanager/mediaservices live test (Azure#20910)
1 parent d38ba4b commit 0ad2be3

File tree

7 files changed

+1557
-1
lines changed

7 files changed

+1557
-1
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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 armmediaservices_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/testutil"
19+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mediaservices/armmediaservices/v3"
20+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
21+
"github.com/stretchr/testify/suite"
22+
)
23+
24+
type AccountsTestSuite struct {
25+
suite.Suite
26+
27+
ctx context.Context
28+
cred azcore.TokenCredential
29+
options *arm.ClientOptions
30+
accountName string
31+
storageAccountId string
32+
storageAccountName string
33+
location string
34+
resourceGroupName string
35+
subscriptionId string
36+
}
37+
38+
func (testsuite *AccountsTestSuite) SetupSuite() {
39+
testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/mediaservices/armmediaservices/testdata")
40+
41+
testsuite.ctx = context.Background()
42+
testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
43+
testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true)
44+
testsuite.storageAccountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "storageaccount", 20, true)
45+
testsuite.location = testutil.GetEnv("LOCATION", "westus")
46+
testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup")
47+
testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
48+
resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location)
49+
testsuite.Require().NoError(err)
50+
testsuite.resourceGroupName = *resourceGroup.Name
51+
testsuite.Prepare()
52+
}
53+
54+
func (testsuite *AccountsTestSuite) TearDownSuite() {
55+
_, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName)
56+
testsuite.Require().NoError(err)
57+
testutil.StopRecording(testsuite.T())
58+
}
59+
60+
func TestAccountsTestSuite(t *testing.T) {
61+
suite.Run(t, new(AccountsTestSuite))
62+
}
63+
64+
func (testsuite *AccountsTestSuite) Prepare() {
65+
var err error
66+
// From step Create_StorageAccount
67+
template := map[string]any{
68+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
69+
"contentVersion": "1.0.0.0",
70+
"outputs": map[string]any{
71+
"storageAccountId": map[string]any{
72+
"type": "string",
73+
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
74+
},
75+
},
76+
"parameters": map[string]any{
77+
"location": map[string]any{
78+
"type": "string",
79+
"defaultValue": testsuite.location,
80+
},
81+
"storageAccountName": map[string]any{
82+
"type": "string",
83+
"defaultValue": testsuite.storageAccountName,
84+
},
85+
},
86+
"resources": []any{
87+
map[string]any{
88+
"name": "[parameters('storageAccountName')]",
89+
"type": "Microsoft.Storage/storageAccounts",
90+
"apiVersion": "2022-05-01",
91+
"kind": "StorageV2",
92+
"location": "[parameters('location')]",
93+
"properties": map[string]any{
94+
"accessTier": "Hot",
95+
"allowBlobPublicAccess": true,
96+
"allowCrossTenantReplication": true,
97+
"allowSharedKeyAccess": true,
98+
"defaultToOAuthAuthentication": false,
99+
"dnsEndpointType": "Standard",
100+
"encryption": map[string]any{
101+
"keySource": "Microsoft.Storage",
102+
"requireInfrastructureEncryption": false,
103+
"services": map[string]any{
104+
"blob": map[string]any{
105+
"enabled": true,
106+
"keyType": "Account",
107+
},
108+
"file": map[string]any{
109+
"enabled": true,
110+
"keyType": "Account",
111+
},
112+
},
113+
},
114+
"minimumTlsVersion": "TLS1_2",
115+
"networkAcls": map[string]any{
116+
"bypass": "AzureServices",
117+
"defaultAction": "Allow",
118+
"ipRules": []any{},
119+
"virtualNetworkRules": []any{},
120+
},
121+
"publicNetworkAccess": "Enabled",
122+
"supportsHttpsTrafficOnly": true,
123+
},
124+
"sku": map[string]any{
125+
"name": "Standard_LRS",
126+
"tier": "Standard",
127+
},
128+
},
129+
},
130+
"variables": map[string]any{},
131+
}
132+
deployment := armresources.Deployment{
133+
Properties: &armresources.DeploymentProperties{
134+
Template: template,
135+
Mode: to.Ptr(armresources.DeploymentModeIncremental),
136+
},
137+
}
138+
deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_StorageAccount", &deployment)
139+
testsuite.Require().NoError(err)
140+
testsuite.storageAccountId = deploymentExtend.Properties.Outputs.(map[string]interface{})["storageAccountId"].(map[string]interface{})["value"].(string)
141+
}
142+
143+
func (testsuite *AccountsTestSuite) TestAccountTests() {
144+
var err error
145+
// From step Locations_CheckNameAvailability
146+
fmt.Println("Call operation: Locations_CheckNameAvailability")
147+
locationsClient, err := armmediaservices.NewLocationsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
148+
testsuite.Require().NoError(err)
149+
_, err = locationsClient.CheckNameAvailability(testsuite.ctx, "japanwest", armmediaservices.CheckNameAvailabilityInput{
150+
Name: to.Ptr(testsuite.accountName),
151+
Type: to.Ptr("Microsoft.Media/mediaservices"),
152+
}, nil)
153+
testsuite.Require().NoError(err)
154+
155+
// From step Mediaservices_CreateOrUpdate
156+
fmt.Println("Call operation: Mediaservices_CreateOrUpdate")
157+
client, err := armmediaservices.NewClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
158+
testsuite.Require().NoError(err)
159+
clientCreateOrUpdateResponsePoller, err := client.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armmediaservices.MediaService{
160+
Location: to.Ptr(testsuite.location),
161+
Tags: map[string]*string{
162+
"key1": to.Ptr("value1"),
163+
"key2": to.Ptr("value2"),
164+
},
165+
Properties: &armmediaservices.MediaServiceProperties{
166+
StorageAccounts: []*armmediaservices.StorageAccount{
167+
{
168+
Type: to.Ptr(armmediaservices.StorageAccountTypePrimary),
169+
ID: to.Ptr(testsuite.storageAccountId),
170+
}},
171+
},
172+
}, nil)
173+
testsuite.Require().NoError(err)
174+
_, err = testutil.PollForTest(testsuite.ctx, clientCreateOrUpdateResponsePoller)
175+
testsuite.Require().NoError(err)
176+
177+
// From step Mediaservices_ListBySubscription
178+
fmt.Println("Call operation: Mediaservices_ListBySubscription")
179+
clientNewListBySubscriptionPager := client.NewListBySubscriptionPager(nil)
180+
for clientNewListBySubscriptionPager.More() {
181+
_, err := clientNewListBySubscriptionPager.NextPage(testsuite.ctx)
182+
testsuite.Require().NoError(err)
183+
break
184+
}
185+
186+
// From step Mediaservices_Get
187+
fmt.Println("Call operation: Mediaservices_Get")
188+
_, err = client.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil)
189+
testsuite.Require().NoError(err)
190+
191+
// From step Mediaservices_List
192+
fmt.Println("Call operation: Mediaservices_List")
193+
clientNewListPager := client.NewListPager(testsuite.resourceGroupName, nil)
194+
for clientNewListPager.More() {
195+
_, err := clientNewListPager.NextPage(testsuite.ctx)
196+
testsuite.Require().NoError(err)
197+
break
198+
}
199+
200+
// From step Mediaservices_Update
201+
fmt.Println("Call operation: Mediaservices_Update")
202+
clientUpdateResponsePoller, err := client.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armmediaservices.MediaServiceUpdate{
203+
Tags: map[string]*string{
204+
"key1": to.Ptr("value3"),
205+
},
206+
}, nil)
207+
testsuite.Require().NoError(err)
208+
_, err = testutil.PollForTest(testsuite.ctx, clientUpdateResponsePoller)
209+
testsuite.Require().NoError(err)
210+
211+
// From step Mediaservices_SyncStorageKeys
212+
fmt.Println("Call operation: Mediaservices_SyncStorageKeys")
213+
_, err = client.SyncStorageKeys(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armmediaservices.SyncStorageKeysInput{
214+
ID: to.Ptr(testsuite.storageAccountId),
215+
}, nil)
216+
testsuite.Require().NoError(err)
217+
218+
// From step Operations_List
219+
fmt.Println("Call operation: Operations_List")
220+
operationsClient, err := armmediaservices.NewOperationsClient(testsuite.cred, testsuite.options)
221+
testsuite.Require().NoError(err)
222+
_, err = operationsClient.List(testsuite.ctx, nil)
223+
testsuite.Require().NoError(err)
224+
225+
// From step Mediaservices_Delete
226+
fmt.Println("Call operation: Mediaservices_Delete")
227+
_, err = client.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil)
228+
testsuite.Require().NoError(err)
229+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"AssetsRepo": "Azure/azure-sdk-assets",
3+
"AssetsRepoPrefixPath": "go",
4+
"TagPrefix": "go/resourcemanager/mediaservices/armmediaservices",
5+
"Tag": "go/resourcemanager/mediaservices/armmediaservices_816a2c4d41"
6+
}

0 commit comments

Comments
 (0)