forked from bitrise-steplib/steps-gradle-runner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
99 lines (87 loc) · 2.97 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
package main
import (
"io/ioutil"
"testing"
)
func loadFileContent(filePth string) (string, error) {
fileBytes, err := ioutil.ReadFile(filePth)
if err != nil {
return "", err
}
return string(fileBytes), nil
}
func testIsFoundWith(t *testing.T, searchPattern, outputToSearchIn string, isShouldFind bool) {
if isFound := isStringFoundInOutput(searchPattern, outputToSearchIn); isFound != isShouldFind {
t.Logf("Search pattern was: %s", searchPattern)
t.Logf("Input string to search in was: %s", outputToSearchIn)
t.Fatalf("Expected (%v), actual (%v)", isShouldFind, isFound)
}
}
func testIsFoundWithFailedToFindTargetWithHashString(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, failedToFindTargetWithHashString, outputToSearchIn, isShouldFind)
}
func testIsFoundWithFailedToFindBuildToolRevision(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, failedToFindBuildToolRevision, outputToSearchIn, isShouldFind)
}
func TestIsStringFoundInOutput_failedToFindTargetWithHashString(t *testing.T) {
failedToFindTargetWithHashStringLog, err := loadFileContent("./_samples/failedToFindTargetWithHashString.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/successfullBuild.txt")
if err != nil {
t.Fatalf("Failed to load successfullBuild.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"Caused by: java.lang.IllegalStateException: failed to find target with hash string 'android-22' in:",
"> failed to find target with hash string 'android-22' in:",
failedToFindTargetWithHashStringLog,
} {
testIsFoundWithFailedToFindTargetWithHashString(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"target with hash string",
"Caused by: java.lang.IllegalStateException:",
sampleOKBuildLog,
} {
testIsFoundWithFailedToFindTargetWithHashString(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_failedToFindBuildToolRevision(t *testing.T) {
failedToFindBuildToolRevisionLog, err := loadFileContent("./_samples/failedToFindBuildToolRevision.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/successfullBuild.txt")
if err != nil {
t.Fatalf("Failed to load successfullBuild.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"Caused by: java.lang.IllegalStateException: failed to find Build Tools revision 22.0.1",
"> failed to find Build Tools revision 22.0.1",
failedToFindBuildToolRevisionLog,
} {
testIsFoundWithFailedToFindBuildToolRevision(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"Build Tools revision 22.0.1",
"Caused by: java.lang.IllegalStateException:",
sampleOKBuildLog,
} {
testIsFoundWithFailedToFindBuildToolRevision(t, anOutStr, false)
}
}
}