aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg/pkg_test.go')
-rw-r--r--internal/pkg/pkg_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go
index 54997624..bb7d760b 100644
--- a/internal/pkg/pkg_test.go
+++ b/internal/pkg/pkg_test.go
@@ -117,6 +117,59 @@ func newStubFile(
}
}
+// destroyArtifact removes all traces of an [Artifact] from the on-disk cache.
+// Do not use this in a test case without a very good reason to do so.
+func destroyArtifact(
+ t *testing.T,
+ base *check.Absolute,
+ c *pkg.Cache,
+ a pkg.Artifact,
+) {
+ if pathname, checksum, err := c.Cure(a); err != nil {
+ t.Fatalf("Cure: error = %v", err)
+ } else if err = os.Remove(pathname.String()); err != nil {
+ t.Fatal(err)
+ } else {
+ p := base.Append(
+ "checksum",
+ pkg.Encode(checksum),
+ )
+ if err = filepath.WalkDir(p.String(), func(
+ path string,
+ d fs.DirEntry,
+ err error,
+ ) error {
+ if err != nil {
+ return err
+ }
+ if d.IsDir() {
+ return os.Chmod(path, 0700)
+ }
+ return nil
+ }); err != nil && !errors.Is(err, os.ErrNotExist) {
+ t.Fatal(err)
+ }
+ if err = os.RemoveAll(p.String()); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+// newDestroyArtifactFunc returns a function that calls destroyArtifact.
+func newDestroyArtifactFunc(a pkg.Artifact) func(
+ t *testing.T,
+ base *check.Absolute,
+ c *pkg.Cache,
+) {
+ return func(
+ t *testing.T,
+ base *check.Absolute,
+ c *pkg.Cache,
+ ) {
+ destroyArtifact(t, base, c, a)
+ }
+}
+
func TestIdent(t *testing.T) {
t.Parallel()