diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-07 22:15:55 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-07 22:16:26 +0900 |
| commit | c86ff02d8d794ef31d8f646ae85e776b714c7ef9 (patch) | |
| tree | 6c8fce143e3c0b22d094b8f9c73bacb92c4d1f0d /internal/pkg/pkg_test.go | |
| parent | e8dda70c417a78647ae31930acc0a98ecf5ad097 (diff) | |
internal/pkg: tar optional file
This allows tar to take a single-file directory Artifact as input.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg_test.go')
| -rw-r--r-- | internal/pkg/pkg_test.go | 53 |
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() |
