aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/spaccount_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-17 05:32:14 +0900
committerOphestra <cat@gensokyo.uk>2025-10-17 05:47:12 +0900
commit3f391329357789f55559404a3d28c60679111a74 (patch)
treeae47e5b53764853d21c8a49c1c8212932593e0e8 /internal/app/spaccount_test.go
parentc922c3f80e85e20a288fd390e8f4e3e0ead52849 (diff)
internal/app/dispatcher: reduce check code duplication
This also improves readability of test cases. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/spaccount_test.go')
-rw-r--r--internal/app/spaccount_test.go41
1 files changed, 12 insertions, 29 deletions
diff --git a/internal/app/spaccount_test.go b/internal/app/spaccount_test.go
index 7ebda46f..c5fb7b5b 100644
--- a/internal/app/spaccount_test.go
+++ b/internal/app/spaccount_test.go
@@ -1,7 +1,6 @@
package app
import (
- "maps"
"os"
"syscall"
"testing"
@@ -42,48 +41,32 @@ func TestSpAccountOp(t *testing.T) {
return c
}, nil, []stub.Call{
// this op performs basic validation and does not make calls during toSystem
- }, newI(), nil, nil, func(state *outcomeStateParams) {
- state.params.Ops = new(container.Ops)
- }, []stub.Call{
+ }, 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")),
- }, func(t *testing.T, state *outcomeStateParams) {
- wantEnv := map[string]string{
- "HOME": config.Container.Home.String(),
- "USER": config.Container.Username,
- "SHELL": config.Container.Shell.String(),
- }
- maps.Copy(wantEnv, config.Container.Env)
- if !maps.Equal(state.env, wantEnv) {
- t.Errorf("toContainer: env = %#v, want %#v", state.env, wantEnv)
- }
- }, nil},
+ }, 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, func(state *outcomeStateParams) {
- state.params.Ops = new(container.Ops)
- }, []stub.Call{
+ }, 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")),
- }, func(t *testing.T, state *outcomeStateParams) {
- wantEnv := map[string]string{
- "HOME": config.Container.Home.String(),
- "USER": config.Container.Username,
- "SHELL": config.Container.Shell.String(),
- }
- maps.Copy(wantEnv, config.Container.Env)
- if !maps.Equal(state.env, wantEnv) {
- t.Errorf("toContainer: env = %#v, want %#v", state.env, wantEnv)
- }
- }, nil},
+ }, paramsWantEnv(config, map[string]string{
+ "HOME": config.Container.Home.String(),
+ "USER": config.Container.Username,
+ "SHELL": config.Container.Shell.String(),
+ }, nil), nil},
})
}