sources.skip_rules_file names a JSON file of filters, each with a
comment, an active flag, a logic mode ("or" by default, or "and") and
rules by buyer, title words or CPV codes. The fetcher applies them
before saving, so only new opportunities are marked; the marks of
stored ones are never touched. CPV rules match when the opportunity's
codes are all in the list, or any of them with exclusive false, and
by prefix with exact false.
The file is read again when its time or size changes: an invalid edit
is logged and the last good rules kept, and a deleted file means no
rules until it's back. fetcher service and serve refuse to start if it
is define but missing or invalid.
job-search skip-rules check validates a rules file, and skip-rules
apply marks the stored opportunities that match Skipped, or only lists
them with --dry-run.
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", "skip-rules", "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")
|
|
}
|
|
}
|