diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-06 00:56:49 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-06 00:56:49 +0900 |
| commit | e91049c3c5a81bc18fb5394de92a6d7617421938 (patch) | |
| tree | 56d00fab2bc16547de1ccfffb1386b8cf29519c8 /internal/pkg/pkg_test.go | |
| parent | 3d4d32932df47816be751062f2f9e77cc38d0148 (diff) | |
internal/pkg: pass cure context as single value
This cleans up the function signature and makes backwards compatible API changes possible.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg_test.go')
| -rw-r--r-- | internal/pkg/pkg_test.go | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go index 8826e5a1..dca39324 100644 --- a/internal/pkg/pkg_test.go +++ b/internal/pkg/pkg_test.go @@ -73,19 +73,13 @@ type stubArtifact struct { params []byte deps []pkg.Artifact - cure func(work, temp *check.Absolute, loadData pkg.CacheDataFunc) error + cure func(c *pkg.CureContext) error } -func (a stubArtifact) Kind() pkg.Kind { return a.kind } -func (a stubArtifact) Params() []byte { return a.params } -func (a stubArtifact) Dependencies() []pkg.Artifact { return a.deps } - -func (a stubArtifact) Cure( - work, temp *check.Absolute, - loadData pkg.CacheDataFunc, -) error { - return a.cure(work, temp, loadData) -} +func (a stubArtifact) Kind() pkg.Kind { return a.kind } +func (a stubArtifact) Params() []byte { return a.params } +func (a stubArtifact) Dependencies() []pkg.Artifact { return a.deps } +func (a stubArtifact) Cure(c *pkg.CureContext) error { return a.cure(c) } // A stubFile implements [File] with hardcoded behaviour. type stubFile struct { @@ -109,7 +103,7 @@ func newStubFile( kind, nil, nil, - func(*check.Absolute, *check.Absolute, pkg.CacheDataFunc) error { + func(*pkg.CureContext) error { panic("unreachable") }, }}} @@ -410,7 +404,8 @@ func TestCache(t *testing.T) { binary.LittleEndian.AppendUint64(nil, pkg.TarGzip), overrideIdent{testdataChecksum, stubArtifact{}}, ) - makeSample := func(work, _ *check.Absolute, _ pkg.CacheDataFunc) error { + makeSample := func(c *pkg.CureContext) error { + work := c.GetWorkDir() if err := os.Mkdir(work.String(), 0700); err != nil { return err } @@ -511,15 +506,15 @@ func TestCache(t *testing.T) { {"cure fault", overrideIdent{pkg.ID{0xff, 0}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, _ pkg.CacheDataFunc) error { - return makeGarbage(work, stub.UniqueError(0xcafe)) + cure: func(c *pkg.CureContext) error { + return makeGarbage(c.GetWorkDir(), stub.UniqueError(0xcafe)) }, }}, nil, pkg.Checksum{}, stub.UniqueError(0xcafe)}, {"checksum mismatch", overrideChecksum{pkg.Checksum{}, overrideIdent{pkg.ID{0xff, 1}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, _ pkg.CacheDataFunc) error { - return makeGarbage(work, nil) + cure: func(c *pkg.CureContext) error { + return makeGarbage(c.GetWorkDir(), nil) }, }}}, nil, pkg.Checksum{}, &pkg.ChecksumMismatchError{ Got: pkg.MustDecode( @@ -538,8 +533,8 @@ func TestCache(t *testing.T) { {"loadData directory", overrideIdent{pkg.ID{0xff, 3}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, loadData pkg.CacheDataFunc) error { - _, err := loadData(overrideChecksumFile{checksum: wantChecksum}) + cure: func(c *pkg.CureContext) error { + _, err := c.LoadData(overrideChecksumFile{checksum: wantChecksum}) return err }, }}, nil, pkg.Checksum{}, &os.PathError{ @@ -553,22 +548,25 @@ func TestCache(t *testing.T) { {"no output", overrideIdent{pkg.ID{0xff, 4}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, loadData pkg.CacheDataFunc) error { + cure: func(c *pkg.CureContext) error { return nil }, }}, nil, pkg.Checksum{}, pkg.NoOutputError{}}, {"file output", overrideIdent{pkg.ID{0xff, 5}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, loadData pkg.CacheDataFunc) error { - return os.WriteFile(work.String(), []byte{0}, 0400) + cure: func(c *pkg.CureContext) error { + return os.WriteFile(c.GetWorkDir().String(), []byte{0}, 0400) }, }}, nil, pkg.Checksum{}, errors.New("non-file artifact produced regular file")}, {"symlink output", overrideIdent{pkg.ID{0xff, 6}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, loadData pkg.CacheDataFunc) error { - return os.Symlink(work.String(), work.String()) + cure: func(c *pkg.CureContext) error { + return os.Symlink( + c.GetWorkDir().String(), + c.GetWorkDir().String(), + ) }, }}, nil, pkg.Checksum{}, pkg.InvalidFileModeError( fs.ModeSymlink | 0777, @@ -584,7 +582,7 @@ func TestCache(t *testing.T) { go func() { if _, _, err := c.Cure(overrideIdent{pkg.ID{0xff}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, loadData pkg.CacheDataFunc) error { + cure: func(c *pkg.CureContext) error { close(ready) <-n return wantErr @@ -616,10 +614,16 @@ func TestCache(t *testing.T) { {"file output", overrideIdent{pkg.ID{0xff, 2}, stubArtifact{ kind: pkg.KindTar, - cure: func(work, _ *check.Absolute, loadData pkg.CacheDataFunc) error { - return os.WriteFile(work.String(), []byte{0}, 0400) + cure: func(c *pkg.CureContext) error { + return os.WriteFile( + c.GetWorkDir().String(), + []byte{0}, + 0400, + ) }, - }}, nil, pkg.Checksum{}, errors.New("non-file artifact produced regular file")}, + }}, nil, pkg.Checksum{}, errors.New( + "non-file artifact produced regular file", + )}, }) wantErrScrub := &pkg.ScrubError{ |
