Skip to content

Commit cf9e6fc

Browse files
authored
sdk/resourcemanager/streamanalytics/armstreamanalytics live test (Azure#20913)
1 parent ba2c3d8 commit cf9e6fc

File tree

10 files changed

+1332
-1
lines changed

10 files changed

+1332
-1
lines changed
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/streamanalytics/armstreamanalytics",
5+
"Tag": "go/resourcemanager/streamanalytics/armstreamanalytics_4124c9f67c"
6+
}
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
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 armstreamanalytics_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/resources/armresources"
20+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/streamanalytics/armstreamanalytics"
21+
"github.com/stretchr/testify/suite"
22+
)
23+
24+
type ClustersTestSuite struct {
25+
suite.Suite
26+
27+
ctx context.Context
28+
cred azcore.TokenCredential
29+
options *arm.ClientOptions
30+
clusterName string
31+
privateEndpointName string
32+
storageAccountId string
33+
storageAccountKey string
34+
storageAccountName string
35+
location string
36+
resourceGroupName string
37+
subscriptionId string
38+
}
39+
40+
func (testsuite *ClustersTestSuite) SetupSuite() {
41+
testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/streamanalytics/armstreamanalytics/testdata")
42+
43+
testsuite.ctx = context.Background()
44+
testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
45+
testsuite.clusterName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "clustern", 14, false)
46+
testsuite.privateEndpointName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "privatee", 14, false)
47+
testsuite.storageAccountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "streamsc", 14, true)
48+
testsuite.location = testutil.GetEnv("LOCATION", "westus")
49+
testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup")
50+
testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
51+
resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location)
52+
testsuite.Require().NoError(err)
53+
testsuite.resourceGroupName = *resourceGroup.Name
54+
testsuite.Prepare()
55+
}
56+
57+
func (testsuite *ClustersTestSuite) TearDownSuite() {
58+
_, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName)
59+
testsuite.Require().NoError(err)
60+
testutil.StopRecording(testsuite.T())
61+
}
62+
63+
func TestClustersTestSuite(t *testing.T) {
64+
suite.Run(t, new(ClustersTestSuite))
65+
}
66+
67+
func (testsuite *ClustersTestSuite) Prepare() {
68+
var err error
69+
// From step Clusters_CreateOrUpdate
70+
fmt.Println("Call operation: Clusters_CreateOrUpdate")
71+
clustersClient, err := armstreamanalytics.NewClustersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
72+
testsuite.Require().NoError(err)
73+
clustersClientCreateOrUpdateResponsePoller, err := clustersClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, armstreamanalytics.Cluster{
74+
Location: to.Ptr(testsuite.location),
75+
Tags: map[string]*string{
76+
"key": to.Ptr("value"),
77+
},
78+
SKU: &armstreamanalytics.ClusterSKU{
79+
Name: to.Ptr(armstreamanalytics.ClusterSKUNameDefault),
80+
Capacity: to.Ptr[int32](36),
81+
},
82+
}, &armstreamanalytics.ClustersClientBeginCreateOrUpdateOptions{IfMatch: nil,
83+
IfNoneMatch: nil,
84+
})
85+
testsuite.Require().NoError(err)
86+
_, err = testutil.PollForTest(testsuite.ctx, clustersClientCreateOrUpdateResponsePoller)
87+
testsuite.Require().NoError(err)
88+
89+
// From step Create_StorageAccount
90+
template := map[string]any{
91+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
92+
"contentVersion": "1.0.0.0",
93+
"outputs": map[string]any{
94+
"storageAccountId": map[string]any{
95+
"type": "string",
96+
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
97+
},
98+
"storageAccountKey": map[string]any{
99+
"type": "string",
100+
"value": "[listKeys(parameters('storageAccountName'),'2022-05-01').keys[0].value]",
101+
},
102+
},
103+
"parameters": map[string]any{
104+
"location": map[string]any{
105+
"type": "string",
106+
"defaultValue": testsuite.location,
107+
},
108+
"storageAccountName": map[string]any{
109+
"type": "string",
110+
"defaultValue": testsuite.storageAccountName,
111+
},
112+
},
113+
"resources": []any{
114+
map[string]any{
115+
"name": "[parameters('storageAccountName')]",
116+
"type": "Microsoft.Storage/storageAccounts",
117+
"apiVersion": "2022-05-01",
118+
"kind": "StorageV2",
119+
"location": "[parameters('location')]",
120+
"properties": map[string]any{
121+
"accessTier": "Hot",
122+
"allowBlobPublicAccess": true,
123+
"allowCrossTenantReplication": true,
124+
"allowSharedKeyAccess": true,
125+
"defaultToOAuthAuthentication": false,
126+
"dnsEndpointType": "Standard",
127+
"encryption": map[string]any{
128+
"keySource": "Microsoft.Storage",
129+
"requireInfrastructureEncryption": false,
130+
"services": map[string]any{
131+
"blob": map[string]any{
132+
"enabled": true,
133+
"keyType": "Account",
134+
},
135+
"file": map[string]any{
136+
"enabled": true,
137+
"keyType": "Account",
138+
},
139+
},
140+
},
141+
"minimumTlsVersion": "TLS1_2",
142+
"networkAcls": map[string]any{
143+
"bypass": "AzureServices",
144+
"defaultAction": "Allow",
145+
"ipRules": []any{},
146+
"virtualNetworkRules": []any{},
147+
},
148+
"publicNetworkAccess": "Enabled",
149+
"supportsHttpsTrafficOnly": true,
150+
},
151+
"sku": map[string]any{
152+
"name": "Standard_RAGRS",
153+
"tier": "Standard",
154+
},
155+
},
156+
},
157+
"variables": map[string]any{},
158+
}
159+
deployment := armresources.Deployment{
160+
Properties: &armresources.DeploymentProperties{
161+
Template: template,
162+
Mode: to.Ptr(armresources.DeploymentModeIncremental),
163+
},
164+
}
165+
deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_StorageAccount", &deployment)
166+
testsuite.Require().NoError(err)
167+
testsuite.storageAccountId = deploymentExtend.Properties.Outputs.(map[string]interface{})["storageAccountId"].(map[string]interface{})["value"].(string)
168+
testsuite.storageAccountKey = deploymentExtend.Properties.Outputs.(map[string]interface{})["storageAccountKey"].(map[string]interface{})["value"].(string)
169+
}
170+
171+
// Microsoft.StreamAnalytics/clusters/{clusterName}
172+
func (testsuite *ClustersTestSuite) TestClusters() {
173+
var err error
174+
// From step Clusters_ListBySubscription
175+
fmt.Println("Call operation: Clusters_ListBySubscription")
176+
clustersClient, err := armstreamanalytics.NewClustersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
177+
testsuite.Require().NoError(err)
178+
clustersClientNewListBySubscriptionPager := clustersClient.NewListBySubscriptionPager(nil)
179+
for clustersClientNewListBySubscriptionPager.More() {
180+
_, err := clustersClientNewListBySubscriptionPager.NextPage(testsuite.ctx)
181+
testsuite.Require().NoError(err)
182+
break
183+
}
184+
185+
// From step Clusters_ListByResourceGroup
186+
fmt.Println("Call operation: Clusters_ListByResourceGroup")
187+
clustersClientNewListByResourceGroupPager := clustersClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil)
188+
for clustersClientNewListByResourceGroupPager.More() {
189+
_, err := clustersClientNewListByResourceGroupPager.NextPage(testsuite.ctx)
190+
testsuite.Require().NoError(err)
191+
break
192+
}
193+
194+
// From step Clusters_Get
195+
fmt.Println("Call operation: Clusters_Get")
196+
_, err = clustersClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, nil)
197+
testsuite.Require().NoError(err)
198+
199+
// From step Clusters_Update
200+
fmt.Println("Call operation: Clusters_Update")
201+
clustersClientUpdateResponsePoller, err := clustersClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, armstreamanalytics.Cluster{}, &armstreamanalytics.ClustersClientBeginUpdateOptions{IfMatch: nil})
202+
testsuite.Require().NoError(err)
203+
_, err = testutil.PollForTest(testsuite.ctx, clustersClientUpdateResponsePoller)
204+
testsuite.Require().NoError(err)
205+
206+
// From step Clusters_ListStreamingJobs
207+
fmt.Println("Call operation: Clusters_ListStreamingJobs")
208+
clustersClientNewListStreamingJobsPager := clustersClient.NewListStreamingJobsPager(testsuite.resourceGroupName, testsuite.clusterName, nil)
209+
for clustersClientNewListStreamingJobsPager.More() {
210+
_, err := clustersClientNewListStreamingJobsPager.NextPage(testsuite.ctx)
211+
testsuite.Require().NoError(err)
212+
break
213+
}
214+
}
215+
216+
// Microsoft.StreamAnalytics/clusters/{clusterName}/privateEndpoints/{privateEndpointName}
217+
func (testsuite *ClustersTestSuite) TestPrivateEndpoint() {
218+
var err error
219+
// From step PrivateEndpoints_CreateOrUpdate
220+
fmt.Println("Call operation: PrivateEndpoints_CreateOrUpdate")
221+
privateEndpointsClient, err := armstreamanalytics.NewPrivateEndpointsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
222+
testsuite.Require().NoError(err)
223+
_, err = privateEndpointsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.privateEndpointName, armstreamanalytics.PrivateEndpoint{
224+
Properties: &armstreamanalytics.PrivateEndpointProperties{
225+
ManualPrivateLinkServiceConnections: []*armstreamanalytics.PrivateLinkServiceConnection{
226+
{
227+
Properties: &armstreamanalytics.PrivateLinkServiceConnectionProperties{
228+
GroupIDs: []*string{
229+
to.Ptr("blob")},
230+
PrivateLinkServiceID: to.Ptr(testsuite.storageAccountId),
231+
},
232+
}},
233+
},
234+
}, &armstreamanalytics.PrivateEndpointsClientCreateOrUpdateOptions{IfMatch: nil,
235+
IfNoneMatch: nil,
236+
})
237+
testsuite.Require().NoError(err)
238+
239+
// From step PrivateEndpoints_ListByCluster
240+
fmt.Println("Call operation: PrivateEndpoints_ListByCluster")
241+
privateEndpointsClientNewListByClusterPager := privateEndpointsClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil)
242+
for privateEndpointsClientNewListByClusterPager.More() {
243+
_, err := privateEndpointsClientNewListByClusterPager.NextPage(testsuite.ctx)
244+
testsuite.Require().NoError(err)
245+
break
246+
}
247+
248+
// From step PrivateEndpoints_Get
249+
fmt.Println("Call operation: PrivateEndpoints_Get")
250+
_, err = privateEndpointsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.privateEndpointName, nil)
251+
testsuite.Require().NoError(err)
252+
253+
// From step PrivateEndpoints_Delete
254+
fmt.Println("Call operation: PrivateEndpoints_Delete")
255+
privateEndpointsClientDeleteResponsePoller, err := privateEndpointsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.privateEndpointName, nil)
256+
testsuite.Require().NoError(err)
257+
_, err = testutil.PollForTest(testsuite.ctx, privateEndpointsClientDeleteResponsePoller)
258+
testsuite.Require().NoError(err)
259+
}

0 commit comments

Comments
 (0)