Перейти к файлу
github-actions[bot] 491c0f0f06 solve gosec issue 2024-09-14 02:40:44 +00:00
.devcontainer add devcontainer config 2022-12-28 10:34:43 +08:00
.github bump gosec version 2024-09-14 02:32:32 +00: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 refactor code, add stream logger serialize output to stdout test 2023-02-01 19:35:12 +08:00
.gitignore refactor code, ignore TestRecord.md.tmp 2023-02-03 07:16:57 +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 fix badge urls 2023-02-02 22:32:34 +08:00
SECURITY.md new files 2022-09-06 14:06:53 +08:00
breakingchange.go ignore .idea folder, resort imports 2023-01-19 15:22:18 +08:00
breakingchange_test.go Add e2e test. 2022-10-16 09:29:35 +08:00
e2etest.go try to fix golangci-lint issues by fix golangci-lint version 2024-08-20 09:19:23 +08:00
e2etest_test.go add new e2e test method so we can skip idempotent check since some examples would try to retrieve data from data plane api and would failed due to the network policy 2023-03-22 13:28:53 +08:00
go.mod Bump golang.org/x/oauth2 from 0.22.0 to 0.23.0 2024-09-14 02:20:47 +00:00
go.sum Bump golang.org/x/oauth2 from 0.22.0 to 0.23.0 2024-09-14 02:20:47 +00:00
module.go remove unused field 2022-10-31 16:53:35 +08:00
retryable_errors.go try to fix golangci-lint issues by fix golangci-lint version 2024-08-20 09:19:23 +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 try to fix golangci-lint issues by fix golangci-lint version 2024-08-20 09:19:23 +08:00
stream_logger.go adjust logging sample output content 2023-02-02 11:54:12 +08:00
stream_logger_test.go try to fix golangci-lint issues by fix golangci-lint version 2024-08-20 09:19:23 +08:00
unittest.go skip destroy for unit test 2023-07-28 13:07:12 +08:00
unittest_test.go add unit test method, no synchronized logger or test snapshot in unit test 2023-02-21 13:40:38 +08:00
upgradetest.go solve gosec issue 2024-09-14 02:40:44 +00:00
upgradetest_test.go ignore .idea folder, resort imports 2023-01-19 15:22:18 +08:00
variable_file.go add vars2file method so we can set complex type variable by using varfile 2023-05-31 17:01:55 +08:00
variable_file_test.go add vars2file method so we can set complex type variable by using varfile 2023-05-31 17:01:55 +08:00
version_helper.go solve gosec issue 2024-09-14 02:40:44 +00:00
version_helper_test.go refactor code, ignore TestRecord.md.tmp 2023-02-03 07:16:57 +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.