-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_test.go
100 lines (93 loc) · 2.35 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
package main
import (
"testing"
"github.com/artemnikitin/devicefarm-ci-tool/model"
"github.com/artemnikitin/devicefarm-ci-tool/service"
)
func TestRunJob(t *testing.T) {
cases := []struct {
name string
project string
file string
config *model.RunConfig
failed []*model.FailedTest
pass bool
partlyUnavailable bool
fullyUnavailable bool
}{
{
name: "Success run",
project: "test",
file: "main_test.go",
config: &model.RunConfig{},
failed: []*model.FailedTest{},
pass: true,
},
{
name: "Run with failed tests",
project: "test",
file: "main_test.go",
config: &model.RunConfig{},
failed: []*model.FailedTest{{}, {}},
pass: false,
},
{
name: "Run with failed job because of infrastructure issues",
project: "test",
file: "main_test.go",
config: &model.RunConfig{
Name: "AWSFail",
},
failed: []*model.FailedTest{},
pass: false,
},
{
name: "Run with some devices as unavailable",
project: "test",
file: "main_test.go",
config: &model.RunConfig{},
failed: []*model.FailedTest{},
pass: true,
partlyUnavailable: true,
},
{
name: "Run with all devices as unavailable",
project: "test",
file: "main_test.go",
config: &model.RunConfig{
Name: "AWSFail",
},
failed: []*model.FailedTest{},
pass: false,
fullyUnavailable: true,
},
}
for _, v := range cases {
t.Run(v.name, func(t *testing.T) {
client := &service.MockClient{}
if v.config.Name == "AWSFail" {
client.AWSFail = true
}
if v.partlyUnavailable {
client.PartlyUnavailableDevice = true
}
if v.fullyUnavailable {
client.FullUnavailableDevices = true
}
client.FakeServer = service.CreateFakeServer()
defer client.FakeServer.Close()
*project = v.project
*appPath = v.file
*wait = true
client.Failed = !v.pass
client.UploadTest = true
failed, pass := runJob(client, v.config)
if pass != v.pass {
t.Errorf("Test: %s\nTest result expected: %t, actual: %t", v.name, v.pass, pass)
}
if len(failed) != len(v.failed) {
t.Errorf("Test: %s\nNumber of failed tests expected: %d, actual: %d", v.name, len(v.failed), len(failed))
}
})
}
}