From 39346467ce203c2e3eebf0fbab687568f5e67119 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 25 Jan 2025 21:06:57 -0300 Subject: tests/fiinha.go: Add test for `commands` var --- src/fiinha.go | 14 +++++++------- tests/fiinha.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/fiinha.go b/src/fiinha.go index fe2fa6a..a20d7c7 100644 --- a/src/fiinha.go +++ b/src/fiinha.go @@ -2422,13 +2422,13 @@ func getopt( command := commandsMap[args.command] if command.name == "" { fmt.Fprintf(w, "Bad COMMAND: \"%s\".\n", args.command) - usage(allArgs[0], w) + usage(argv0, w) return argsT{}, commandT{}, 2 } args, ok := command.getopt(args, w) if !ok { - usage(allArgs[0], w) + usage(argv0, w) return argsT{}, commandT{}, 2 } @@ -2436,11 +2436,11 @@ func getopt( } func runCommand( - args argsT, + args argsT, command commandT, - stdin io.Reader, - stdout io.Writer, - stderr io.Writer, + stdin io.Reader, + stdout io.Writer, + stderr io.Writer, ) int { iqueue, err := NewWithPrefix(args.databasePath, args.prefix) if err != nil { @@ -2457,7 +2457,7 @@ func runCommand( return rc } -var commands = map[string]commandT { +var commands = map[string]commandT{ "in": commandT{ name: "in", getopt: topicGetopt, diff --git a/tests/fiinha.go b/tests/fiinha.go index b733935..b7a4cf5 100644 --- a/tests/fiinha.go +++ b/tests/fiinha.go @@ -5787,6 +5787,16 @@ func test_runCommand() { }) } +func test_commands() { + g.TestStart("commands") + + g.Testing("ensure map key and name are in sync", func() { + for key, command := range commands { + g.TAssertEqual(command.name, key) + } + }) +} + func dumpQueries() { queries := []struct{name string; fn func(string) queryT}{ @@ -5888,4 +5898,5 @@ func MainTest() { test_usage() test_getopt() test_runCommand() + test_commands() } -- cgit v1.2.3