-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils_test.go
51 lines (42 loc) · 1.12 KB
/
utils_test.go
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
43
44
45
46
47
48
49
50
51
package main
import (
"errors"
"testing"
)
func TestIsRecoverable(t *testing.T) {
if msg := "broken pipes all over"; isRecoverable(errors.New(msg)) {
t.Errorf("Expected %s to NOT be recoverable", msg)
}
if msg := "Oh noes, I broken pipe"; !isRecoverable(errors.New(msg)) {
t.Errorf("Expected %s to BE recoverable", msg)
}
}
func TestMsg(t *testing.T) {
actual := msg()
if expected := ""; actual != expected {
t.Error("Expected a blank message, got", actual)
}
verbose := opts.verbose
opts.verbose = true
if actual := msg("Foo", "bar", "baz"); actual != "Foo\n" {
t.Error("Expected Foo\\n got", actual)
}
quiet := opts.quiet
opts.quiet = true
opts.verbose = false
if actual := msg("Foo", "bar", "baz"); actual != "baz" {
t.Error("Expected baz got", actual)
}
if actual := msg(); actual != "" {
t.Error("Expected message to be blank, got", actual)
}
opts.quiet = false
if actual := msg("Foo", "bar", "baz"); actual != "bar" {
t.Error("Expected bar got", actual)
}
if actual := msg("Foo"); actual != "" {
t.Error("Expected blank message got", actual)
}
opts.verbose = verbose
opts.quiet = quiet
}