-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
160 lines (149 loc) · 5.08 KB
/
main_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
"reflect"
"testing"
"github.com/bitrise-io/go-android/gradle"
)
func Test_androidTestVariantPairs(t *testing.T) {
tests := []struct {
name string
module string
variantsMap gradle.Variants
want gradle.Variants
wantErr bool
}{
{
name: "one AndroidTest for app module",
module: "app",
variantsMap: oneAndroidTestVariantsMap(),
want: wantOneAndroidTestForApp(),
wantErr: false,
},
{
name: "one AndroidTest for another_app module",
module: "another_app",
variantsMap: oneAndroidTestVariantsMap(),
want: wantOneAndroidTestForAnotherApp(),
wantErr: false,
},
{
name: "no AndroidTest for another_app module",
module: "another_app",
variantsMap: noAndroidTestVariantsMap(),
want: map[string][]string{},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := androidTestVariantPairs(tt.module, tt.variantsMap)
if (err != nil) != tt.wantErr {
t.Errorf("androidTestVariantPairs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("androidTestVariantPairs() = %v, want %v", got, tt.want)
}
})
}
}
func oneAndroidTestVariantsMap() gradle.Variants {
variantsMap := gradle.Variants{}
variantsMap["app"] = []string{"AndroidTest", "Debug", "Demo", "Release", "DemoDebug", "DemoDebugAndroidTest", "DemoDebugUnitTest", "DemoRelease", "DemoReleaseUnitTest"}
variantsMap["another_app"] = []string{"AndroidTest", "AnotherDemo", "Debug", "Demo", "AnotherDemoDebug", "AnotherDemoDebugAndroidTest", "AnotherDemoDebugUnitTest", "AnotherDemoRelease"}
return variantsMap
}
func noAndroidTestVariantsMap() gradle.Variants {
variantsMap := gradle.Variants{}
variantsMap["another_app"] = []string{"AndroidTest", "AnotherDemo", "Debug", "Demo", "AnotherDemoDebug", "AnotherDemoDebugUnitTest", "AnotherDemoRelease"}
return variantsMap
}
func wantOneAndroidTestForApp() gradle.Variants {
want := gradle.Variants{}
want["app"] = []string{"DemoDebug", "DemoDebugAndroidTest"}
want["another_app"] = []string{"AnotherDemoDebug", "AnotherDemoDebugAndroidTest"}
return want
}
func wantOneAndroidTestForAnotherApp() gradle.Variants {
want := gradle.Variants{}
want["app"] = []string{"DemoDebug", "DemoDebugAndroidTest"}
want["another_app"] = []string{"AnotherDemoDebug", "AnotherDemoDebugAndroidTest"}
return want
}
func Test_filterVariants(t *testing.T) {
tests := []struct {
name string
module string
variant string
variantsMap gradle.Variants
want gradle.Variants
wantErr bool
}{
{
name: "variant filter for app module",
module: "app",
variant: "DemoDebug",
variantsMap: oneAndroidTestVariantsMap(),
want: wantVariantFilterForApp(),
wantErr: false,
},
{
name: "variant filter for app module",
module: "another_app",
variant: "AnotherDemoDebug",
variantsMap: oneAndroidTestVariantsMap(),
want: wantVariantFilterForAnotherApp(),
wantErr: false,
},
{
name: "variant filter for app module",
module: "app",
variant: "DemoDebug",
variantsMap: appVariantNotFoundVariantsMap(),
want: nil,
wantErr: true,
},
{
name: "variant filter for app module",
module: "app",
variant: "DemoDebug",
variantsMap: testVariantNotFoundVariantsMap(),
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := filterVariants(tt.module, tt.variant, tt.variantsMap)
if (err != nil) != tt.wantErr {
t.Errorf("filterVariants() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("filterVariants() = %v, want %v", got, tt.want)
}
})
}
}
func appVariantNotFoundVariantsMap() gradle.Variants {
variantsMap := gradle.Variants{}
variantsMap["app"] = []string{"AndroidTest", "Debug", "Demo", "Release", "DemoDebugAndroidTest", "DemoDebugUnitTest", "DemoRelease", "DemoReleaseUnitTest"}
variantsMap["another_app"] = []string{"AndroidTest", "AnotherDemo", "Debug", "Demo", "AnotherDemoDebug", "AnotherDemoDebugAndroidTest", "AnotherDemoDebugUnitTest", "AnotherDemoRelease"}
return variantsMap
}
func testVariantNotFoundVariantsMap() gradle.Variants {
variantsMap := gradle.Variants{}
variantsMap["app"] = []string{"AndroidTest", "Debug", "Demo", "Release", "DemoDebug", "DemoDebugUnitTest", "DemoRelease", "DemoReleaseUnitTest"}
variantsMap["another_app"] = []string{"AndroidTest", "AnotherDemo", "Debug", "Demo", "AnotherDemoDebug", "AnotherDemoDebugAndroidTest", "AnotherDemoDebugUnitTest", "AnotherDemoRelease"}
return variantsMap
}
func wantVariantFilterForApp() gradle.Variants {
want := gradle.Variants{}
want["app"] = []string{"DemoDebug", "DemoDebugAndroidTest"}
return want
}
func wantVariantFilterForAnotherApp() gradle.Variants {
want := gradle.Variants{}
want["another_app"] = []string{"AnotherDemoDebug", "AnotherDemoDebugAndroidTest"}
return want
}