fortify: check print behaviour
All checks were successful
Test / Create distribution (push) Successful in 1m10s
Test / Run NixOS test (push) Successful in 3m59s

These output are supposed to be deterministic, so checking them is a good way to catch regressions.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-02-14 14:44:28 +09:00
parent 1f74b636d3
commit aaebb8f3ab
3 changed files with 787 additions and 90 deletions

10
main.go
View File

@@ -13,6 +13,7 @@ import (
"sync"
"syscall"
"text/tabwriter"
"time"
"git.gensokyo.uk/security/fortify/dbus"
"git.gensokyo.uk/security/fortify/fst"
@@ -23,6 +24,7 @@ import (
"git.gensokyo.uk/security/fortify/internal/linux"
init0 "git.gensokyo.uk/security/fortify/internal/priv/init"
"git.gensokyo.uk/security/fortify/internal/priv/shim"
"git.gensokyo.uk/security/fortify/internal/state"
"git.gensokyo.uk/security/fortify/internal/system"
)
@@ -114,7 +116,7 @@ func main() {
fmt.Println(license)
fmsg.Exit(0)
case "template": // print full template configuration
printJSON(fst.Template())
printJSON(os.Stdout, false, fst.Template())
fmsg.Exit(0)
case "help": // print help message
flag.CommandLine.Usage()
@@ -127,7 +129,7 @@ func main() {
// Ignore errors; set is set for ExitOnError.
_ = set.Parse(args[1:])
printPs(short)
printPs(os.Stdout, time.Now().UTC(), state.NewMulti(sys.Paths().RunDirPath), short)
fmsg.Exit(0)
case "show": // pretty-print app info
set := flag.NewFlagSet("show", flag.ExitOnError)
@@ -139,14 +141,14 @@ func main() {
switch len(set.Args()) {
case 0: // system
printShowSystem(short)
printShowSystem(os.Stdout, short)
case 1: // instance
name := set.Args()[0]
config, instance := tryShort(name)
if config == nil {
config = tryPath(name)
}
printShowInstance(instance, config, short)
printShowInstance(os.Stdout, time.Now().UTC(), instance, config, short)
default:
fmsg.Fatal("show requires 1 argument")
}