forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgctsCloneRepository_test.go
208 lines (184 loc) · 5.13 KB
/
gctsCloneRepository_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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package cmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGctsCloneRepositorySuccess(t *testing.T) {
config := gctsCloneRepositoryOptions{
Host: "http://testHost.com:50000",
Client: "000",
Repository: "testRepo",
Username: "testUser",
Password: "testPassword",
}
t.Run("cloning successful", func(t *testing.T) {
httpClient := httpMockGcts{StatusCode: 200, ResponseBody: `{
"result": {
"rid": "my-repository",
"checkoutTime": 20180606130524,
"fromCommit": "f1cdb6a032c1d8187c0990b51e94e8d8bb9898b2",
"toCommit": "f1cdb6a032c1d8187c0990b51e94e8d8bb9898b2",
"caller": "JOHNDOE",
"request": "SIDK1234567",
"type": "PULL"
},
"log": [
{
"time": 20180606130524,
"user": "JENKINS",
"section": "REPOSITORY_FACTORY",
"action": "CREATE_REPOSITORY",
"severity": "INFO",
"message": "Start action CREATE_REPOSITORY review",
"code": "GCTS.API.410"
}
]
}`}
err := cloneRepository(&config, nil, &httpClient)
if assert.NoError(t, err) {
t.Run("check url", func(t *testing.T) {
assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/clone?sap-client=000", httpClient.URL)
})
t.Run("check method", func(t *testing.T) {
assert.Equal(t, "POST", httpClient.Method)
})
t.Run("check user", func(t *testing.T) {
assert.Equal(t, "testUser", httpClient.Options.Username)
})
t.Run("check password", func(t *testing.T) {
assert.Equal(t, "testPassword", httpClient.Options.Password)
})
}
})
t.Run("repository has already been cloned", func(t *testing.T) {
httpClient := httpMockGcts{StatusCode: 500, ResponseBody: `{
"errorLog": [
{
"time": 20200414112900,
"user": "USER",
"section": "CLIENT_TP",
"action": "GET_SOURCE_FROM_REMOTE",
"severity": "ERROR",
"message": "20200414112900: Error action GET_SOURCE_FROM_REMOTE",
"protocol": [
{
"type": "Paramters",
"protocol": [
{
"repouri": "https://github.com/test-repo",
"logfile": "/usr/sap/SID/D00/gcts/repos/gcts/repo-name/log/20200414_112900_AD0F43952A5A3F47133637329BA760D8.log",
"repodir": "/usr/sap/SID/D00/gcts/repos/gcts/repo-name/data/",
"loglevel": "warning",
"command": "clone"
}
]
},
{
"type": "Client Log",
"protocol": [
"protocol logs"
]
},
{
"type": "Client Stack Log",
"protocol": [
{
"client stack log key": "client stack log value",
"stack": [
"java",
"stack"
]
}
]
}
]
},
{
"severity": "ERROR",
"message": "Cloning a repository into a new working directory failed: Destination path 'data' already exists and is not an empty directory",
"code": "GCTS.CLIENT.1420"
},
{
"time": 20200414112900,
"user": "USER",
"section": "REPOSITORY",
"action": "CLONE",
"severity": "ERROR",
"message": "20200414112900: Error action CLONE 20200414_112900_AD0F43952A5A3F47133637329BA760D8"
}
]
}`}
err := cloneRepository(&config, nil, &httpClient)
assert.NoError(t, err)
})
}
func TestGctsCloneRepositoryFailure(t *testing.T) {
config := gctsCloneRepositoryOptions{
Host: "http://testHost.com:50000",
Client: "000",
Repository: "testRepo",
Username: "testUser",
Password: "testPassword",
}
t.Run("a http error occurred", func(t *testing.T) {
httpClient := httpMockGcts{StatusCode: 500, ResponseBody: `{
"errorLog": [
{
"time": 20200414112900,
"user": "USER",
"section": "CLIENT_TP",
"action": "GET_SOURCE_FROM_REMOTE",
"severity": "ERROR",
"message": "20200414112900: Error action GET_SOURCE_FROM_REMOTE",
"protocol": [
{
"type": "Paramters",
"protocol": [
{
"repouri": "https://github.com/test-repo",
"logfile": "/usr/sap/SID/D00/gcts/repos/gcts/repo-name/log/20200414_112900_AD0F43952A5A3F47133637329BA760D8.log",
"repodir": "/usr/sap/SID/D00/gcts/repos/gcts/repo-name/data/",
"loglevel": "warning",
"command": "clone"
}
]
},
{
"type": "Client Log",
"protocol": [
"protocol logs"
]
},
{
"type": "Client Stack Log",
"protocol": [
{
"client stack log key": "client stack log value",
"stack": [
"java",
"stack"
]
}
]
}
]
},
{
"severity": "ERROR",
"message": "Cloning a repository into a new working directory failed: Destination path 'data' already exists and is not an empty directory",
"code": "GCTS.CLIENT.9999"
},
{
"time": 20200414112900,
"user": "USER",
"section": "REPOSITORY",
"action": "CLONE",
"severity": "ERROR",
"message": "20200414112900: Error action CLONE 20200414_112900_AD0F43952A5A3F47133637329BA760D8"
}
]
}`}
err := cloneRepository(&config, nil, &httpClient)
assert.EqualError(t, err, "cloning the repository failed: a http error occurred")
})
}