aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-14 01:48:56 +0900
committerOphestra <cat@gensokyo.uk>2025-10-14 01:48:56 +0900
commit048c1957f136347826990513d198e58d049446cd (patch)
tree14953fd43820640ec8595a626934528203f15b3b
parent790d77075e40ee3162d7925e983f01747b5c2c89 (diff)
helper/args: variadic check function
This package turns out to be much less widely used than anticipated, and might be facing removal. This change makes test cases cleaner. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--helper/args.go6
-rw-r--r--helper/args_test.go4
-rw-r--r--helper/helper_test.go2
-rw-r--r--system/dbus/proxy.go2
-rw-r--r--system/dbus_test.go60
5 files changed, 37 insertions, 37 deletions
diff --git a/helper/args.go b/helper/args.go
index 88b5e691..80cd3024 100644
--- a/helper/args.go
+++ b/helper/args.go
@@ -35,7 +35,7 @@ func (a argsWt) String() string {
}
// NewCheckedArgs returns a checked null-terminated argument writer for a copy of args.
-func NewCheckedArgs(args []string) (wt io.WriterTo, err error) {
+func NewCheckedArgs(args ...string) (wt io.WriterTo, err error) {
a := make(argsWt, len(args))
for i, arg := range args {
a[i], err = syscall.ByteSliceFromString(arg)
@@ -49,8 +49,8 @@ func NewCheckedArgs(args []string) (wt io.WriterTo, err error) {
// MustNewCheckedArgs returns a checked null-terminated argument writer for a copy of args.
// If s contains a NUL byte this function panics instead of returning an error.
-func MustNewCheckedArgs(args []string) io.WriterTo {
- a, err := NewCheckedArgs(args)
+func MustNewCheckedArgs(args ...string) io.WriterTo {
+ a, err := NewCheckedArgs(args...)
if err != nil {
panic(err.Error())
}
diff --git a/helper/args_test.go b/helper/args_test.go
index 3aff8cf5..d6225c3e 100644
--- a/helper/args_test.go
+++ b/helper/args_test.go
@@ -22,7 +22,7 @@ func TestNewCheckedArgs(t *testing.T) {
t.Parallel()
args := []string{"\x00"}
- if _, err := helper.NewCheckedArgs(args); !errors.Is(err, syscall.EINVAL) {
+ if _, err := helper.NewCheckedArgs(args...); !errors.Is(err, syscall.EINVAL) {
t.Errorf("NewCheckedArgs: error = %v, wantErr %v", err, syscall.EINVAL)
}
@@ -36,6 +36,6 @@ func TestNewCheckedArgs(t *testing.T) {
t.Errorf("MustNewCheckedArgs: panic = %v, wantPanic %v", r, wantPanic)
}
}()
- helper.MustNewCheckedArgs(badPayload)
+ helper.MustNewCheckedArgs(badPayload...)
})
}
diff --git a/helper/helper_test.go b/helper/helper_test.go
index 45f7bc96..4cc36d34 100644
--- a/helper/helper_test.go
+++ b/helper/helper_test.go
@@ -27,7 +27,7 @@ var (
}
wantPayload = strings.Join(wantArgs, "\x00") + "\x00"
- argsWt = helper.MustNewCheckedArgs(wantArgs)
+ argsWt = helper.MustNewCheckedArgs(wantArgs...)
)
func argF(argsFd, statFd int) []string {
diff --git a/system/dbus/proxy.go b/system/dbus/proxy.go
index 385a8c7c..a3a60652 100644
--- a/system/dbus/proxy.go
+++ b/system/dbus/proxy.go
@@ -78,7 +78,7 @@ func Finalise(sessionBus, systemBus ProxyPair, session, system *hst.BusConfig) (
final = &Final{Session: sessionBus, System: systemBus}
- final.WriterTo, err = helper.NewCheckedArgs(args)
+ final.WriterTo, err = helper.NewCheckedArgs(args...)
if err != nil {
return
}
diff --git a/system/dbus_test.go b/system/dbus_test.go
index a346711e..5fd9f27f 100644
--- a/system/dbus_test.go
+++ b/system/dbus_test.go
@@ -181,7 +181,7 @@ func TestDBusProxyOp(t *testing.T) {
call("isVerbose", stub.ExpectArgs{}, true, nil),
call("verbose", stub.ExpectArgs{[]any{"session bus proxy:", []string{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/99dd71ee2146369514e0d10783368f8f/bus", "--filter", "--talk=session\x00"}}}, nil, nil),
call("verbose", stub.ExpectArgs{[]any{"system bus proxy:", []string{"unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/99dd71ee2146369514e0d10783368f8f/system_bus_socket", "--filter", "--talk=system\x00"}}}, nil, nil),
- call("verbose", stub.ExpectArgs{[]any{"message bus proxy final args:", helper.MustNewCheckedArgs([]string{"unique", "value", "0", "injected", "by", "the", "test", "suite"})}}, nil, nil),
+ call("verbose", stub.ExpectArgs{[]any{"message bus proxy final args:", helper.MustNewCheckedArgs("unique", "value", "0", "injected", "by", "the", "test", "suite")}}, nil, nil),
}}},
})
@@ -196,10 +196,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: false,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -208,10 +208,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, false},
@@ -222,10 +222,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1001/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -234,10 +234,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, false},
@@ -248,10 +248,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket\x00"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -260,10 +260,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, false},
@@ -274,10 +274,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1001/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -286,10 +286,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, false},
@@ -300,10 +300,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -312,10 +312,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, false},
@@ -326,10 +326,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -338,10 +338,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, false},
@@ -352,10 +352,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, &dbusProxyOp{final: &dbus.Final{
Session: dbus.ProxyPair{"unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus"},
@@ -364,10 +364,10 @@ func TestDBusProxyOp(t *testing.T) {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"unix", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{
+ WriterTo: helper.MustNewCheckedArgs(
"--filter", "unix:path=/run/user/1000/bus", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/bus",
"--filter", "unix:path=/run/dbus/system_bus_socket", "/tmp/hakurei.0/b186c281d9e83a39afdc66d964ef99c6/system_bus_socket",
- }),
+ ),
}, system: true,
}, true},
})
@@ -387,7 +387,7 @@ func dbusNewFinalSample(v int) *dbus.Final {
SessionUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/user/1000/bus"}}}},
SystemUpstream: []dbus.AddrEntry{{Method: "unix", Values: [][2]string{{"path", "/run/dbus/system_bus_socket"}}}},
- WriterTo: helper.MustNewCheckedArgs([]string{"unique", "value", strconv.Itoa(v), "injected", "by", "the", "test", "suite"}),
+ WriterTo: helper.MustNewCheckedArgs("unique", "value", strconv.Itoa(v), "injected", "by", "the", "test", "suite"),
}
}