aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/autoetc_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-20 02:37:11 +0900
committerOphestra <cat@gensokyo.uk>2025-08-20 02:37:11 +0900
commitb4c018da8f5280bf3e2716c8ccfea82f4459e80a (patch)
tree9389a3584cdc4a85421d61cc7f803bdee47c3e55 /container/autoetc_test.go
parent66f52407d3a7f59fd7e2743fe1ccee7ad46df795 (diff)
container/autoetc: do not bypass absolute check
This can now be done cleanly via path function wrappers. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/autoetc_test.go')
-rw-r--r--container/autoetc_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/container/autoetc_test.go b/container/autoetc_test.go
new file mode 100644
index 00000000..4040fb0d
--- /dev/null
+++ b/container/autoetc_test.go
@@ -0,0 +1,40 @@
+package container
+
+import "testing"
+
+func TestAutoEtcOp(t *testing.T) {
+ checkOpsBuilder(t, []opsBuilderTestCase{
+ {"pd", new(Ops).Etc(MustAbs("/etc/"), "048090b6ed8f9ebb10e275ff5d8c0659"), Ops{
+ &MkdirOp{Path: MustAbs("/etc/"), Perm: 0755},
+ &BindMountOp{
+ Source: MustAbs("/etc/"),
+ Target: MustAbs("/etc/.host/048090b6ed8f9ebb10e275ff5d8c0659"),
+ },
+ &AutoEtcOp{Prefix: "048090b6ed8f9ebb10e275ff5d8c0659"},
+ }},
+ })
+
+ checkOpIs(t, []opIsTestCase{
+ {"zero", new(AutoEtcOp), new(AutoEtcOp), true},
+ {"differs", &AutoEtcOp{Prefix: "\x00"}, &AutoEtcOp{":3"}, false},
+ {"equals", &AutoEtcOp{Prefix: ":3"}, &AutoEtcOp{":3"}, true},
+ })
+
+ checkOpMeta(t, []opMetaTestCase{
+ {"etc", &AutoEtcOp{
+ Prefix: ":3",
+ }, "setting up", "auto etc :3"},
+ })
+
+ t.Run("host path rel", func(t *testing.T) {
+ op := &AutoEtcOp{Prefix: "048090b6ed8f9ebb10e275ff5d8c0659"}
+ wantHostPath := "/etc/.host/048090b6ed8f9ebb10e275ff5d8c0659"
+ wantHostRel := ".host/048090b6ed8f9ebb10e275ff5d8c0659"
+ if got := op.hostPath(); got.String() != wantHostPath {
+ t.Errorf("hostPath: %q, want %q", got, wantHostPath)
+ }
+ if got := op.hostRel(); got != wantHostRel {
+ t.Errorf("hostRel: %q, want %q", got, wantHostRel)
+ }
+ })
+}