job-search no longer has a fetch command. Its subcommands are now in cmd/fetcher, which reads the same configuration: "fetcher service" runs every enabled source's fetcher on its interval until stopped, and "fetcher fts-once" (was "fetch once") fetches from Find a Tender once and prints the releases as JSON. The new namea say what the commands do, because service runs every source while fts-once fetches only from Find a Tender. The code stays in internal/cli/fetch, where NewCommands replaces the fetch parent command. once.go is now fts_once.go and commandOnce is commandFTSOnce. The README's usage, the config README and the find_a_tender api_root comment now give the new command names.
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/cli/cmdtest"
|
|
)
|
|
|
|
// The commands are tested in their own packages under internal/cli. These
|
|
// tests check newRootCmd puts them together.
|
|
|
|
func TestCommandTree(t *testing.T) {
|
|
root := newRootCmd()
|
|
|
|
var names []string
|
|
for _, c := range root.Commands() {
|
|
names = append(names, c.Name())
|
|
}
|
|
|
|
commands := []string{"config", "migrate", "serve", "version"}
|
|
for _, want := range commands {
|
|
if !slices.Contains(names, want) {
|
|
t.Errorf("job-search has no %q command; has %v", want, names)
|
|
}
|
|
}
|
|
|
|
for _, flag := range []string{"config", "debug", "quiet"} {
|
|
if root.PersistentFlags().Lookup(flag) == nil {
|
|
t.Errorf("job-search has no --%s flag", flag)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestVersion(t *testing.T) {
|
|
cmdtest.Setup(t, "")
|
|
cmdtest.Contains(t, cmdtest.MustRun(t, newRootCmd, "version"), "JobSearch - ")
|
|
}
|
|
|
|
// A command that loads the configuration runs through the real root: its
|
|
// flags and hooks, and the subcommand beneath it.
|
|
func TestRootRunsCommands(t *testing.T) {
|
|
cmdtest.Setup(t, "logging:\n level: info\n")
|
|
cmdtest.Contains(
|
|
t,
|
|
cmdtest.MustRun(t, newRootCmd, "config", "get", "logging.level"),
|
|
"info <string>",
|
|
)
|
|
cmdtest.Contains(
|
|
t,
|
|
cmdtest.MustRun(t, newRootCmd, "config", "get", "logging.level", "--debug"),
|
|
"debug <string>",
|
|
)
|
|
}
|
|
|
|
func TestUnknownCommand(t *testing.T) {
|
|
cmdtest.Setup(t, "")
|
|
if _, err := cmdtest.Run(t, newRootCmd, "", "nope"); err == nil {
|
|
t.Error("an unknown command was accepted")
|
|
}
|
|
}
|