-
Notifications
You must be signed in to change notification settings - Fork 2
/
ios_handler_test.go
156 lines (143 loc) · 3.92 KB
/
ios_handler_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_iOSHandler_isPackage(t *testing.T) {
type args struct {
filename string
}
tests := []struct {
name string
args args
want bool
}{
{"filename", args{"Info.plisT"}, true},
{"filename with path and \\", args{"c:/dev/info.plist"}, true},
{"filename with path and /", args{"c:\\dev\\info.plist"}, true},
{"filename with path", args{"c:\\dev/info.plist"}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
handler := new(iOSHandler)
if got := handler.isPackage(tt.args.filename); got != tt.want {
t.Errorf("isiOsPackage() = %v, want %v", got, tt.want)
}
})
}
}
func Test_iOSHandler_getPackageInfo(t *testing.T) {
type args struct {
filename string
}
tests := []struct {
name string
args args
want packageInfo
}{
{"normal file", args{"test/Info.plist"}, packageInfo{Version: "1.0.1", InternalVersion: "1.0.1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
handler := new(iOSHandler)
got, _ := handler.getPackageInfo(tt.args.filename)
assert.Equal(t, got.Version, tt.want.Version)
assert.Equal(t, got.InternalVersion, tt.want.InternalVersion)
})
}
}
func Test_iOSHandler_changePackageVersion(t *testing.T) {
handler := new(iOSHandler)
currentVersion, _ := handler.getPackageInfo("test/Info.plist")
handler.changePackageVersion(currentVersion, "1.0.2")
currentVersion, _ = handler.getPackageInfo("test/Info.plist")
assert.Equal(t, "1.0.2", currentVersion.Version)
assert.Equal(t, "1.0.2", currentVersion.InternalVersion)
// some kind of rollback
handler.changePackageVersion(currentVersion, "1.0.1")
}
func Test_iOSHandler_applyVersion(t *testing.T) {
type args struct {
data []byte
version string
}
tests := []struct {
name string
args args
want string
shouldError bool
}{
{"invalid bytes", args{invalidPlist, "1.0.2"}, "", true},
{"valid file", args{readFile("test/Info.plist"), "1.0.2"}, "1.0.2", false},
{"valid bytes", args{iOSSeed, "1.0.2"}, "1.0.2", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
handler := new(iOSHandler)
got, err := handler.applyVersion(tt.args.data, tt.args.version)
if tt.shouldError {
require.Error(t, err)
return
}
data, _ := handler.read(got)
require.NoError(t, err)
assert.Equal(t, tt.want, data["CFBundleVersion"])
})
}
}
func Test_iOSHandler_read(t *testing.T) {
type args struct {
data []byte
}
tests := []struct {
name string
args args
want string
shouldError bool
}{
{"invalid bytes", args{invalidPlist}, "", true},
{"missing properties", args{missingPropertiesPlist}, "", true},
{"valid file", args{readFile("test/Info.plist")}, "1.0.1", false},
{"valid bytes", args{iOSSeed}, "1.0.1", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
handler := new(iOSHandler)
got, err := handler.read(tt.args.data)
if tt.shouldError {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.want, got["CFBundleVersion"])
assert.Equal(t, tt.want, got["CFBundleShortVersionString"])
})
}
}
var iOSSeed = []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>test</string>
<key>CFBundleVersion</key>
<string>1.0.1</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
</dict>
</plist>
`)
var invalidPlist = []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<plist ve/
`)
var missingPropertiesPlist = []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
`)