chore: cache terraform providers between CI test runs (#17373)

Addresses https://github.com/coder/internal/issues/322.

This PR starts caching Terraform providers used by `TestProvision` in
`provisioner/terraform/provision_test.go`. The goal is to improve the
reliability of this test by cutting down on the number of network calls
to external services. It leverages GitHub Actions cache, which [on depot
runners is persisted for 14 days by
default](https://depot.dev/docs/github-actions/overview#cache-retention-policy).

Other than the aforementioned `TestProvision`, I couldn't find any other
tests which depend on external terraform providers.
This commit is contained in:
Hugo Dutka
2025-04-28 10:57:24 +02:00
committed by GitHub
parent 08ad910171
commit b47d54d777
7 changed files with 393 additions and 34 deletions

25
testutil/cache.go Normal file
View File

@ -0,0 +1,25 @@
package testutil
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
// PersistentCacheDir returns a path to a directory
// that will be cached between test runs in Github Actions.
func PersistentCacheDir(t *testing.T) string {
t.Helper()
// We don't use os.UserCacheDir() because the path it
// returns is different on different operating systems.
// This would make it harder to specify which cache dir to use
// in Github Actions.
home, err := os.UserHomeDir()
require.NoError(t, err)
dir := filepath.Join(home, ".cache", "coderv2-test")
return dir
}