55 lines
2.3 KiB
Go
55 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// With a reason, the seat passes it to the command, and a verb that only reads is not held to one.
|
|
func TestARepairByHandCarriesItsReason(t *testing.T) {
|
|
for _, c := range []struct {
|
|
verb string
|
|
args map[string]any
|
|
want string
|
|
}{
|
|
{"hand-act", map[string]any{"what": "restarted", "why": "hung", "cause": "proxy", "condition": "machine.a.silent"},
|
|
"hand-act record restarted --why hung --cause proxy --condition machine.a.silent"},
|
|
{"command", map[string]any{"command": "plans plan-1"}, "plans plan-1"},
|
|
} {
|
|
argv, err := argvFor(c.verb, c.args)
|
|
if err != nil || strings.Join(argv, " ") != c.want {
|
|
t.Errorf("%s %v: %v %v, want %q", c.verb, c.args, argv, err, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// **A drill has its own verb** — `hand-act drill`, the seat's `drill` — and `hand-act record` refuses
|
|
// the cause, so a repair cannot pass for a drill by the word it gives.
|
|
func TestADrillIsRecordedThroughItsOwnVerb(t *testing.T) {
|
|
err := handActCommand(context.Background(), []string{"record", "stopped searxng", "--why", "a test", "--cause", "drill"})
|
|
if err == nil || !strings.Contains(err.Error(), "hand-act drill") {
|
|
t.Errorf("hand-act record --cause drill was not sent to the drill verb: %v", err)
|
|
}
|
|
if err := handActCommand(context.Background(), []string{"drill", "stopped searxng"}); err == nil ||
|
|
!strings.Contains(err.Error(), "--why") {
|
|
t.Errorf("a drill without what it tests: %v", err)
|
|
}
|
|
if err := handActCommand(context.Background(), []string{"drill", "--why", "a test"}); err == nil ||
|
|
!strings.Contains(err.Error(), "hand-act drill <what") {
|
|
t.Errorf("a drill without what was done: %v", err)
|
|
}
|
|
argv, err := argvFor("drill", map[string]any{"what": "stopped searxng", "why": "ADR 0240 phase A",
|
|
"condition": "machine.ace.module.searxng.unhealthy"})
|
|
if want := "hand-act drill stopped searxng --why ADR 0240 phase A --condition machine.ace.module.searxng.unhealthy"; err != nil ||
|
|
strings.Join(argv, " ") != want {
|
|
t.Errorf("the seat's drill: %v %v, want %q", argv, err, want)
|
|
}
|
|
if _, err := argvFor("drill", map[string]any{"what": "stopped searxng"}); err == nil {
|
|
t.Error("the seat's drill without why was not refused")
|
|
}
|
|
if repairingCommand([]string{"hand-act", "drill", "x"}) != "hand-act drill" {
|
|
t.Error("a drill through `command` is not held to why")
|
|
}
|
|
}
|