Files
hakurei/cmd/hakurei/command_test.go
T
cat f1dd3a085b
Test / Create distribution (push) Successful in 53s
Test / Sandbox (push) Successful in 2m51s
Test / Hakurei (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 5m53s
Test / Hakurei (race detector) (push) Successful in 7m2s
Test / ShareFS (push) Successful in 7m19s
Test / Flake checks (push) Successful in 1m8s
command: hard wrap help message flags
This greatly improves readability when lots of flags are registered.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-08-07 20:32:24 +09:00

100 lines
2.9 KiB
Go

package main
import (
"bytes"
"errors"
"flag"
"testing"
"hakurei.app/command"
"hakurei.app/message"
)
func TestHelp(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
args []string
want string
}{
{
"main", []string{}, `usage: hakurei [-h | --help] [-v] [--insecure] [--json] <command> [<args>]
commands:
run Load and start container from configuration file
exec Configure and start a permissive container
show Show live or local instance configuration
ps List active instances
version Display version information
license Show full license text
template Produce a config template
help Show this help message
`,
},
{
"exec", []string{"exec", "-h"}, `usage: hakurei exec [-h | --help] [--dbus-config <value>]
[--dbus-system <value>] [--mpris] [--dbus-log]
[--id <value>] [-a <int>] [-g <value>] [-d <value>]
[-u <value>] [--policy <value>] [--priority <int>]
[--private-runtime] [--private-tmpdir] [--wayland] [-X]
[--dbus] [--pipewire] [--pulse] <command> [<args>]
flags:
-X Enable direct connection to X11
-a int
Application identity
-d string
Container home directory (default "os")
-dbus
Enable proxied connection to D-Bus
-dbus-config string
Path to session bus proxy config file, or "builtin" for defaults (default "builtin")
-dbus-log
Force buffered logging in the D-Bus proxy
-dbus-system string
Path to system bus proxy config file, or "nil" to disable (default "nil")
-g value
Groups inherited by all container processes
-id string
Reverse-DNS style Application identifier, leave empty to inherit instance identifier
-mpris
Allow owning MPRIS D-Bus path, has no effect if custom config is available
-pipewire
Enable connection to PipeWire via SecurityContext
-policy string
Scheduling policy to set for the container
-priority int
Scheduling priority to set for the container
-private-runtime
Do not share XDG_RUNTIME_DIR between containers under the same identity
-private-tmpdir
Do not share TMPDIR between containers under the same identity
-pulse
Enable PulseAudio compatibility daemon
-u string
Passwd user name within sandbox (default "chronos")
-wayland
Enable connection to Wayland via security-context-v1
`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
out := new(bytes.Buffer)
c := buildCommand(t.Context(), message.New(nil), new(earlyHardeningErrs), out)
if err := c.Parse(tc.args); !errors.Is(err, command.ErrHelp) && !errors.Is(err, flag.ErrHelp) {
t.Errorf("Parse: error = %v; want %v",
err, command.ErrHelp)
}
if got := out.String(); got != tc.want {
t.Errorf("Parse: %s want %s", got, tc.want)
}
})
}
}