aboutsummaryrefslogtreecommitdiffhomepage
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
parentc922c3f80e85e20a288fd390e8f4e3e0ead52849 (diff)
internal/app/dispatcher: reduce check code duplication
This also improves readability of test cases. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/app/dispatcher_test.go86
-rw-r--r--internal/app/spaccount_test.go41
-rw-r--r--internal/app/spcontainer_test.go57
-rw-r--r--internal/app/spdbus.go1
-rw-r--r--internal/app/spdbus_test.go93
5 files changed, 141 insertions, 137 deletions
diff --git a/internal/app/dispatcher_test.go b/internal/app/dispatcher_test.go
index d00170ad..2dd9c882 100644
--- a/internal/app/dispatcher_test.go
+++ b/internal/app/dispatcher_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"io/fs"
"log"
+ "maps"
"os"
"os/exec"
"reflect"
@@ -26,30 +27,97 @@ func call(name string, args stub.ExpectArgs, ret any, err error) stub.Call {
return stub.Call{Name: name, Args: args, Ret: ret, Err: err}
}
-// checkExpectUid is the uid value used by checkOpBehaviour to initialise [system.I].
-const checkExpectUid = 0xcafebabe
-
-// wantAutoEtcPrefix is the autoetc prefix corresponding to checkExpectInstanceId.
-const wantAutoEtcPrefix = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+const (
+ // checkExpectUid is the uid value used by checkOpBehaviour to initialise [system.I].
+ checkExpectUid = 0xcafebabe
+ // wantAutoEtcPrefix is the autoetc prefix corresponding to checkExpectInstanceId.
+ wantAutoEtcPrefix = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ // wantInstancePrefix is the SharePath corresponding to checkExpectInstanceId.
+ wantInstancePrefix = container.Nonexistent + "/tmp/hakurei.0/" + wantAutoEtcPrefix
+)
// checkExpectInstanceId is the [state.ID] value used by checkOpBehaviour to initialise outcomeState.
var checkExpectInstanceId = *(*state.ID)(bytes.Repeat([]byte{0xaa}, len(state.ID{})))
+type (
+ // pStateSysFunc is called before each test case is run to prepare outcomeStateSys.
+ pStateSysFunc = func(state *outcomeStateSys)
+ // pStateContainerFunc is called before each test case is run to prepare outcomeStateParams.
+ pStateContainerFunc = func(state *outcomeStateParams)
+
+ // extraCheckSysFunc is called to check outcomeStateSys and must not have side effects.
+ extraCheckSysFunc = func(t *testing.T, state *outcomeStateSys)
+ // extraCheckParamsFunc is called to check outcomeStateParams and must not have side effects.
+ extraCheckParamsFunc = func(t *testing.T, state *outcomeStateParams)
+)
+
+// insertsOps prepares outcomeStateParams to allow [container.Op] to be inserted.
+func insertsOps(next pStateContainerFunc) pStateContainerFunc {
+ return func(state *outcomeStateParams) {
+ state.params.Ops = new(container.Ops)
+
+ if next != nil {
+ next(state)
+ }
+ }
+}
+
+// afterSpRuntimeOp prepares outcomeStateParams for an outcomeOp meant to run after spRuntimeOp.
+func afterSpRuntimeOp(next pStateContainerFunc) pStateContainerFunc {
+ return func(state *outcomeStateParams) {
+ // emulates spRuntimeOp
+ state.runtimeDir = m("/run/user/1000")
+
+ if next != nil {
+ next(state)
+ }
+ }
+}
+
+// sysUsesInstance checks for use of the outcomeStateSys.instance method.
+func sysUsesInstance(next extraCheckSysFunc) extraCheckSysFunc {
+ return func(t *testing.T, state *outcomeStateSys) {
+ if want := m(wantInstancePrefix); !reflect.DeepEqual(state.sharePath, want) {
+ t.Errorf("outcomeStateSys: sharePath = %v, want %v", state.sharePath, want)
+ }
+
+ if next != nil {
+ next(t, state)
+ }
+ }
+}
+
+// paramsWantEnv checks outcomeStateParams.env for inserted entries on top of [hst.Config].
+func paramsWantEnv(config *hst.Config, wantEnv map[string]string, next extraCheckParamsFunc) extraCheckParamsFunc {
+ want := make(map[string]string, len(wantEnv)+len(config.Container.Env))
+ maps.Copy(want, wantEnv)
+ maps.Copy(want, config.Container.Env)
+ return func(t *testing.T, state *outcomeStateParams) {
+ if !maps.Equal(state.env, want) {
+ t.Errorf("toContainer: env = %#v, want %#v", state.env, want)
+ }
+
+ if next != nil {
+ next(t, state)
+ }
+ }
+}
+
type opBehaviourTestCase struct {
name string
newOp func(isShim, clearUnexported bool) outcomeOp
newConfig func() *hst.Config
- pStateSys func(state *outcomeStateSys)
+ pStateSys pStateSysFunc
toSystem []stub.Call
wantSys *system.I
- extraCheckSys func(t *testing.T, state *outcomeStateSys)
+ extraCheckSys extraCheckSysFunc
wantErrSystem error
- pStateContainer func(state *outcomeStateParams)
+ pStateContainer pStateContainerFunc
toContainer []stub.Call
wantParams *container.Params
- extraCheckParams func(t *testing.T, state *outcomeStateParams)
+ extraCheckParams extraCheckParamsFunc
wantErrContainer error
}
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},
})
}
diff --git a/internal/app/spcontainer_test.go b/internal/app/spcontainer_test.go
index 458588af..6b2354a2 100644
--- a/internal/app/spcontainer_test.go
+++ b/internal/app/spcontainer_test.go
@@ -2,7 +2,6 @@ package app
import (
"errors"
- "maps"
"os"
"reflect"
"syscall"
@@ -72,16 +71,9 @@ func TestSpParamsOp(t *testing.T) {
Proc(fhs.AbsProc).Tmpfs(hst.AbsPrivateTmp, 1<<12, 0755).
DevWritable(fhs.AbsDev, true).
Tmpfs(fhs.AbsDev.Append("shm"), 0, 01777),
+ }, paramsWantEnv(config, map[string]string{
+ "TERM": "xterm",
}, func(t *testing.T, state *outcomeStateParams) {
- wantEnv := map[string]string{
- "TERM": "xterm",
- }
- maps.Copy(wantEnv, config.Container.Env)
- if !maps.Equal(state.env, wantEnv) {
- t.Errorf("toContainer: env = %#v, want %#v", state.env, wantEnv)
- }
-
- const wantAutoEtcPrefix = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
if state.as.AutoEtcPrefix != wantAutoEtcPrefix {
t.Errorf("toContainer: as.AutoEtcPrefix = %q, want %q", state.as.AutoEtcPrefix, wantAutoEtcPrefix)
}
@@ -90,7 +82,7 @@ func TestSpParamsOp(t *testing.T) {
if !reflect.DeepEqual(state.filesystem, wantFilesystems) {
t.Errorf("toContainer: filesystem = %#v, want %#v", state.filesystem, wantFilesystems)
}
- }, nil},
+ }), nil},
{"success", func(isShim, _ bool) outcomeOp {
if !isShim {
@@ -117,15 +109,9 @@ func TestSpParamsOp(t *testing.T) {
Proc(fhs.AbsProc).Tmpfs(hst.AbsPrivateTmp, 1<<12, 0755).
Bind(fhs.AbsDev, fhs.AbsDev, bits.BindWritable|bits.BindDevice).
Tmpfs(fhs.AbsDev.Append("shm"), 0, 01777),
+ }, paramsWantEnv(config, map[string]string{
+ "TERM": "xterm",
}, func(t *testing.T, state *outcomeStateParams) {
- wantEnv := map[string]string{
- "TERM": "xterm",
- }
- maps.Copy(wantEnv, config.Container.Env)
- if !maps.Equal(state.env, wantEnv) {
- t.Errorf("toContainer: env = %#v, want %#v", state.env, wantEnv)
- }
-
if state.as.AutoEtcPrefix != wantAutoEtcPrefix {
t.Errorf("toContainer: as.AutoEtcPrefix = %q, want %q", state.as.AutoEtcPrefix, wantAutoEtcPrefix)
}
@@ -134,7 +120,7 @@ func TestSpParamsOp(t *testing.T) {
if !reflect.DeepEqual(state.filesystem, wantFilesystems) {
t.Errorf("toContainer: filesystem = %#v, want %#v", state.filesystem, wantFilesystems)
}
- }, nil},
+ }), nil},
})
}
@@ -159,6 +145,16 @@ func TestSpFilesystemOp(t *testing.T) {
}
configSmall := newConfigSmall()
+ needsApplyState := func(next pStateContainerFunc) pStateContainerFunc {
+ return func(state *outcomeStateParams) {
+ state.as = hst.ApplyState{AutoEtcPrefix: wantAutoEtcPrefix, Ops: opsAdapter{state.params.Ops}}
+
+ if next != nil {
+ next(state)
+ }
+ }
+ }
+
checkOpBehaviour(t, []opBehaviourTestCase{
{"readdir", func(bool, bool) outcomeOp {
return new(spFilesystemOp)
@@ -310,12 +306,9 @@ func TestSpFilesystemOp(t *testing.T) {
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.nixos/.ro-store"}, nePrefix+"/var/lib/hakurei/base/org.nixos/.ro-store", nil),
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.nixos/org.chromium.Chromium"}, nePrefix+"/var/lib/hakurei/base/org.nixos/org.chromium.Chromium", nil),
call("verbosef", stub.ExpectArgs{"hiding path %q from %q", []any{"/proc/nonexistent/eval/etc/dbus", "/etc/"}}, nil, nil),
- }, newI(), nil, nil, func(state *outcomeStateParams) {
- state.filesystem = configSmall.Container.Filesystem
- state.params.Ops = new(container.Ops)
- state.as = hst.ApplyState{AutoEtcPrefix: wantAutoEtcPrefix, Ops: opsAdapter{state.params.Ops}}
- state.filesystem = append(state.filesystem, hst.FilesystemConfigJSON{})
- }, []stub.Call{
+ }, newI(), nil, nil, insertsOps(needsApplyState(func(state *outcomeStateParams) {
+ state.filesystem = append(configSmall.Container.Filesystem, hst.FilesystemConfigJSON{})
+ })), []stub.Call{
// this op configures the container state and does not make calls during toContainer
}, nil, nil, &hst.AppError{
Step: "finalise",
@@ -341,11 +334,9 @@ func TestSpFilesystemOp(t *testing.T) {
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.nixos/.ro-store"}, nePrefix+"/var/lib/hakurei/base/org.nixos/.ro-store", nil),
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.nixos/org.chromium.Chromium"}, nePrefix+"/var/lib/hakurei/base/org.nixos/org.chromium.Chromium", nil),
call("verbosef", stub.ExpectArgs{"hiding path %q from %q", []any{"/proc/nonexistent/eval/etc/dbus", "/etc/"}}, nil, nil),
- }, newI(), nil, nil, func(state *outcomeStateParams) {
+ }, newI(), nil, nil, insertsOps(needsApplyState(func(state *outcomeStateParams) {
state.filesystem = configSmall.Container.Filesystem
- state.params.Ops = new(container.Ops)
- state.as = hst.ApplyState{AutoEtcPrefix: wantAutoEtcPrefix, Ops: opsAdapter{state.params.Ops}}
- }, []stub.Call{
+ })), []stub.Call{
// this op configures the container state and does not make calls during toContainer
}, &container.Params{
Ops: new(container.Ops).
@@ -386,11 +377,9 @@ func TestSpFilesystemOp(t *testing.T) {
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.debian/sys"}, nePrefix+"/var/lib/hakurei/base/org.debian/sys", nil),
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.debian/usr"}, nePrefix+"/var/lib/hakurei/base/org.debian/usr", nil),
call("evalSymlinks", stub.ExpectArgs{"/var/lib/hakurei/base/org.debian/var"}, nePrefix+"/var/lib/hakurei/base/org.debian/var", nil),
- }, newI(), nil, nil, func(state *outcomeStateParams) {
+ }, newI(), nil, nil, insertsOps(needsApplyState(func(state *outcomeStateParams) {
state.filesystem = config.Container.Filesystem[1:]
- state.params.Ops = new(container.Ops)
- state.as = hst.ApplyState{AutoEtcPrefix: wantAutoEtcPrefix, Ops: opsAdapter{state.params.Ops}}
- }, []stub.Call{
+ })), []stub.Call{
// this op configures the container state and does not make calls during toContainer
}, &container.Params{
Ops: new(container.Ops).
diff --git a/internal/app/spdbus.go b/internal/app/spdbus.go
index c2c1fefe..429674d0 100644
--- a/internal/app/spdbus.go
+++ b/internal/app/spdbus.go
@@ -12,6 +12,7 @@ import (
func init() { gob.Register(new(spDBusOp)) }
// spDBusOp maintains an xdg-dbus-proxy instance for the container.
+// Runs after spRuntimeOp.
type spDBusOp struct {
// Whether to bind the system bus socket. Populated during toSystem.
ProxySystem bool
diff --git a/internal/app/spdbus_test.go b/internal/app/spdbus_test.go
index 0adf2be3..8dcf102c 100644
--- a/internal/app/spdbus_test.go
+++ b/internal/app/spdbus_test.go
@@ -1,8 +1,6 @@
package app
import (
- "maps"
- "reflect"
"syscall"
"testing"
@@ -18,7 +16,6 @@ import (
func TestSpDBusOp(t *testing.T) {
config := hst.Template()
- const instancePrefix = container.Nonexistent + "/tmp/hakurei.0/" + wantAutoEtcPrefix
checkOpBehaviour(t, []opBehaviourTestCase{
{"not enabled", func(bool, bool) outcomeOp {
@@ -41,11 +38,7 @@ func TestSpDBusOp(t *testing.T) {
"unix:path=/run/user/1000/bus",
"unix:path=/var/run/dbus/system_bus_socket",
}, nil),
- }, nil, func(t *testing.T, state *outcomeStateSys) {
- if want := m(instancePrefix); !reflect.DeepEqual(state.sharePath, want) {
- t.Errorf("outcomeStateSys: sharePath = %v, want %v", state.sharePath, want)
- }
- }, &system.OpError{
+ }, nil, sysUsesInstance(nil), &system.OpError{
Op: "dbus",
Err: syscall.EINVAL,
Msg: "message bus proxy configuration contains NUL byte",
@@ -66,7 +59,7 @@ func TestSpDBusOp(t *testing.T) {
call("isVerbose", stub.ExpectArgs{}, true, nil),
call("verbose", stub.ExpectArgs{[]any{"session bus proxy:", []string{
"unix:path=/run/user/1000/bus",
- instancePrefix + "/bus",
+ wantInstancePrefix + "/bus",
"--filter",
"--talk=org.freedesktop.DBus",
"--talk=org.freedesktop.Notifications",
@@ -77,7 +70,7 @@ func TestSpDBusOp(t *testing.T) {
}}}, nil, nil),
call("verbose", stub.ExpectArgs{[]any{"message bus proxy final args:", helper.MustNewCheckedArgs(
"unix:path=/run/user/1000/bus",
- instancePrefix+"/bus",
+ wantInstancePrefix+"/bus",
"--filter",
"--talk=org.freedesktop.DBus",
"--talk=org.freedesktop.Notifications",
@@ -88,40 +81,25 @@ func TestSpDBusOp(t *testing.T) {
)}}, nil, nil),
}, func() *system.I {
sys := system.New(panicMsgContext{}, message.NewMsg(nil), checkExpectUid)
- sys.Ephemeral(system.Process, m(instancePrefix), 0711)
+ sys.Ephemeral(system.Process, m(wantInstancePrefix), 0711)
if err := sys.ProxyDBus(
dbus.NewConfig(config.ID, true, true), nil,
- dbus.ProxyPair{"unix:path=/run/user/1000/bus", instancePrefix + "/bus"},
- dbus.ProxyPair{"unix:path=/var/run/dbus/system_bus_socket", instancePrefix + "/system_bus_socket"},
+ dbus.ProxyPair{"unix:path=/run/user/1000/bus", wantInstancePrefix + "/bus"},
+ dbus.ProxyPair{"unix:path=/var/run/dbus/system_bus_socket", wantInstancePrefix + "/system_bus_socket"},
); err != nil {
t.Fatalf("cannot prepare sys: %v", err)
}
- sys.UpdatePerm(m(instancePrefix+"/bus"), acl.Read, acl.Write)
+ sys.UpdatePerm(m(wantInstancePrefix+"/bus"), acl.Read, acl.Write)
return sys
- }(), func(t *testing.T, state *outcomeStateSys) {
- if want := m(instancePrefix); !reflect.DeepEqual(state.sharePath, want) {
- t.Errorf("outcomeStateSys: sharePath = %v, want %v", state.sharePath, want)
- }
- }, nil, func(state *outcomeStateParams) {
- state.params.Ops = new(container.Ops)
-
- // emulates spRuntimeOp
- state.runtimeDir = m("/run/user/1000")
- }, []stub.Call{
+ }(), sysUsesInstance(nil), nil, insertsOps(afterSpRuntimeOp(nil)), []stub.Call{
// this op configures the container state and does not make calls during toContainer
}, &container.Params{
Ops: new(container.Ops).
- Bind(m(instancePrefix+"/bus"),
+ Bind(m(wantInstancePrefix+"/bus"),
m("/run/user/1000/bus"), 0),
- }, func(t *testing.T, state *outcomeStateParams) {
- wantEnv := map[string]string{
- "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
- }
- 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{
+ "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
+ }, nil), nil},
{"success", func(isShim, _ bool) outcomeOp {
if !isShim {
@@ -136,7 +114,7 @@ func TestSpDBusOp(t *testing.T) {
call("isVerbose", stub.ExpectArgs{}, true, nil),
call("verbose", stub.ExpectArgs{[]any{"session bus proxy:", []string{
"unix:path=/run/user/1000/bus",
- instancePrefix + "/bus",
+ wantInstancePrefix + "/bus",
"--filter",
"--talk=org.freedesktop.Notifications",
"--talk=org.freedesktop.FileManager1",
@@ -153,7 +131,7 @@ func TestSpDBusOp(t *testing.T) {
}}}, nil, nil),
call("verbose", stub.ExpectArgs{[]any{"system bus proxy:", []string{
"unix:path=/var/run/dbus/system_bus_socket",
- instancePrefix + "/system_bus_socket",
+ wantInstancePrefix + "/system_bus_socket",
"--filter",
"--talk=org.bluez",
"--talk=org.freedesktop.Avahi",
@@ -161,7 +139,7 @@ func TestSpDBusOp(t *testing.T) {
}}}, nil, nil),
call("verbose", stub.ExpectArgs{[]any{"message bus proxy final args:", helper.MustNewCheckedArgs(
"unix:path=/run/user/1000/bus",
- instancePrefix+"/bus",
+ wantInstancePrefix+"/bus",
"--filter",
"--talk=org.freedesktop.Notifications",
"--talk=org.freedesktop.FileManager1",
@@ -177,7 +155,7 @@ func TestSpDBusOp(t *testing.T) {
"--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*",
"unix:path=/var/run/dbus/system_bus_socket",
- instancePrefix+"/system_bus_socket",
+ wantInstancePrefix+"/system_bus_socket",
"--filter",
"--talk=org.bluez",
"--talk=org.freedesktop.Avahi",
@@ -185,43 +163,28 @@ func TestSpDBusOp(t *testing.T) {
)}}, nil, nil),
}, func() *system.I {
sys := system.New(panicMsgContext{}, message.NewMsg(nil), checkExpectUid)
- sys.Ephemeral(system.Process, m(instancePrefix), 0711)
+ sys.Ephemeral(system.Process, m(wantInstancePrefix), 0711)
if err := sys.ProxyDBus(
config.SessionBus, config.SystemBus,
- dbus.ProxyPair{"unix:path=/run/user/1000/bus", instancePrefix + "/bus"},
- dbus.ProxyPair{"unix:path=/var/run/dbus/system_bus_socket", instancePrefix + "/system_bus_socket"},
+ dbus.ProxyPair{"unix:path=/run/user/1000/bus", wantInstancePrefix + "/bus"},
+ dbus.ProxyPair{"unix:path=/var/run/dbus/system_bus_socket", wantInstancePrefix + "/system_bus_socket"},
); err != nil {
t.Fatalf("cannot prepare sys: %v", err)
}
- sys.UpdatePerm(m(instancePrefix+"/bus"), acl.Read, acl.Write).
- UpdatePerm(m(instancePrefix+"/system_bus_socket"), acl.Read, acl.Write)
+ sys.UpdatePerm(m(wantInstancePrefix+"/bus"), acl.Read, acl.Write).
+ UpdatePerm(m(wantInstancePrefix+"/system_bus_socket"), acl.Read, acl.Write)
return sys
- }(), func(t *testing.T, state *outcomeStateSys) {
- if want := m(instancePrefix); !reflect.DeepEqual(state.sharePath, want) {
- t.Errorf("outcomeStateSys: sharePath = %v, want %v", state.sharePath, want)
- }
- }, nil, func(state *outcomeStateParams) {
- state.params.Ops = new(container.Ops)
-
- // emulates spRuntimeOp
- state.runtimeDir = m("/run/user/1000")
- }, []stub.Call{
+ }(), sysUsesInstance(nil), nil, insertsOps(afterSpRuntimeOp(nil)), []stub.Call{
// this op configures the container state and does not make calls during toContainer
}, &container.Params{
Ops: new(container.Ops).
- Bind(m(instancePrefix+"/bus"),
+ Bind(m(wantInstancePrefix+"/bus"),
m("/run/user/1000/bus"), 0).
- Bind(m(instancePrefix+"/system_bus_socket"),
+ Bind(m(wantInstancePrefix+"/system_bus_socket"),
m("/var/run/dbus/system_bus_socket"), 0),
- }, func(t *testing.T, state *outcomeStateParams) {
- wantEnv := map[string]string{
- "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
- "DBUS_SYSTEM_BUS_ADDRESS": "unix:path=/var/run/dbus/system_bus_socket",
- }
- 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{
+ "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
+ "DBUS_SYSTEM_BUS_ADDRESS": "unix:path=/var/run/dbus/system_bus_socket",
+ }, nil), nil},
})
}