internal/pkg: relocate testtool workaround
All checks were successful
Test / Create distribution (push) Successful in 50s
Test / Sandbox (push) Successful in 3m8s
Test / ShareFS (push) Successful in 5m39s
Test / Sandbox (race detector) (push) Successful in 5m48s
Test / Hpkg (push) Successful in 6m7s
Test / Hakurei (push) Successful in 7m6s
Test / Hakurei (race detector) (push) Successful in 8m27s
Test / Flake checks (push) Successful in 1m42s
All checks were successful
Test / Create distribution (push) Successful in 50s
Test / Sandbox (push) Successful in 3m8s
Test / ShareFS (push) Successful in 5m39s
Test / Sandbox (race detector) (push) Successful in 5m48s
Test / Hpkg (push) Successful in 6m7s
Test / Hakurei (push) Successful in 7m6s
Test / Hakurei (race detector) (push) Successful in 8m27s
Test / Flake checks (push) Successful in 1m42s
This can be reused in other test cases. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -27,26 +27,9 @@ func TestExec(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
checkWithCache(t, []cacheTestCase{
|
||||
{"container", nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
{"offline", nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
c.SetStrict(true)
|
||||
|
||||
// this is built during go:generate and is not deterministic
|
||||
testtool := overrideIdent{pkg.ID{0xfe, 0xff}, stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(c *pkg.CureContext) error {
|
||||
work := c.GetWorkDir()
|
||||
if err := os.MkdirAll(
|
||||
work.Append("bin").String(),
|
||||
0700,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(c.GetWorkDir().Append(
|
||||
"bin",
|
||||
"testtool",
|
||||
).String(), testtoolBin, 0500)
|
||||
},
|
||||
}}
|
||||
testtool, testtoolDestroy := newTesttool()
|
||||
|
||||
msg := message.New(log.New(os.Stderr, "container: ", 0))
|
||||
msg.SwapVerbose(testing.Verbose())
|
||||
@@ -125,26 +108,54 @@ func TestExec(t *testing.T) {
|
||||
t.Fatalf("Cure: error = %v, want init exit status 1", err)
|
||||
}
|
||||
|
||||
// the testtool is not deterministic
|
||||
if pathname, checksum, err := c.Cure(testtool); err != nil {
|
||||
t.Fatalf("Cure: error = %v", err)
|
||||
} else if err = os.Remove(pathname.String()); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
p := base.Append(
|
||||
"checksum",
|
||||
pkg.Encode(checksum),
|
||||
)
|
||||
if err = os.Chmod(p.Append("bin").String(), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = os.Chmod(p.String(), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = os.RemoveAll(p.String()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
testtoolDestroy(t, base, c)
|
||||
}, pkg.MustDecode("7PoPpWLjFPXIymbuIYLZAzOpCYr-2PN4CZ11jFdO-mDlnZNgFO3JyOtK8HW8Jxvm")},
|
||||
})
|
||||
}
|
||||
|
||||
// newTesttool returns an [Artifact] that cures into testtoolBin. The returned
|
||||
// function must be called at the end of the test but not deferred.
|
||||
func newTesttool() (
|
||||
testtool pkg.Artifact,
|
||||
testtoolDestroy func(t *testing.T, base *check.Absolute, c *pkg.Cache),
|
||||
) {
|
||||
// testtoolBin is built during go:generate and is not deterministic
|
||||
testtool = overrideIdent{pkg.ID{0xfe, 0xff}, stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(c *pkg.CureContext) error {
|
||||
work := c.GetWorkDir()
|
||||
if err := os.MkdirAll(
|
||||
work.Append("bin").String(),
|
||||
0700,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(c.GetWorkDir().Append(
|
||||
"bin",
|
||||
"testtool",
|
||||
).String(), testtoolBin, 0500)
|
||||
},
|
||||
}}
|
||||
testtoolDestroy = func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
|
||||
if pathname, checksum, err := c.Cure(testtool); err != nil {
|
||||
t.Fatalf("Cure: error = %v", err)
|
||||
} else if err = os.Remove(pathname.String()); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
p := base.Append(
|
||||
"checksum",
|
||||
pkg.Encode(checksum),
|
||||
)
|
||||
if err = os.Chmod(p.Append("bin").String(), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = os.Chmod(p.String(), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = os.RemoveAll(p.String()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user