aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-13 19:43:53 +0900
committerOphestra <cat@gensokyo.uk>2026-05-13 19:43:53 +0900
commita759cf3666897e97d8437cd1b74356d20c7cadca (patch)
tree35f002b899c594c2bdb853ae4d63ff9b82882ef8
parent8c2dd3e9848799ac8408b8322e3eba237ce37903 (diff)
internal/pkg: check exec substitution
This relies on the testtool having ident as relevant input to assert successful substitution. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/pkg/exec_test.go40
-rw-r--r--internal/pkg/pkg_test.go23
2 files changed, 50 insertions, 13 deletions
diff --git a/internal/pkg/exec_test.go b/internal/pkg/exec_test.go
index c88ff3f4..74648c0e 100644
--- a/internal/pkg/exec_test.go
+++ b/internal/pkg/exec_test.go
@@ -86,6 +86,30 @@ func TestExec(t *testing.T) {
pkg.MustPath("/opt", false, testtool),
), ignorePathname, wantOffline, nil},
+ {"substitution", pkg.NewExec(
+ "exec-offline", "", new(wantOffline.hash()), 0, false, false,
+ pkg.AbsWork,
+ []string{"HAKUREI_TEST=1"},
+ check.MustAbs("/opt/bin/testtool"),
+ []string{"testtool"},
+
+ pkg.MustPath("/file", false, newStubFile(
+ pkg.KindHTTPGet,
+ pkg.ID{0xfe, 0},
+ nil,
+ nil, nil,
+ )),
+ // substitution miss fails in testtool due to differing idents
+ pkg.MustPath("/.hakurei", false, &stubArtifact{
+ kind: pkg.KindTar,
+ params: []byte("empty directory (substituted)"),
+ cure: func(t *pkg.TContext) error {
+ return os.MkdirAll(t.GetWorkDir().String(), 0700)
+ },
+ }),
+ pkg.MustPath("/opt", false, testtool),
+ ), ignorePathname, wantOffline, nil},
+
{"error passthrough", pkg.NewExec(
"", "", nil, 0, false, true,
pkg.AbsWork,
@@ -147,7 +171,7 @@ func TestExec(t *testing.T) {
t.Errorf("unexpected status:\n%s", string(faultStatus))
}
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 1)
testtoolDestroy(t, base, c)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
@@ -159,6 +183,8 @@ func TestExec(t *testing.T) {
"checksum/OLBgp1GsljhM2TJ-sbHjaiH9txEUvgdDTAzHv2P24donTt6_529l-9Ua0vFImLlb": {Mode: 0400, Data: []byte{}},
"identifier": {Mode: fs.ModeDir | 0700},
+ "identifier/IY91PCtOpCYy21AaIK0c9f8-Z6fb2_2ewoHWkt4dxoLf0GOrWqS8yAGFLV84b1Dw": {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/" + wantOfflineEncode)},
+ "identifier/QwS7SmiatdqryQYgESdGw7Yw2PcpNf0vNfpvUA0t92BTlKiUjfCrXyMW17G2X77X": {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/MGWmEfjut2QE2xPJwTsmUzpff4BN_FEnQ7T0j7gvUCCiugJQNwqt9m151fm9D1yU")},
"identifier/_gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA": {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/OLBgp1GsljhM2TJ-sbHjaiH9txEUvgdDTAzHv2P24donTt6_529l-9Ua0vFImLlb")},
"identifier/" + expected.Offline: {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/" + wantOfflineEncode)},
"identifier/vjz1MHPcGBKV7sjcs8jQP3cqxJ1hgPTiQBMCEHP9BGXjGxd-tJmEmXKaStObo5gK": {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/MGWmEfjut2QE2xPJwTsmUzpff4BN_FEnQ7T0j7gvUCCiugJQNwqt9m151fm9D1yU")},
@@ -202,7 +228,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantNet, nil},
})
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 0)
testtoolDestroy(t, base, c)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
@@ -246,7 +272,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil},
})
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 0)
testtoolDestroy(t, base, c)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
@@ -293,7 +319,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil},
})
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 0)
testtoolDestroy(t, base, c)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
@@ -362,7 +388,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil},
})
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 0)
testtoolDestroy(t, base, c)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
@@ -415,7 +441,7 @@ func TestExec(t *testing.T) {
), ignorePathname, wantOffline, nil},
})
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 0)
testtoolDestroy(t, base, c)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
@@ -480,7 +506,7 @@ func TestExec(t *testing.T) {
}, nil},
})
- destroyStatus(t, base, 2)
+ destroyStatus(t, base, 2, 0)
}, expectsFS{
".": {Mode: fs.ModeDir | 0700},
diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go
index 0877e791..d5c92a6d 100644
--- a/internal/pkg/pkg_test.go
+++ b/internal/pkg/pkg_test.go
@@ -246,26 +246,37 @@ func newDestroyArtifactFunc(a pkg.Artifact) func(
}
// destroyStatus counts non-substitution status entries and destroys them.
-func destroyStatus(t *testing.T, base *check.Absolute, n int) {
+func destroyStatus(t *testing.T, base *check.Absolute, c, s int) {
dents, err := os.ReadDir(base.Append("status").String())
if err != nil {
t.Fatal(err)
}
+ var gotC, gotS int
for _, dent := range dents {
- if !dent.Type().IsRegular() {
- t.Errorf("%s: %s", dent.Name(), dent.Type())
- }
if err = os.Remove(base.Append(
"status",
dent.Name(),
).String()); err != nil {
t.Fatal(err)
}
+
+ if dent.Type().IsRegular() {
+ gotC++
+ continue
+ }
+ if dent.Type()&fs.ModeSymlink == fs.ModeSymlink {
+ gotS++
+ continue
+ }
+ t.Errorf("%s: %s", dent.Name(), dent.Type())
}
- if len(dents) != n {
- t.Errorf("ReadDir: %d entries, want %d", len(dents), n)
+ if gotC != c {
+ t.Errorf("status: c = %d, want %d", gotC, c)
+ }
+ if gotS != s {
+ t.Errorf("status: s = %d, want %d", gotS, s)
}
}