-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
5,112 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package commands_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/azure/armstrong/commands" | ||
) | ||
|
||
func TestTestCommand_AllPass(t *testing.T) { | ||
if os.Getenv("TF_ACC") == "" { | ||
t.Skip("TF_ACC is not set") | ||
} | ||
runTestCommand(t, map[string]string{ | ||
"all_passed_report.md": "Microsoft.Automation/automationAccounts@2023-11-01 (azapi_resource.automationAccount)", | ||
}) | ||
} | ||
|
||
func TestTestCommand_Diff(t *testing.T) { | ||
if os.Getenv("TF_ACC") == "" { | ||
t.Skip("TF_ACC is not set") | ||
} | ||
runTestCommand(t, map[string]string{ | ||
"partial_passed_report.md": "Microsoft.Resources/resourceGroups@2020-06-01 (azapi_resource.resourceGroup)", | ||
"Microsoft.Automation_automationAccounts@2023-11-01_automationAccount.md": ".properties.sku.name: expect Free, but got Basic", | ||
}) | ||
} | ||
|
||
func TestTestCommand_MissingProperties(t *testing.T) { | ||
if os.Getenv("TF_ACC") == "" { | ||
t.Skip("TF_ACC is not set") | ||
} | ||
runTestCommand(t, map[string]string{ | ||
"partial_passed_report.md": "Microsoft.Resources/resourceGroups@2020-06-01 (azapi_resource.resourceGroup)", | ||
"Microsoft.Automation_automationAccounts@2023-11-01_automationAccount.md": ".properties.sku.family = bar: not returned from response", | ||
}) | ||
} | ||
|
||
func TestTestCommand_BadRequest(t *testing.T) { | ||
if os.Getenv("TF_ACC") == "" { | ||
t.Skip("TF_ACC is not set") | ||
} | ||
runTestCommand(t, map[string]string{ | ||
"partial_passed_report.md": "Microsoft.Resources/resourceGroups@2020-06-01 (azapi_resource.resourceGroup)", | ||
"Microsoft.Automation_automationAccounts@2023-11-01_automationAccount.md": "RESPONSE 400: 400 Bad Request", | ||
}) | ||
} | ||
|
||
func runTestCommand(t *testing.T, fileContentMap map[string]string) { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("failed to get working directory: %+v", err) | ||
} | ||
|
||
tfDir := path.Join(wd, ".temp", t.Name()) | ||
if err := os.MkdirAll(tfDir, 0755); err != nil { | ||
t.Fatalf("failed to create working directory: %+v", err) | ||
} | ||
defer os.RemoveAll(tfDir) | ||
defer commands.CleanupCommand{}.Run([]string{"-working-dir", tfDir}) | ||
|
||
if err := copyFile(path.Join(wd, "testdata", t.Name(), "main.tf"), path.Join(tfDir, "main.tf")); err != nil { | ||
t.Fatalf("failed to copy file: %+v", err) | ||
} | ||
|
||
command := commands.TestCommand{} | ||
command.Run([]string{"-working-dir", tfDir}) | ||
|
||
reportDir := tfDir | ||
dirs, err := os.ReadDir(reportDir) | ||
if err != nil { | ||
t.Fatalf("failed to read directory %s: %+v", reportDir, err) | ||
} | ||
for _, dir := range dirs { | ||
if dir.IsDir() && strings.HasPrefix(dir.Name(), "armstrong_reports_") { | ||
reportDir = path.Join(reportDir, dir.Name()) | ||
break | ||
} | ||
} | ||
|
||
for file, content := range fileContentMap { | ||
filePath := path.Join(reportDir, file) | ||
if _, err := os.Stat(filePath); os.IsNotExist(err) { | ||
t.Fatalf("file %s not found", filePath) | ||
} | ||
if content != "" { | ||
data, err := os.ReadFile(filePath) | ||
if err != nil { | ||
t.Fatalf("failed to read file %s: %+v", filePath, err) | ||
} | ||
if !strings.Contains(string(data), content) { | ||
t.Fatalf("file %s does not contain expected content", filePath) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func copyFile(src, dst string) error { | ||
data, err := os.ReadFile(src) | ||
if err != nil { | ||
return err | ||
} | ||
return os.WriteFile(dst, data, 0644) | ||
} |
22 changes: 22 additions & 0 deletions
22
...ds/testdata/TestGenerateCommand_fromSwagger/examples/Accounts_AddRootCollectionAdmin.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"parameters": { | ||
"subscriptionId": "34adfa4f-cedf-4dc0-ba29-b6d1a69ab345", | ||
"resourceGroupName": "SampleResourceGroup", | ||
"accountName": "account1", | ||
"api-version": "2021-12-01", | ||
"collectionAdminUpdate": { | ||
"objectId": "7e8de0e7-2bfc-4e1f-9659-2a5785e4356f" | ||
} | ||
}, | ||
"responses": { | ||
"200": { | ||
"headers": { | ||
"Date": "Wed, 13 Sep 2017 18:04:32 GMT", | ||
"x-ms-request-id": "d5496da4-9c52-402f-b067-83cc9ddea888", | ||
"X-Content-Type-Options": "nosniff", | ||
"x-ms-ratelimit-remaining-tenant-reads": "14999", | ||
"x-ms-correlation-request-id": "25c78f97-0b0a-4fe9-ad39-883a482265cd" | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...nds/testdata/TestGenerateCommand_fromSwagger/examples/Accounts_CheckNameAvailability.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"parameters": { | ||
"checkNameAvailabilityRequest": { | ||
"name": "account1", | ||
"type": "Microsoft.Purview/accounts" | ||
}, | ||
"api-version": "2021-12-01", | ||
"subscriptionId": "34adfa4f-cedf-4dc0-ba29-b6d1a69ab345" | ||
}, | ||
"responses": { | ||
"200": { | ||
"headers": { | ||
"Date": "Wed, 13 Sep 2017 18:04:32 GMT", | ||
"x-ms-request-id": "d5496da4-9c52-402f-b067-83cc9ddea888", | ||
"X-Content-Type-Options": "nosniff", | ||
"x-ms-ratelimit-remaining-tenant-reads": "14999", | ||
"x-ms-correlation-request-id": "25c78f97-0b0a-4fe9-ad39-883a482265cd" | ||
}, | ||
"body": { | ||
"nameAvailable": true | ||
} | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
commands/testdata/TestGenerateCommand_fromSwagger/examples/Accounts_CreateOrUpdate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"parameters": { | ||
"subscriptionId": "34adfa4f-cedf-4dc0-ba29-b6d1a69ab345", | ||
"resourceGroupName": "SampleResourceGroup", | ||
"accountName": "account1", | ||
"api-version": "2021-12-01", | ||
"account": { | ||
"location": "West US 2", | ||
"properties": { | ||
"managedResourceGroupName": "custom-rgname", | ||
"managedResourcesPublicNetworkAccess": "Enabled" | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"201": { | ||
"headers": { | ||
"Date": "Wed, 13 Sep 2017 18:04:32 GMT", | ||
"x-ms-request-id": "d5496da4-9c52-402f-b067-83cc9ddea888", | ||
"X-Content-Type-Options": "nosniff", | ||
"x-ms-ratelimit-remaining-tenant-reads": "14999", | ||
"x-ms-correlation-request-id": "25c78f97-0b0a-4fe9-ad39-883a482265cd" | ||
}, | ||
"body": { | ||
"location": "West US 2", | ||
"id": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/SampleResourceGroup/providers/Microsoft.Purview/accounts/account1", | ||
"name": "account1", | ||
"type": "Microsoft.Purview/accounts", | ||
"sku": { | ||
"name": "Standard", | ||
"capacity": 1 | ||
}, | ||
"properties": { | ||
"friendlyName": "friendly-account1", | ||
"provisioningState": "Creating", | ||
"accountStatus": { | ||
"accountProvisioningState": "Succeeded", | ||
"errorDetails": {} | ||
}, | ||
"endpoints": { | ||
"catalog": "https://account1.catalog.purview.azure-test.com", | ||
"scan": "https://account1.scan.purview.azure-test.com", | ||
"guardian": "https://account1.guardian.purview.azure-test.com" | ||
}, | ||
"publicNetworkAccess": "Enabled" | ||
} | ||
} | ||
}, | ||
"200": { | ||
"headers": { | ||
"Date": "Wed, 13 Sep 2017 18:04:32 GMT", | ||
"x-ms-request-id": "d5496da4-9c52-402f-b067-83cc9ddea888", | ||
"X-Content-Type-Options": "nosniff", | ||
"x-ms-ratelimit-remaining-tenant-reads": "14999", | ||
"x-ms-correlation-request-id": "25c78f97-0b0a-4fe9-ad39-883a482265cd" | ||
}, | ||
"body": { | ||
"location": "West US 2", | ||
"id": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/SampleResourceGroup/providers/Microsoft.Purview/accounts/account1", | ||
"name": "account1", | ||
"type": "Microsoft.Purview/accounts", | ||
"sku": { | ||
"name": "Standard", | ||
"capacity": 1 | ||
}, | ||
"systemData": { | ||
"createdBy": "client-name", | ||
"createdByType": "User", | ||
"createdAt": "2019-11-22T18:39:58.6929344Z", | ||
"lastModifiedBy": "client-name", | ||
"lastModifiedByType": "User", | ||
"lastModifiedAt": "2021-03-16T23:24:34.3430059Z" | ||
}, | ||
"properties": { | ||
"friendlyName": "friendly-account1", | ||
"provisioningState": "Succeeded", | ||
"accountStatus": { | ||
"accountProvisioningState": "Succeeded", | ||
"errorDetails": {} | ||
}, | ||
"endpoints": { | ||
"catalog": "https://account1.catalog.purview.azure-test.com", | ||
"scan": "https://account1.scan.purview.azure-test.com", | ||
"guardian": "https://account1.guardian.purview.azure-test.com" | ||
}, | ||
"publicNetworkAccess": "Enabled", | ||
"managedResourceGroupName": "custom-rgname", | ||
"managedResourcesPublicNetworkAccess": "Enabled", | ||
"managedResources": { | ||
"resourceGroup": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/custom-rgname", | ||
"storageAccount": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/custom-rgname/providers/Microsoft.Storage/storageAccounts/scanwestustzaagzr", | ||
"eventHubNamespace": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/custom-rgname/providers/Microsoft.EventHub/namespaces/atlas-westusdddnbtp" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.