forked from instructure/steps-xcode-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshots_test.go
119 lines (116 loc) · 3.29 KB
/
screenshots_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
package main
import (
"path/filepath"
"reflect"
"testing"
"time"
"github.com/bitrise-steplib/steps-xcode-test/pretty"
"github.com/bitrise-steplib/steps-xcode-test/xcodeutil/testsummaries"
)
func Test_createRenamePlan(t *testing.T) {
const attachmentDir = "/tmp/test"
const testID = "project/testSuccess()"
const activityTitle = "Start Test"
const activityUUID = "CE23D189-E75A-437D-A4B5-B97F1658FC98"
const fileName = "Screenshot of main screen (ID 1)_1_A07C26DB-8E1E-46ED-90F2-981438BE0BBA.png"
timeStamp := time.Time{}
type args struct {
testResults []testsummaries.TestResult
attachmentDir string
}
tests := []struct {
name string
args args
want map[string]string
}{
{
name: "Empty",
args: args{
testResults: []testsummaries.TestResult{
{},
},
attachmentDir: attachmentDir,
},
want: map[string]string{},
},
{
name: "Test result with screenshots",
args: args{
testResults: []testsummaries.TestResult{{
ID: testID,
Status: "Success",
FailureInfo: nil,
Activities: []testsummaries.Activity{{
Title: activityTitle,
UUID: activityUUID,
Screenshots: []testsummaries.Screenshot{{
FileName: fileName,
TimeCreated: timeStamp,
}},
}},
}},
attachmentDir: attachmentDir,
},
want: map[string]string{
filepath.Join(attachmentDir, fileName): filepath.Join(attachmentDir, "project-testSuccess()_0001-01-01_12-00-00_Start Test_CE23D189-E75A-437D-A4B5-B97F1658FC98.png"),
},
},
{
name: "Failing test result with screenshots",
args: args{
testResults: []testsummaries.TestResult{{
ID: testID,
Status: "Failure",
FailureInfo: nil,
Activities: []testsummaries.Activity{{
Title: activityTitle,
UUID: activityUUID,
Screenshots: []testsummaries.Screenshot{{
FileName: fileName,
TimeCreated: timeStamp,
}},
}},
}},
attachmentDir: attachmentDir,
},
want: map[string]string{
filepath.Join(attachmentDir, fileName): filepath.Join(attachmentDir, "Failures", "project-testSuccess()_0001-01-01_12-00-00_Start Test_CE23D189-E75A-437D-A4B5-B97F1658FC98.png"),
},
},
{
name: "Test result with subactivity screenshot",
args: args{
testResults: []testsummaries.TestResult{{
ID: testID,
Status: "Success",
FailureInfo: nil,
Activities: []testsummaries.Activity{{
Title: "Launch",
UUID: "uuid",
Screenshots: nil,
SubActivities: []testsummaries.Activity{{
Title: activityTitle,
UUID: activityUUID,
Screenshots: []testsummaries.Screenshot{{
FileName: fileName,
TimeCreated: timeStamp,
}},
SubActivities: nil,
}},
}},
}},
attachmentDir: attachmentDir,
},
want: map[string]string{
filepath.Join(attachmentDir, fileName): filepath.Join(attachmentDir, "project-testSuccess()_0001-01-01_12-00-00_Start Test_CE23D189-E75A-437D-A4B5-B97F1658FC98.png"),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := createRenamePlan(tt.args.testResults, tt.args.attachmentDir); !reflect.DeepEqual(got, tt.want) {
t.Errorf("createRenamePlan() = %v, want %v", pretty.Object(got), pretty.Object(tt.want))
}
})
}
}