mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
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.
26 lines
600 B
Go
26 lines
600 B
Go
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
|
|
}
|