Skip to content

Commit b14a600

Browse files
authored
sdk/resourcemanager/chaos/armchaos live test (Azure#22070)
* sdk/resourcemanager/chaos/armchaos live test * fix
1 parent 0cf3f2c commit b14a600

File tree

9 files changed

+805
-1
lines changed

9 files changed

+805
-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/chaos/armchaos",
5+
"Tag": "go/resourcemanager/chaos/armchaos_67d3127f01"
6+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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 armchaos_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/chaos/armchaos"
19+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil"
20+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
21+
"github.com/stretchr/testify/suite"
22+
)
23+
24+
type CapabilitiesTestSuite struct {
25+
suite.Suite
26+
27+
ctx context.Context
28+
cred azcore.TokenCredential
29+
options *arm.ClientOptions
30+
armEndpoint string
31+
capabilityName string
32+
cosmosAccountId string
33+
cosmosaccountName string
34+
targetName string
35+
location string
36+
resourceGroupName string
37+
subscriptionId string
38+
}
39+
40+
func (testsuite *CapabilitiesTestSuite) SetupSuite() {
41+
testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/chaos/armchaos/testdata")
42+
43+
testsuite.ctx = context.Background()
44+
testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
45+
testsuite.armEndpoint = "https://management.azure.com"
46+
testsuite.capabilityName = "Failover-1.0"
47+
testsuite.cosmosaccountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "account", 13, true)
48+
testsuite.targetName = "Microsoft-CosmosDB"
49+
testsuite.location = recording.GetEnvVariable("LOCATION", "eastus")
50+
testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup")
51+
testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
52+
resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location)
53+
testsuite.Require().NoError(err)
54+
testsuite.resourceGroupName = *resourceGroup.Name
55+
testsuite.Prepare()
56+
}
57+
58+
func (testsuite *CapabilitiesTestSuite) TearDownSuite() {
59+
_, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName)
60+
testsuite.Require().NoError(err)
61+
testutil.StopRecording(testsuite.T())
62+
}
63+
64+
func TestCapabilitiesTestSuite(t *testing.T) {
65+
suite.Run(t, new(CapabilitiesTestSuite))
66+
}
67+
68+
func (testsuite *CapabilitiesTestSuite) Prepare() {
69+
var err error
70+
// From step Create_CosmosAccount
71+
template := map[string]any{
72+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
73+
"contentVersion": "1.0.0.0",
74+
"outputs": map[string]any{
75+
"cosmosAccountId": map[string]any{
76+
"type": "string",
77+
"value": "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('cosmosaccountName'))]",
78+
},
79+
},
80+
"parameters": map[string]any{
81+
"cosmosaccountName": map[string]any{
82+
"type": "string",
83+
"defaultValue": testsuite.cosmosaccountName,
84+
},
85+
"location": map[string]any{
86+
"type": "string",
87+
"defaultValue": testsuite.location,
88+
},
89+
},
90+
"resources": []any{
91+
map[string]any{
92+
"name": "[parameters('cosmosaccountName')]",
93+
"type": "Microsoft.DocumentDB/databaseAccounts",
94+
"apiVersion": "2023-09-15",
95+
"location": "[parameters('location')]",
96+
"properties": map[string]any{
97+
"databaseAccountOfferType": "Standard",
98+
"locations": []any{
99+
map[string]any{
100+
"failoverPriority": "0",
101+
"is_zone_redundant": false,
102+
"locationName": "westus",
103+
},
104+
map[string]any{
105+
"failoverPriority": "1",
106+
"locationName": "eastus",
107+
},
108+
},
109+
},
110+
},
111+
},
112+
"variables": map[string]any{},
113+
}
114+
deployment := armresources.Deployment{
115+
Properties: &armresources.DeploymentProperties{
116+
Template: template,
117+
Mode: to.Ptr(armresources.DeploymentModeIncremental),
118+
},
119+
}
120+
deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_CosmosAccount", &deployment)
121+
testsuite.Require().NoError(err)
122+
testsuite.cosmosAccountId = deploymentExtend.Properties.Outputs.(map[string]interface{})["cosmosAccountId"].(map[string]interface{})["value"].(string)
123+
}
124+
125+
// Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName}
126+
func (testsuite *CapabilitiesTestSuite) TestCapabilities() {
127+
parentProviderNamespace := "Microsoft.DocumentDB"
128+
parentResourceName := testsuite.cosmosaccountName
129+
parentResourceType := "databaseAccounts"
130+
var err error
131+
// From step Targets_CreateOrUpdate
132+
fmt.Println("Call operation: Targets_CreateOrUpdate")
133+
targetsClient, err := armchaos.NewTargetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
134+
testsuite.Require().NoError(err)
135+
_, err = targetsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, testsuite.targetName, armchaos.Target{
136+
Properties: map[string]any{
137+
"identities": []any{
138+
map[string]any{
139+
"type": "CertificateSubjectIssuer",
140+
"subject": "CN=example.subject",
141+
},
142+
},
143+
},
144+
}, nil)
145+
testsuite.Require().NoError(err)
146+
147+
// From step Capabilities_CreateOrUpdate
148+
fmt.Println("Call operation: Capabilities_CreateOrUpdate")
149+
capabilitiesClient, err := armchaos.NewCapabilitiesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
150+
testsuite.Require().NoError(err)
151+
_, err = capabilitiesClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, testsuite.targetName, testsuite.capabilityName, armchaos.Capability{
152+
Properties: &armchaos.CapabilityProperties{},
153+
}, nil)
154+
testsuite.Require().NoError(err)
155+
156+
// From step Capabilities_Get
157+
fmt.Println("Call operation: Capabilities_Get")
158+
_, err = capabilitiesClient.Get(testsuite.ctx, testsuite.resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, testsuite.targetName, testsuite.capabilityName, nil)
159+
testsuite.Require().NoError(err)
160+
161+
// From step Capabilities_List
162+
fmt.Println("Call operation: Capabilities_List")
163+
capabilitiesClientNewListPager := capabilitiesClient.NewListPager(testsuite.resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, testsuite.targetName, &armchaos.CapabilitiesClientListOptions{ContinuationToken: nil})
164+
for capabilitiesClientNewListPager.More() {
165+
_, err := capabilitiesClientNewListPager.NextPage(testsuite.ctx)
166+
testsuite.Require().NoError(err)
167+
break
168+
}
169+
170+
// From step Capabilities_Delete
171+
fmt.Println("Call operation: Capabilities_Delete")
172+
_, err = capabilitiesClient.Delete(testsuite.ctx, testsuite.resourceGroupName, parentProviderNamespace, parentResourceType, parentResourceName, testsuite.targetName, testsuite.capabilityName, nil)
173+
testsuite.Require().NoError(err)
174+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 armchaos_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/internal/recording"
17+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/chaos/armchaos"
18+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil"
19+
"github.com/stretchr/testify/suite"
20+
)
21+
22+
type CapabilityTypesTestSuite struct {
23+
suite.Suite
24+
25+
ctx context.Context
26+
cred azcore.TokenCredential
27+
options *arm.ClientOptions
28+
armEndpoint string
29+
location string
30+
resourceGroupName string
31+
subscriptionId string
32+
}
33+
34+
func (testsuite *CapabilityTypesTestSuite) SetupSuite() {
35+
testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/chaos/armchaos/testdata")
36+
37+
testsuite.ctx = context.Background()
38+
testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
39+
testsuite.armEndpoint = "https://management.azure.com"
40+
testsuite.location = recording.GetEnvVariable("LOCATION", "eastus")
41+
testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup")
42+
testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
43+
resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location)
44+
testsuite.Require().NoError(err)
45+
testsuite.resourceGroupName = *resourceGroup.Name
46+
}
47+
48+
func (testsuite *CapabilityTypesTestSuite) TearDownSuite() {
49+
_, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName)
50+
testsuite.Require().NoError(err)
51+
testutil.StopRecording(testsuite.T())
52+
}
53+
54+
func TestCapabilityTypesTestSuite(t *testing.T) {
55+
suite.Run(t, new(CapabilityTypesTestSuite))
56+
}
57+
58+
// Microsoft.Chaos/locations/{locationName}/targetTypes/{targetTypeName}/capabilityTypes/{capabilityTypeName}
59+
func (testsuite *CapabilityTypesTestSuite) TestCapabilityTypes() {
60+
var err error
61+
// From step CapabilityTypes_List
62+
fmt.Println("Call operation: CapabilityTypes_List")
63+
capabilityTypesClient, err := armchaos.NewCapabilityTypesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
64+
testsuite.Require().NoError(err)
65+
capabilityTypesClientNewListPager := capabilityTypesClient.NewListPager("westus2", "Microsoft-VirtualMachine", &armchaos.CapabilityTypesClientListOptions{ContinuationToken: nil})
66+
for capabilityTypesClientNewListPager.More() {
67+
_, err := capabilityTypesClientNewListPager.NextPage(testsuite.ctx)
68+
testsuite.Require().NoError(err)
69+
break
70+
}
71+
72+
// From step CapabilityTypes_Get
73+
fmt.Println("Call operation: CapabilityTypes_Get")
74+
_, err = capabilityTypesClient.Get(testsuite.ctx, "westus2", "Microsoft-VirtualMachine", "Shutdown-1.0", nil)
75+
testsuite.Require().NoError(err)
76+
}

0 commit comments

Comments
 (0)