GetTestTFCacheDir returns a unique cache directory path based on the test name and template files. Each test gets a unique cache dir based on its name and template files. This ensures that tests can download providers in parallel and that they will redownload providers if the template files change.
(t *testing.T, rootDir string, testName string, templateFiles map[string]string)
| 103 | // This ensures that tests can download providers in parallel and that they |
| 104 | // will redownload providers if the template files change. |
| 105 | func GetTestTFCacheDir(t *testing.T, rootDir string, testName string, templateFiles map[string]string) string { |
| 106 | t.Helper() |
| 107 | |
| 108 | hash := hashTemplateFilesAndTestName(t, testName, templateFiles) |
| 109 | dir := filepath.Join(rootDir, hash[:12]) |
| 110 | return dir |
| 111 | } |
| 112 | |
| 113 | // DownloadTFProviders ensures Terraform providers are downloaded and cached locally in a unique directory for the test. |
| 114 | // Uses `terraform init` then `mirror` to populate the cache if needed. |