internal/pkg: improve artifact interface
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m35s
Test / Hakurei (push) Successful in 3m36s
Test / ShareFS (push) Successful in 3m41s
Test / Hpkg (push) Successful in 4m19s
Test / Sandbox (race detector) (push) Successful in 4m52s
Test / Hakurei (race detector) (push) Successful in 5m52s
Test / Flake checks (push) Successful in 1m53s

This moves all cache I/O code to Cache. Artifact now only contains methods for constructing their actual contents.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-04 21:57:57 +09:00
parent d6e4f85864
commit 4897b0259e
6 changed files with 1013 additions and 773 deletions

View File

@@ -79,7 +79,7 @@ func TestTar(t *testing.T) {
return pkg.ID(h.Sum(nil))
}()
a, err := c.NewHTTPGetTar(
a, err := pkg.NewHTTPGetTar(
t.Context(),
&client,
"file:///testdata",
@@ -89,27 +89,27 @@ func TestTar(t *testing.T) {
if err != nil {
t.Fatalf("NewHTTPGetTar: error = %v", err)
} else if id := a.ID(); id != wantIdent {
t.Fatalf("ID: %s, want %s", pkg.Encode(id), pkg.Encode(wantIdent))
} else if id := pkg.Ident(a); id != wantIdent {
t.Fatalf("Ident: %s, want %s", pkg.Encode(id), pkg.Encode(wantIdent))
}
var pathname *check.Absolute
var (
pathname *check.Absolute
checksum pkg.Checksum
)
wantPathname := base.Append(
"identifier",
pkg.Encode(wantIdent),
)
if pathname, err = a.Pathname(); err != nil {
t.Fatalf("Pathname: error = %v", err)
wantChecksum := pkg.MustDecode(
"yJlSb2A3jxaMLuKqwp1GwHOguAHddS9MjygF9ICEeegKfRvgLPdPmNh8mva47f8o",
)
if pathname, checksum, err = c.Cure(a); err != nil {
t.Fatalf("Cure: error = %v", err)
} else if !pathname.Is(wantPathname) {
t.Fatalf("Pathname: %q, want %q", pathname, wantPathname)
}
var checksum pkg.Checksum
wantChecksum := pkg.MustDecode("yJlSb2A3jxaMLuKqwp1GwHOguAHddS9MjygF9ICEeegKfRvgLPdPmNh8mva47f8o")
if checksum, err = a.Hash(); err != nil {
t.Fatalf("Hash: error = %v", err)
t.Fatalf("Cure: %q, want %q", pathname, wantPathname)
} else if checksum != wantChecksum {
t.Fatalf("Hash: %v", &pkg.ChecksumMismatchError{
t.Fatalf("Cure: %v", &pkg.ChecksumMismatchError{
Got: checksum,
Want: wantChecksum,
})