diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-03 21:24:50 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-03 21:26:25 +0900 |
| commit | 8ad990906555d843d1212c5eb8a1ac194031426c (patch) | |
| tree | 710c54cad83d8fb20dd6666791249100480a426c /internal/pkg/pkg_test.go | |
| parent | deda16da38187091ec59d28fb4fbc672ff71e70e (diff) | |
internal/pkg: compute identifier from deps
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>
Diffstat (limited to 'internal/pkg/pkg_test.go')
| -rw-r--r-- | internal/pkg/pkg_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go index 79544430..1151a681 100644 --- a/internal/pkg/pkg_test.go +++ b/internal/pkg/pkg_test.go @@ -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. |
