1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package main
import (
"bytes"
"testing"
"mm/internal/config"
"mm/internal/ui"
)
// The banner says which way yolo is set, both ways.
func TestYoloColumn(t *testing.T) {
old := config.Cfg.Yolo
t.Cleanup(func() { config.Cfg.Yolo = old })
config.Cfg.Yolo = true
if got := yoloColumn(); got != "yolo: on" {
t.Errorf("yolo on: %q", got)
}
config.Cfg.Yolo = false
if got := yoloColumn(); got != "yolo: off (tools ask)" {
t.Errorf("yolo off: %q", got)
}
}
// A start-up error goes to stderr, never to ui.Out: in `-p` mode stdout is
// the answer, and a script would read "[config error: …]" as one.
func TestStartupErrorsGoToStderr(t *testing.T) {
var stderr, out bytes.Buffer
oldErr, oldOut := errOut, ui.Out
errOut, ui.Out = &stderr, &out
t.Cleanup(func() { errOut, ui.Out = oldErr, oldOut })
fail("[config error: %v ]", "open agent.countries.yaml: no such file or directory")
if out.Len() != 0 {
t.Errorf("ui.Out got %q, want nothing", out.String())
}
if stderr.String() != "[config error: open agent.countries.yaml: no such file or directory ]\n" {
t.Errorf("stderr got %q", stderr.String())
}
}
|