aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/outcome/spaccount_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-29 04:32:43 +0900
committerOphestra <cat@gensokyo.uk>2025-10-29 04:33:13 +0900
commita0b4e47acc228e48165966d8e139277b8f6f450e (patch)
treed363a6781536ce946aa445271ca1d3df587e6031 /internal/outcome/spaccount_test.go
parenta52f7038e5a607dd0901244abb791c96deaf9c2d (diff)
internal/outcome: rename from app
This is less ambiguous, and more accurately describes the purpose of the package. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/outcome/spaccount_test.go')
-rw-r--r--internal/outcome/spaccount_test.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/internal/outcome/spaccount_test.go b/internal/outcome/spaccount_test.go
new file mode 100644
index 00000000..c1693dd8
--- /dev/null
+++ b/internal/outcome/spaccount_test.go
@@ -0,0 +1,72 @@
+package outcome
+
+import (
+ "os"
+ "syscall"
+ "testing"
+
+ "hakurei.app/container"
+ "hakurei.app/container/stub"
+ "hakurei.app/hst"
+)
+
+func TestSpAccountOp(t *testing.T) {
+ t.Parallel()
+ config := hst.Template()
+
+ checkOpBehaviour(t, []opBehaviourTestCase{
+ {"invalid state", func(bool, bool) outcomeOp { return spAccountOp{} }, func() *hst.Config {
+ c := hst.Template()
+ c.Container.Shell = nil
+ return c
+ }, nil, []stub.Call{
+ // this op performs basic validation and does not make calls during toSystem
+ }, nil, nil, syscall.ENOTRECOVERABLE, nil, nil, nil, nil, nil},
+
+ {"invalid user name", func(bool, bool) outcomeOp { return spAccountOp{} }, func() *hst.Config {
+ c := hst.Template()
+ c.Container.Username = "9"
+ return c
+ }, nil, []stub.Call{
+ // this op performs basic validation and does not make calls during toSystem
+ }, nil, nil, &hst.AppError{
+ Step: "finalise",
+ Err: os.ErrInvalid,
+ Msg: `invalid user name "9"`,
+ }, nil, nil, nil, nil, nil},
+
+ {"success fallback username", func(bool, bool) outcomeOp { return spAccountOp{} }, func() *hst.Config {
+ c := hst.Template()
+ c.Container.Username = ""
+ return c
+ }, nil, []stub.Call{
+ // this op performs basic validation and does not make calls during toSystem
+ }, newI(), nil, nil, insertsOps(nil), []stub.Call{
+ // this op configures the container state and does not make calls during toContainer
+ }, &container.Params{
+ Dir: config.Container.Home,
+ Ops: new(container.Ops).
+ Place(m("/etc/passwd"), []byte("chronos:x:1000:100:Hakurei:/data/data/org.chromium.Chromium:/run/current-system/sw/bin/zsh\n")).
+ Place(m("/etc/group"), []byte("hakurei:x:100:\n")),
+ }, paramsWantEnv(config, map[string]string{
+ "HOME": config.Container.Home.String(),
+ "USER": config.Container.Username,
+ "SHELL": config.Container.Shell.String(),
+ }, nil), nil},
+
+ {"success", func(bool, bool) outcomeOp { return spAccountOp{} }, hst.Template, nil, []stub.Call{
+ // this op performs basic validation and does not make calls during toSystem
+ }, newI(), nil, nil, insertsOps(nil), []stub.Call{
+ // this op configures the container state and does not make calls during toContainer
+ }, &container.Params{
+ Dir: config.Container.Home,
+ Ops: new(container.Ops).
+ Place(m("/etc/passwd"), []byte("chronos:x:1000:100:Hakurei:/data/data/org.chromium.Chromium:/run/current-system/sw/bin/zsh\n")).
+ Place(m("/etc/group"), []byte("hakurei:x:100:\n")),
+ }, paramsWantEnv(config, map[string]string{
+ "HOME": config.Container.Home.String(),
+ "USER": config.Container.Username,
+ "SHELL": config.Container.Shell.String(),
+ }, nil), nil},
+ })
+}