-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_computer_test.go
110 lines (103 loc) · 2.39 KB
/
config_computer_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package core_test
import (
"errors"
"testing"
differ "github.com/andreyvit/diff"
"github.com/google/go-cmp/cmp"
"github.com/yoanm/go-github-tf/core"
)
func TestComputeConfig(t *testing.T) {
t.Parallel()
aName := "a_name"
cases := map[string]struct {
value *core.Config
expected *core.Config
error error
}{
"nil": {
nil,
nil,
nil,
},
"empty": {
&core.Config{Templates: nil, Repos: nil},
core.NewConfig(),
nil,
},
"base": {
&core.Config{
Templates: nil,
Repos: []*core.GhRepoConfig{
{
&aName, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
},
},
},
&core.Config{
Templates: &core.TemplatesConfig{
Repos: map[string]*core.GhRepoConfig{},
Branches: map[string]*core.GhBranchConfig{},
BranchProtections: map[string]*core.GhBranchProtectionConfig{},
},
Repos: []*core.GhRepoConfig{
{
&aName, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
},
},
},
nil,
},
"Repo without name": {
&core.Config{
Templates: nil,
Repos: []*core.GhRepoConfig{
{
nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
},
{
nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
},
},
},
nil,
errors.New("error during computation:\n\t - repo #0: repository name is mandatory\n\t - repo #1: repository name is mandatory"),
},
"Underlying computation error": {
&core.Config{
Templates: nil,
Repos: []*core.GhRepoConfig{
{
&aName, &[]string{aName}, nil, nil, nil, nil,
nil, nil, nil, nil, nil,
},
},
},
nil,
errors.New("error during computation:\n\t - repository a_name: repository template not found as none available"),
},
}
for tcname, tc := range cases {
t.Run(
tcname,
func(t *testing.T) {
t.Parallel()
actual, err := core.ComputeConfig(tc.value)
if tc.error != nil {
if err == nil {
t.Errorf("Case %q: expected an error but everything went well", tcname)
} else if err.Error() != tc.error.Error() {
t.Errorf("Case %q:\n- expected\n+ actual\n\n%v", tcname, differ.LineDiff(tc.error.Error(), err.Error()))
}
} else if err != nil {
t.Errorf("Case %q: %s", tcname, err)
} else if diff := cmp.Diff(tc.expected, actual); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
}
},
)
}
}