internal/pkg: compute identifier from deps
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m31s
Test / Hakurei (push) Successful in 3m34s
Test / ShareFS (push) Successful in 3m40s
Test / Hpkg (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 4m51s
Test / Hakurei (race detector) (push) Successful in 5m50s
Test / Flake checks (push) Successful in 1m46s
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m31s
Test / Hakurei (push) Successful in 3m34s
Test / ShareFS (push) Successful in 3m40s
Test / Hpkg (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 4m51s
Test / Hakurei (race detector) (push) Successful in 5m50s
Test / Flake checks (push) Successful in 1m46s
This provides infrastructure for computing a deterministic identifier based on current artifact kind, opaque parameters data, and optional dependency kind and identifiers. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -18,6 +18,46 @@ import (
|
||||
"hakurei.app/internal/pkg"
|
||||
)
|
||||
|
||||
// A stubArtifact implements [Artifact] with hardcoded kind and identifier.
|
||||
type stubArtifact struct {
|
||||
kind pkg.Kind
|
||||
id pkg.ID
|
||||
}
|
||||
|
||||
func (a stubArtifact) Kind() pkg.Kind { return a.kind }
|
||||
func (a stubArtifact) ID() pkg.ID { return a.id }
|
||||
func (a stubArtifact) Hash() (pkg.Checksum, error) { panic("unreachable") }
|
||||
func (a stubArtifact) Pathname() (*check.Absolute, error) { panic("unreachable") }
|
||||
|
||||
func TestIdent(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
kind pkg.Kind
|
||||
params []byte
|
||||
deps []pkg.Artifact
|
||||
want pkg.ID
|
||||
}{
|
||||
{"tar", pkg.KindTar, []byte{
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
}, []pkg.Artifact{
|
||||
stubArtifact{pkg.KindHTTP, pkg.ID{}},
|
||||
}, pkg.MustDecode("HnySzeLQvSBZuTUcvfmLEX_OmH4yJWWH788NxuLuv7kVn8_uPM6Ks4rqFWM2NZJY")},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := tc.kind.Ident(tc.params, tc.deps...); got != tc.want {
|
||||
t.Errorf("Ident: %s, want %s",
|
||||
base64.URLEncoding.EncodeToString(got[:]),
|
||||
base64.URLEncoding.EncodeToString(tc.want[:]))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// cacheTestCase is a test case passed to checkWithCache where a new instance
|
||||
// of [pkg.Cache] is prepared for the test case, and is validated and removed
|
||||
// on test completion.
|
||||
|
||||
Reference in New Issue
Block a user