(t *testing.T)
| 34 | ) |
| 35 | |
| 36 | func TestPluginCache_Golden(t *testing.T) { |
| 37 | t.Parallel() |
| 38 | |
| 39 | prepare := func() (afero.Fs, slog.Logger) { |
| 40 | // afero.MemMapFs does not modify atimes, so use a real FS instead. |
| 41 | tmpDir := t.TempDir() |
| 42 | fs := afero.NewBasePathFs(afero.NewOsFs(), tmpDir) |
| 43 | logger := testutil.Logger(t). |
| 44 | Leveled(slog.LevelDebug). |
| 45 | Named("cleanup-test") |
| 46 | return fs, logger |
| 47 | } |
| 48 | |
| 49 | t.Run("all plugins are stale", func(t *testing.T) { |
| 50 | t.Parallel() |
| 51 | |
| 52 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 53 | defer cancel() |
| 54 | |
| 55 | fs, logger := prepare() |
| 56 | |
| 57 | // given |
| 58 | // This plugin is older than 30 days. |
| 59 | addPluginFile(t, fs, coderPluginPath, "terraform-provider-coder_v0.11.1", now.Add(-63*24*time.Hour)) |
| 60 | addPluginFile(t, fs, coderPluginPath, "LICENSE", now.Add(-33*24*time.Hour)) |
| 61 | addPluginFile(t, fs, coderPluginPath, "README.md", now.Add(-31*24*time.Hour)) |
| 62 | addPluginFolder(t, fs, coderPluginPath, "new_folder", now.Add(-31*24*time.Hour)) |
| 63 | addPluginFile(t, fs, coderPluginPath, filepath.Join("new_folder", "foobar.tf"), now.Add(-43*24*time.Hour)) |
| 64 | |
| 65 | // This plugin is older than 30 days. |
| 66 | addPluginFile(t, fs, dockerPluginPath, "terraform-provider-docker_v2.25.0", now.Add(-31*24*time.Hour)) |
| 67 | addPluginFile(t, fs, dockerPluginPath, "LICENSE", now.Add(-32*24*time.Hour)) |
| 68 | addPluginFile(t, fs, dockerPluginPath, "README.md", now.Add(-33*24*time.Hour)) |
| 69 | |
| 70 | // when |
| 71 | terraform.CleanStaleTerraformPlugins(ctx, cachePath, fs, now, logger) |
| 72 | |
| 73 | // then |
| 74 | diffFileSystem(t, fs) |
| 75 | }) |
| 76 | |
| 77 | t.Run("one plugin is stale", func(t *testing.T) { |
| 78 | t.Parallel() |
| 79 | |
| 80 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 81 | defer cancel() |
| 82 | |
| 83 | fs, logger := prepare() |
| 84 | |
| 85 | // given |
| 86 | addPluginFile(t, fs, coderPluginPath, "terraform-provider-coder_v0.11.1", now.Add(-2*time.Hour)) |
| 87 | addPluginFile(t, fs, coderPluginPath, "LICENSE", now.Add(-3*time.Hour)) |
| 88 | addPluginFile(t, fs, coderPluginPath, "README.md", now.Add(-4*time.Hour)) |
| 89 | addPluginFolder(t, fs, coderPluginPath, "new_folder", now.Add(-5*time.Hour)) |
| 90 | addPluginFile(t, fs, coderPluginPath, filepath.Join("new_folder", "foobar.tf"), now.Add(-4*time.Hour)) |
| 91 | |
| 92 | // This plugin is older than 30 days. |
| 93 | addPluginFile(t, fs, dockerPluginPath, "terraform-provider-docker_v2.25.0", now.Add(-31*24*time.Hour)) |
nothing calls this directly
no test coverage detected