forked from security/hakurei
internal/pkg: standardise artifact IR
This should hopefully provide good separation between the artifact curing backend implementation and the (still work in progress) language. Making the IR parseable also guarantees uniqueness of the representation. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -94,7 +94,7 @@ type stubArtifact struct {
|
||||
}
|
||||
|
||||
func (a *stubArtifact) Kind() pkg.Kind { return a.kind }
|
||||
func (a *stubArtifact) Params(ctx *pkg.IContext) { ctx.GetHash().Write(a.params) }
|
||||
func (a *stubArtifact) Params(ctx *pkg.IContext) { ctx.Write(a.params) }
|
||||
func (a *stubArtifact) Dependencies() []pkg.Artifact { return a.deps }
|
||||
func (a *stubArtifact) Cure(t *pkg.TContext) error { return a.cure(t) }
|
||||
func (*stubArtifact) IsExclusive() bool { return false }
|
||||
@@ -110,7 +110,7 @@ type stubArtifactF struct {
|
||||
}
|
||||
|
||||
func (a *stubArtifactF) Kind() pkg.Kind { return a.kind }
|
||||
func (a *stubArtifactF) Params(ctx *pkg.IContext) { ctx.GetHash().Write(a.params) }
|
||||
func (a *stubArtifactF) Params(ctx *pkg.IContext) { ctx.Write(a.params) }
|
||||
func (a *stubArtifactF) Dependencies() []pkg.Artifact { return a.deps }
|
||||
func (a *stubArtifactF) Cure(f *pkg.FContext) error { return a.cure(f) }
|
||||
func (a *stubArtifactF) IsExclusive() bool { return a.excl }
|
||||
@@ -219,7 +219,7 @@ func TestIdent(t *testing.T) {
|
||||
},
|
||||
nil,
|
||||
}, unique.Make[pkg.ID](pkg.MustDecode(
|
||||
"v86qCz5fDqUsjA3KY_4LIrEh3aQnp04plNiWJ5_ap06McHSSBlROyKIFEwx3c0O7",
|
||||
"WKErnjTOVbuH2P9a0gM4OcAAO4p-CoX2HQu7CbZrg8ZOzApvWoO3-ISzPw6av_rN",
|
||||
))},
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ func TestCache(t *testing.T) {
|
||||
kind: pkg.KindExec,
|
||||
params: []byte("artifact overridden to be incomplete"),
|
||||
}}, nil, pkg.Checksum{}, pkg.InvalidArtifactError(pkg.MustDecode(
|
||||
"0z3fA0YngFaRRCQRrxKburhpAGz3gkYIZ346X_tAwOr_ldelYg1nTifI3-WX8hQD",
|
||||
"E__uZ1sLIvb84vzSm5Uezb03RogsiaeTt1nfIVv8TKnnf4LqwtSi-smdHhlkZrUJ",
|
||||
))},
|
||||
|
||||
{"error passthrough", newStubFile(
|
||||
@@ -954,6 +954,17 @@ func TestErrors(t *testing.T) {
|
||||
{"NoOutputError", pkg.NoOutputError{
|
||||
// empty struct
|
||||
}, "artifact cured successfully but did not produce any output"},
|
||||
|
||||
{"IRKindError", &pkg.IRKindError{
|
||||
Got: pkg.IRKindEnd,
|
||||
Want: pkg.IRKindIdent,
|
||||
Ancillary: 0xcafebabe,
|
||||
}, "got terminator IR value (0xcafebabe) instead of ident"},
|
||||
{"IRKindError invalid", &pkg.IRKindError{
|
||||
Got: 0xbeef,
|
||||
Want: pkg.IRKindIdent,
|
||||
Ancillary: 0xcafe,
|
||||
}, "got invalid kind 48879 IR value (0xcafe) instead of ident"},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user