internal/pkg: implement caching for directories
All checks were successful
Test / Create distribution (push) Successful in 45s
Test / Sandbox (push) Successful in 2m30s
Test / Hakurei (push) Successful in 3m38s
Test / ShareFS (push) Successful in 3m40s
Test / Hpkg (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 4m50s
Test / Hakurei (race detector) (push) Successful in 5m49s
Test / Flake checks (push) Successful in 1m43s
All checks were successful
Test / Create distribution (push) Successful in 45s
Test / Sandbox (push) Successful in 2m30s
Test / Hakurei (push) Successful in 3m38s
Test / ShareFS (push) Successful in 3m40s
Test / Hpkg (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 4m50s
Test / Hakurei (race detector) (push) Successful in 5m49s
Test / Flake checks (push) Successful in 1m43s
This works on any directories and should be robust against any bad state the artifact curing process might have failed at. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -3,6 +3,7 @@ package pkg_test
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha512"
|
||||
"encoding/binary"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -303,6 +304,158 @@ func TestCache(t *testing.T) {
|
||||
t.Fatalf("LoadFile: error = %#v, want %#v", err, wantErrNonexistentZero)
|
||||
}
|
||||
}, pkg.MustDecode("G4u4W77C3u46oSAzwPTERKbS9h76iIvcd7Zl8p8Y6hTMb4_QGpH0Glg_DIJg-Usa")},
|
||||
|
||||
{"directory", nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
id := pkg.KindTar.Ident(
|
||||
binary.LittleEndian.AppendUint64(nil, 1),
|
||||
stubArtifact{pkg.KindHTTP, testdataChecksum},
|
||||
)
|
||||
makeSample := func(work *check.Absolute) error {
|
||||
if err := os.WriteFile(
|
||||
work.Append("check").String(),
|
||||
[]byte{0, 0},
|
||||
0400,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(work.Append(
|
||||
"lib",
|
||||
"pkgconfig",
|
||||
).String(), 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Symlink(
|
||||
"/proc/nonexistent/libedac.so",
|
||||
work.Append(
|
||||
"lib",
|
||||
"libedac.so",
|
||||
).String(),
|
||||
)
|
||||
}
|
||||
wantChecksum := pkg.MustDecode(
|
||||
"1TL00Qb8dcqayX7wTO8WNaraHvY6b-KCsctLDTrb64QBCmxj_-byK1HdIUwMaFEP",
|
||||
)
|
||||
wantPathname := base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(id),
|
||||
)
|
||||
|
||||
if pathname, store, err := c.Store(
|
||||
id,
|
||||
makeSample,
|
||||
&wantChecksum,
|
||||
true,
|
||||
); err != nil {
|
||||
t.Fatalf("Store: error = %v", err)
|
||||
} else if !store {
|
||||
t.Fatal("Store did not store nonpresent entry")
|
||||
} else if !pathname.Is(wantPathname) {
|
||||
t.Fatalf("Store: pathname = %q, want %q", pathname, wantPathname)
|
||||
}
|
||||
|
||||
// check lookup
|
||||
if pathname, store, err := c.Store(
|
||||
id,
|
||||
nil,
|
||||
&wantChecksum,
|
||||
true,
|
||||
); err != nil {
|
||||
t.Fatalf("Store: error = %v", err)
|
||||
} else if store {
|
||||
t.Fatal("Store stored over present entry")
|
||||
} else if !pathname.Is(wantPathname) {
|
||||
t.Fatalf("Store: pathname = %q, want %q", pathname, wantPathname)
|
||||
}
|
||||
|
||||
// check exist
|
||||
id0 := pkg.KindTar.Ident(
|
||||
binary.LittleEndian.AppendUint64(nil, 1),
|
||||
stubArtifact{pkg.KindHTTP, pkg.ID{}},
|
||||
)
|
||||
wantPathname0 := base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(id0),
|
||||
)
|
||||
if pathname, store, err := c.Store(
|
||||
id0,
|
||||
makeSample,
|
||||
&wantChecksum,
|
||||
true,
|
||||
); err != nil {
|
||||
t.Fatalf("Store: error = %v", err)
|
||||
} else if !store {
|
||||
t.Fatal("Store did not store nonpresent entry")
|
||||
} else if !pathname.Is(wantPathname0) {
|
||||
t.Fatalf("Store: pathname = %q, want %q", pathname, wantPathname0)
|
||||
}
|
||||
|
||||
var wantErrMakeGarbage error
|
||||
makeGarbage := func(work *check.Absolute) error {
|
||||
mode := fs.FileMode(0)
|
||||
if wantErrMakeGarbage == nil {
|
||||
mode = 0500
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(work.Append(
|
||||
"lib",
|
||||
"pkgconfig",
|
||||
).String(), 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(work.Append(
|
||||
"lib",
|
||||
"check",
|
||||
).String(), nil, 0400&mode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chmod(work.Append(
|
||||
"lib",
|
||||
"pkgconfig",
|
||||
).String(), 0500&mode); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Chmod(work.Append(
|
||||
"lib",
|
||||
).String(), 0500&mode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return wantErrMakeGarbage
|
||||
}
|
||||
|
||||
// check makeArtifact fault
|
||||
wantErrMakeGarbage = stub.UniqueError(0xcafe)
|
||||
if _, store, err := c.Store(
|
||||
pkg.ID{},
|
||||
makeGarbage,
|
||||
nil,
|
||||
false,
|
||||
); !reflect.DeepEqual(err, wantErrMakeGarbage) {
|
||||
t.Fatalf("Store: error = %#v, want %#v", err, wantErrMakeGarbage)
|
||||
} else if !store {
|
||||
t.Fatal("Store did not store nonpresent entry")
|
||||
}
|
||||
|
||||
// checksum mismatch
|
||||
wantErrMakeGarbage = nil
|
||||
wantErrMismatch := &pkg.ChecksumMismatchError{
|
||||
Got: pkg.MustDecode("GbjlYMcHQANdfwL6qNGopBF99IscPTvCy95HSH1_kIF3eKjFDSLP0_iUUT0z8hiw"),
|
||||
}
|
||||
if _, store, err := c.Store(
|
||||
pkg.ID{},
|
||||
makeGarbage,
|
||||
new(pkg.Checksum),
|
||||
true,
|
||||
); !reflect.DeepEqual(err, wantErrMismatch) {
|
||||
t.Fatalf("Store: error = %v, want %v", err, wantErrMismatch)
|
||||
} else if !store {
|
||||
t.Fatal("Store did not store nonpresent entry")
|
||||
}
|
||||
}, pkg.MustDecode("N7dntFYbOq9V4iC-rjAQ-By6ofPIQVZkA8V0r0G07M_sdB7Zh42Ttrspsc38ioYa")},
|
||||
}
|
||||
checkWithCache(t, testCases)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user