-
Notifications
You must be signed in to change notification settings - Fork 18
/
cocoapods_installer_test.go
184 lines (152 loc) · 7.58 KB
/
cocoapods_installer_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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package main
import (
"errors"
"strings"
"testing"
"bitrise-steplib/steps-cocoapods-install/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func Test_GivenCocoapodsInstaller_WhenArgsGiven_ThenRunsExpectedCommand(t *testing.T) {
type args struct {
podArg []string
podCmd string
verbose bool
}
tests := []struct {
name string
args args
wantCmd []string
}{
{
name: "simple pod install",
args: args{podArg: []string{"pod"}, podCmd: "install", verbose: false},
wantCmd: []string{"pod", "install", "--no-repo-update"},
},
{
name: "verbose pod install",
args: args{podArg: []string{"pod"}, podCmd: "install", verbose: true},
wantCmd: []string{"pod", "install", "--no-repo-update", "--verbose"},
},
{
name: "verbose pod update",
args: args{podArg: []string{"pod"}, podCmd: "update", verbose: true},
wantCmd: []string{"pod", "update", "--no-repo-update", "--verbose"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Given
cmd := new(mocks.Command)
cmd.On("PrintableCommandArgs").Return(strings.Join(tt.wantCmd, " "))
cmd.On("Run").Return(nil)
cmdFactory := new(mocks.CommandFactory)
cmdFactory.On("Create", tt.wantCmd[0], tt.wantCmd[1:], mock.Anything).Return(cmd)
logger := new(mocks.Logger)
logger.On("Donef", mock.Anything, mock.Anything)
installer := NewCocoapodsInstaller(cmdFactory, logger)
// When
err := installer.InstallPods(tt.args.podArg, tt.args.podCmd, "", tt.args.verbose)
// Then
require.NoError(t, err)
cmdFactory.AssertExpectations(t)
cmd.AssertExpectations(t)
})
}
}
func Test_GivenCocoapodsInstaller_WhenInstallFails_ThenRunsRepoUpdateAndRetries(t *testing.T) {
// Given
podArg := []string{"pod"}
podCmd := "install"
firstInstallCmd := new(mocks.Command)
firstInstallCmd.On("PrintableCommandArgs").Return(mock.Anything)
firstInstallCmd.On("Run").Return(errors.New("[!] Error installing boost")).Once()
repoUpdateCmd := new(mocks.Command)
repoUpdateCmd.On("PrintableCommandArgs").Return(mock.Anything)
repoUpdateCmd.On("Run").Return(nil).Once()
secondInstallCmd := new(mocks.Command)
secondInstallCmd.On("PrintableCommandArgs").Return(mock.Anything)
secondInstallCmd.On("Run").Return(nil).Once()
cmdFactory := new(mocks.CommandFactory)
cmdFactory.On("Create", podArg[0], []string{podCmd, "--no-repo-update"}, mock.Anything).Return(firstInstallCmd).Once()
cmdFactory.On("Create", podArg[0], []string{"repo", "update"}, mock.Anything).Return(repoUpdateCmd).Once()
cmdFactory.On("Create", podArg[0], []string{podCmd, "--no-repo-update"}, mock.Anything).Return(secondInstallCmd).Once()
logger := new(mocks.Logger)
logger.On("Donef", mock.Anything, mock.Anything)
logger.On("Printf", mock.Anything, mock.Anything)
logger.On("Warnf", mock.Anything, mock.Anything)
installer := NewCocoapodsInstaller(cmdFactory, logger)
// When
err := installer.InstallPods(podArg, podCmd, "", false)
// Then
require.NoError(t, err)
cmdFactory.AssertExpectations(t)
firstInstallCmd.AssertExpectations(t)
repoUpdateCmd.AssertExpectations(t)
secondInstallCmd.AssertExpectations(t)
}
func Test_GivenCocoapodsErrorFinder_WhenGatewayTimeOut_ThenFindsErrors(t *testing.T) {
expectedErrors := []string{
"[!] Error installing boost",
"[!] /usr/bin/curl -f -L -o /var/folders/v9/hjkgcpmn6bq99p7gvyhpq6800000gn/T/d20221018-7204-3bfs7/file.tbz https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2 --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.6.3'",
"Transient problem",
"curl: (22) The requested URL returned error: 504 Gateway Time-out",
}
errorFinder := cocoapodsCmdErrorFinder{}
errors := errorFinder.findErrors(podInstallGatewayTimeOutError)
require.Equal(t, expectedErrors, errors)
}
func Test_GivenCocoapodsErrorFinder_WhenBadGateway_ThenFindsErrors(t *testing.T) {
expectedErrors := []string{
"[!] Error installing boost",
"[!] /usr/bin/curl -f -L -o /var/folders/v9/hjkgcpmn6bq99p7gvyhpq6800000gn/T/d20221018-3650-smj60t/file.tbz https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2 --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.6.3'",
"Transient problem",
"curl: (22) The requested URL returned error: 502 Bad Gateway",
}
errorFinder := cocoapodsCmdErrorFinder{}
errors := errorFinder.findErrors(podInstallBadGatewayError)
require.Equal(t, expectedErrors, errors)
}
const podInstallGatewayTimeOutError = `Installing YogaKit (1.18.1)
Installing boost (1.76.0)
[!] Error installing boost
[!] /usr/bin/curl -f -L -o /var/folders/v9/hjkgcpmn6bq99p7gvyhpq6800000gn/T/d20221018-7204-3bfs7/file.tbz https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2 --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.6.3'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
Warning: Transient problem: HTTP error Will retry in 1 seconds. 2 retries
Warning: left.
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:01:15 --:--:-- 0
Warning: Transient problem: HTTP error Will retry in 2 seconds. 1 retries
Warning: left.
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:01:15 --:--:-- 0
curl: (22) The requested URL returned error: 504 Gateway Time-out
`
const podInstallBadGatewayError = `Installing YogaKit (1.18.1)
Installing boost (1.76.0)
[!] Error installing boost
[!] /usr/bin/curl -f -L -o /var/folders/v9/hjkgcpmn6bq99p7gvyhpq6800000gn/T/d20221018-3650-smj60t/file.tbz https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2 --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.6.3'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:01:05 --:--:-- 0
Warning: Transient problem: HTTP error Will retry in 1 seconds. 2 retries
Warning: left.
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:01:15 --:--:-- 0
Warning: Transient problem: HTTP error Will retry in 2 seconds. 1 retries
Warning: left.
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
curl: (22) The requested URL returned error: 502 Bad Gateway`