-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
77 lines (70 loc) · 1.38 KB
/
config_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package vanity_test
import (
"encoding/json"
"testing"
"go.yhsif.com/vanity"
)
func TestVCS(t *testing.T) {
t.Run("unmarshal-json-empty", func(t *testing.T) {
var vcs vanity.VCS
if err := json.Unmarshal([]byte(`""`), &vcs); err != nil {
t.Fatal(err)
}
if vcs.String() != vanity.DefaultVCS.String() {
t.Errorf("Expected %q, got %q", vanity.DefaultVCS, vcs)
}
})
for _, c := range []struct {
label string
vcs vanity.VCS
str string
}{
{
label: "zero",
vcs: "",
str: "git",
},
{
label: "git",
vcs: "git",
str: "git",
},
{
label: "mod",
vcs: "mod",
str: "mod",
},
} {
t.Run(c.label, func(t *testing.T) {
var output []byte
t.Run("marshal-json", func(t *testing.T) {
var err error
output, err = json.Marshal(c.vcs)
if err != nil {
t.Error(err)
}
})
if t.Failed() {
t.FailNow()
}
t.Run("unmarshal-json-string", func(t *testing.T) {
var str string
if err := json.Unmarshal(output, &str); err != nil {
t.Fatal(err)
}
if str != c.str {
t.Errorf("Expected %q, got %q", c.str, str)
}
})
t.Run("unmarshal-json-vcs", func(t *testing.T) {
var vcs vanity.VCS
if err := json.Unmarshal(output, &vcs); err != nil {
t.Fatal(err)
}
if vcs.String() != c.vcs.String() {
t.Errorf("Expected %q, got %q", c.vcs, vcs)
}
})
})
}
}