mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
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:
25
testutil/cache.go
Normal file
25
testutil/cache.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user