Перейти к файлу
zjhe bb388e19fb update badge url 2022-12-30 13:59:32 +08:00
.devcontainer add devcontainer config 2022-12-28 10:34:43 +08:00
.github add dependabot config 2022-12-27 13:15:35 +08:00
bin/breaking_detect change main arg, add targetRef arg so we can use ref other than latest default branch in case the pr's target is not default branch. 2022-10-16 16:16:20 +08:00
example use tfmodredirector to modify hcl file directly so we don't need override file anymore 2022-12-01 19:14:31 +08:00
.gitignore init commit (#1) 2022-03-01 13:17:23 +08:00
CODE_OF_CONDUCT.md new files 2022-09-06 14:06:53 +08:00
LICENSE new files 2022-09-06 14:06:53 +08:00
README.md update badge url 2022-12-30 13:59:32 +08:00
SECURITY.md new files 2022-09-06 14:06:53 +08:00
breakingchange.go change main arg, add targetRef arg so we can use ref other than latest default branch in case the pr's target is not default branch. 2022-10-16 16:16:20 +08:00
breakingchange_test.go Add e2e test. 2022-10-16 09:29:35 +08:00
e2etest.go disable refresh when execute destroy so config validation error won't block destroy 2022-12-30 13:47:57 +08:00
e2etest_test.go use tfmodredirector to modify hcl file directly so we don't need override file anymore 2022-12-01 19:14:31 +08:00
go.mod Bump github.com/hashicorp/hcl/v2 from 2.12.0 to 2.15.0 (#6) 2022-12-28 10:42:52 +08:00
go.sum Bump github.com/hashicorp/hcl/v2 from 2.12.0 to 2.15.0 (#6) 2022-12-28 10:42:52 +08:00
module.go remove unused field 2022-10-31 16:53:35 +08:00
retryable_errors.go change ReadRetryableErrors argument's type from File to []byte 2022-11-22 18:46:00 +08:00
retryable_errors_sample.hcl.json add ReadRetryableErros method so acceptance tests can assign some errors to retry 2022-11-16 14:55:36 +08:00
retryable_errors_test.go change ReadRetryableErrors argument's type from File to []byte 2022-11-22 18:46:00 +08:00
upgradetest.go remove deprecated annotation. 2022-12-12 19:44:30 +08:00
upgradetest_test.go use tfmodredirector to modify hcl file directly so we don't need override file anymore 2022-12-01 19:14:31 +08:00

README.md

Azure Verified Terraform Module Test Helper

test lint

This repo contains two helper functions that were used to test Azure Verified Terraform Module.

For End-End test:

func TestExamplesStartup(t *testing.T) {
	vars := map[string]interface{}{
		"client_id":     "",
		"client_secret": "",
	}
	managedIdentityId := os.Getenv("MSI_ID")
	if managedIdentityId != "" {
		vars["managed_identity_principal_id"] = managedIdentityId
	}
	test_helper.RunE2ETest(t, "../../", "examples/startup", terraform.Options{
		Upgrade: true,
		Vars:    vars,
	}, func(t *testing.T, output test_helper.TerraformOutput) {
		aksId, ok := output["test_aks_id"].(string)
		assert.True(t, ok)
		assert.Regexp(t, regexp.MustCompile("/subscriptions/.+/resourceGroups/.+/providers/Microsoft.ContainerService/managedClusters/.+"), aksId)
	})
}

The RunE2ETest function accept module's root path, sub-folder to example code that our test want to apply, a terraform.Options argument, and an assertion callback.

In E2E test we apply the example code,then we execute terraform output and pass the json format output to this assertion callback, you can assert whether the output meets your spec there.

For Version-Upgrade Test:

func TestExampleUpgrade_startup(t *testing.T) {
	currentRoot, err := test_helper.GetCurrentModuleRootPath()
	if err != nil {
		t.FailNow()
	}
	currentMajorVersion, err := test_helper.GetCurrentMajorVersionFromEnv()
	if err != nil {
		t.FailNow()
	}
	vars := map[string]interface{}{
		"client_id":     "",
		"client_secret": "",
	}
	managedIdentityId := os.Getenv("MSI_ID")
	if managedIdentityId != "" {
		vars["managed_identity_principal_id"] = managedIdentityId
	}
	test_helper.ModuleUpgradeTest(t, "Azure", "terraform-azurerm-aks", "examples/startup", currentRoot, terraform.Options{
		Upgrade: true,
		Vars:    vars,
	}, currentMajorVersion)
}

The ModuleUpgradeTest function accept your Github repo's owner name (could be username or org name), repo name, sub-folder to example code, and module's current major version (eg: v3.0.0 major version is 3).

The ModuleUpgradeTest function will clone and checkout the latest released tag version within the major version you've passed, apply the code in a temp directory, then modify the module's source to the current path, then execute terraform plan to see if there would be any drift in the plan.