hakurei/container/initplace_test.go
Ophestra 5d8a2199b6
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m10s
Test / Hakurei (push) Successful in 3m12s
Test / Hpkg (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 4m19s
Test / Hakurei (race detector) (push) Successful in 4m57s
Test / Flake checks (push) Successful in 1m25s
container/init: op interface valid method
Check ops early and eliminate duplicate checks.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-08-21 00:18:50 +09:00

63 lines
1.8 KiB
Go

package container
import "testing"
func TestTmpfileOp(t *testing.T) {
checkOpsValid(t, []opValidTestCase{
{"nil", (*TmpfileOp)(nil), false},
{"zero", new(TmpfileOp), false},
{"valid", &TmpfileOp{Path: MustAbs("/etc/passwd")}, true},
})
checkOpsBuilder(t, []opsBuilderTestCase{
{"noref", new(Ops).Place(MustAbs("/etc/passwd"), []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`)), Ops{
&TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
},
}},
{"ref", new(Ops).PlaceP(MustAbs("/etc/passwd"), new(*[]byte)), Ops{
&TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte{},
},
}},
})
checkOpIs(t, []opIsTestCase{
{"zero", new(TmpfileOp), new(TmpfileOp), false},
{"differs path", &TmpfileOp{
Path: MustAbs("/etc/group"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
}, &TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
}, false},
{"differs data", &TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh` + "\x00"),
}, &TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
}, false},
{"equals", &TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
}, &TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
}, true},
})
checkOpMeta(t, []opMetaTestCase{
{"passwd", &TmpfileOp{
Path: MustAbs("/etc/passwd"),
Data: []byte(`chronos:x:65534:65534:Hakurei:/var/empty:/bin/zsh`),
}, "placing", `tmpfile "/etc/passwd" (49 bytes)`},
})
}