-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag_test.go
45 lines (38 loc) · 1.11 KB
/
flag_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
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestRecoveryLevel_Set(t *testing.T) {
assertLevel := func(t *testing.T, want recoveryLevel, s string) {
t.Helper()
var got recoveryLevel
checkError(t, got.Set(s))
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("recoveryLevel.Set(%s): got %v, want %s\n%s", s, got, want, diff)
}
}
assertLevel(t, recoveryLevelLow, "low")
assertLevel(t, recoveryLevelMedium, "medium")
assertLevel(t, recoveryLevelHigh, "high")
assertLevel(t, recoveryLevelHighest, "highest")
}
func TestRecoveryLevel_String(t *testing.T) {
assertString := func(t *testing.T, want string, r recoveryLevel) {
t.Helper()
got := r.String()
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("recoveryLevel.String(): got %q, want %q\n%s", got, want, diff)
}
}
assertString(t, "low", recoveryLevelLow)
assertString(t, "medium", recoveryLevelMedium)
assertString(t, "high", recoveryLevelHigh)
assertString(t, "highest", recoveryLevelHighest)
}
func checkError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Error(err, "unexpected error")
}
}