зеркало из https://github.com/microsoft/cobalt.git
Add ACR Extensions (#407)
* Add acr extension code * Linting, remove licenses, infratest => integration * Adding tf_options Co-authored-by: technicallywilliams <dexterw@microsoft.com>
This commit is contained in:
Родитель
dafc35246c
Коммит
df6eaf803d
|
@ -0,0 +1,4 @@
|
|||
TF_VAR_container_registry_name
|
||||
TF_VAR_resource_group_name
|
||||
TF_VAR_remote_state_account
|
||||
TF_VAR_remote_state_container
|
|
@ -0,0 +1,59 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/microsoft/cobalt/test-harness/terratest-extensions/modules/azure"
|
||||
"github.com/microsoft/terratest-abstraction/integration"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// healthCheck - Asserts that the deployment was successful.
|
||||
func healthCheck(t *testing.T, provisionState string) {
|
||||
require.Equal(t, "Succeeded", provisionState, "The deployment hasn't succeeded.")
|
||||
}
|
||||
|
||||
// validateDeployment - Asserts that ACR deployment was successful
|
||||
func validateDeployment(
|
||||
t *testing.T,
|
||||
output integration.TerraformOutput,
|
||||
subscriptionID string,
|
||||
resourceGroupNameOutput string,
|
||||
containerRegistryNameOutput string) {
|
||||
|
||||
// Obtain the container registry output name
|
||||
acrName := output[containerRegistryNameOutput].(string)
|
||||
|
||||
// Obtain the registry structure
|
||||
resourceGroupName := output[resourceGroupNameOutput].(string)
|
||||
|
||||
require.NotEmpty(t, acrName, "Registry Name not returned.")
|
||||
|
||||
// Get Registry
|
||||
registry, err := azure.ACRRegistryE(subscriptionID, resourceGroupName, acrName)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Get registry's properties
|
||||
properties := registry.RegistryProperties
|
||||
// check that the registry was provisioned
|
||||
healthCheck(t, string(properties.ProvisioningState))
|
||||
|
||||
// check if the admin settings were disabled
|
||||
isAdminEnabled := properties.AdminUserEnabled
|
||||
require.Equal(t, false, *isAdminEnabled, "The admin user identity must be disabled for this registry.")
|
||||
|
||||
}
|
||||
|
||||
// InspectContainerRegistryOutputs - Runs test assertions to validate that the module outputs are valid.
|
||||
func InspectContainerRegistryOutputs(subscriptionID string,
|
||||
resourceGroupNameOutput string,
|
||||
containerRegistryNameOutput string) func(t *testing.T, output integration.TerraformOutput) {
|
||||
return func(t *testing.T, output integration.TerraformOutput) {
|
||||
validateDeployment(t, output, subscriptionID,
|
||||
resourceGroupNameOutput,
|
||||
containerRegistryNameOutput)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/microsoft/cobalt/infra/modules/providers/azure/container-registry/tests"
|
||||
"github.com/microsoft/terratest-abstraction/integration"
|
||||
)
|
||||
|
||||
const outputVariableCount int = 3
|
||||
|
||||
var subscription_id = os.Getenv("ARM_SUBSCRIPTION_ID")
|
||||
|
||||
func TestServiceDeployment(t *testing.T) {
|
||||
|
||||
testFixture := integration.IntegrationTestFixture{
|
||||
GoTest: t,
|
||||
TfOptions: tests.RegistryTFOptions,
|
||||
ExpectedTfOutputCount: outputVariableCount,
|
||||
TfOutputAssertions: []integration.TerraformOutputValidation{
|
||||
InspectContainerRegistryOutputs(subscription_id, "resource_group_name", "container_registry_name"),
|
||||
},
|
||||
}
|
||||
integration.RunIntegrationTests(&testFixture)
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"os"
|
||||
"github.com/gruntwork-io/terratest/modules/terraform"
|
||||
)
|
||||
|
||||
var container_registry_name = os.Getenv("TF_VAR_container_registry_name")
|
||||
var resource_group_name = os.Getenv("TF_VAR_resource_group_name")
|
||||
|
||||
//Sets variable values for module level testing
|
||||
var RegistryTFOptions = &terraform.Options{
|
||||
TerraformDir: ".",
|
||||
Upgrade: true,
|
||||
Vars: map[string]interface{}{
|
||||
"resource_group_name": resource_group_name,
|
||||
"container_registery_name": container_registry_name,
|
||||
},
|
||||
BackendConfig: map[string]interface{}{
|
||||
"storage_account_name": os.Getenv("TF_VAR_remote_state_account"),
|
||||
"container_name": os.Getenv("TF_VAR_remote_state_container"),
|
||||
},
|
||||
}
|
|
@ -2,8 +2,9 @@ package azure
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
|
||||
"testing"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
|
||||
)
|
||||
|
||||
func registriesClientE(subscriptionID string) (*containerregistry.RegistriesClient, error) {
|
||||
|
@ -98,3 +99,19 @@ func ACRWebHookCallback(t *testing.T, subscriptionID string, resourceGroupName s
|
|||
}
|
||||
return webhookCallback
|
||||
}
|
||||
|
||||
// ACRRegistryE - Return the Registry structure for the given ACR
|
||||
func ACRRegistryE(subscriptionID string, resourceGroupName string, acrName string) (*containerregistry.Registry, error) {
|
||||
|
||||
client, err := registriesClientE(subscriptionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
acr, err := client.Get(context.Background(), resourceGroupName, acrName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &acr, nil
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче