-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathcats_suite_helpers.go
441 lines (389 loc) · 10.8 KB
/
cats_suite_helpers.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
package cats_suite_helpers
import (
"fmt"
"net"
"regexp"
"strings"
"time"
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/config"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/skip_messages"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
"github.com/cloudfoundry/cf-test-helpers/v2/workflowhelpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
const (
CF_JAVA_TIMEOUT = 10 * time.Minute
V3_PROCESS_TIMEOUT = 45 * time.Second
DEFAULT_MEMORY_LIMIT = "256M"
DEFAULT_WINDOWS_MEMORY_LIMIT = "1G"
)
var (
Config CatsConfig
TestSetup *workflowhelpers.ReproducibleTestSuiteSetup
ScpPath string
SftpPath string
)
func AppSyslogTcpDescribe(description string, callback func()) bool {
return Describe("[app_syslog_tcp]", func() {
BeforeEach(func() {
if !Config.GetIncludeAppSyslogTcp() {
Skip(skip_messages.SkipAppSyslogTcpMessage)
}
})
Describe(description, callback)
})
}
func AppsDescribe(description string, callback func()) bool {
return Describe("[apps]", func() {
BeforeEach(func() {
if !Config.GetIncludeApps() {
Skip(skip_messages.SkipAppsMessage)
}
})
Describe(description, callback)
})
}
func IsolatedTCPRoutingDescribe(description string, callback func()) bool {
return Describe("[isolated tcp routing]", func() {
BeforeEach(func() {
if Config.GetIncludeRoutingIsolationSegments() || !Config.GetIncludeTCPIsolationSegments() {
Skip(skip_messages.SkipIsolatedTCPRoutingMessage)
}
})
Describe(description, callback)
})
}
func IsolationSegmentsDescribe(description string, callback func()) bool {
return Describe("[isolation_segments]", func() {
BeforeEach(func() {
if !Config.GetIncludeIsolationSegments() {
Skip(skip_messages.SkipIsolationSegmentsMessage)
}
})
Describe(description, callback)
})
}
func DetectDescribe(description string, callback func()) bool {
return Describe("[detect]", func() {
BeforeEach(func() {
if !Config.GetIncludeDetect() {
Skip(skip_messages.SkipDetectMessage)
}
})
Describe(description, callback)
})
}
func DockerDescribe(description string, callback func()) bool {
return Describe("[docker]", func() {
BeforeEach(func() {
if !Config.GetIncludeDocker() {
Skip(skip_messages.SkipDockerMessage)
}
})
Describe(description, callback)
})
}
func InternetDependentDescribe(description string, callback func()) bool {
return Describe("[internet_dependent]", func() {
BeforeEach(func() {
if !Config.GetIncludeInternetDependent() {
Skip(skip_messages.SkipInternetDependentMessage)
}
})
Describe(description, callback)
})
}
func RouteServicesDescribe(description string, callback func()) bool {
return Describe("[route_services]", func() {
BeforeEach(func() {
if !Config.GetIncludeRouteServices() {
Skip(skip_messages.SkipRouteServicesMessage)
}
})
Describe(description, callback)
})
}
func RoutingDescribe(description string, callback func()) bool {
return Describe("[routing]", func() {
BeforeEach(func() {
if !Config.GetIncludeRouting() {
Skip(skip_messages.SkipRoutingMessage)
}
})
Describe(description, callback)
})
}
func HTTP2RoutingDescribe(description string, callback func()) bool {
return Describe("[HTTP/2 routing]", func() {
BeforeEach(func() {
if !Config.GetIncludeHTTP2Routing() {
Skip(skip_messages.SkipHTTP2RoutingMessage)
}
})
Describe(description, callback)
})
}
func TCPRoutingDescribe(description string, callback func()) bool {
return Describe("[tcp routing]", func() {
BeforeEach(func() {
if !Config.GetIncludeTCPRouting() {
Skip(skip_messages.SkipTCPRoutingMessage)
}
})
Describe(description, callback)
})
}
func RoutingIsolationSegmentsDescribe(description string, callback func()) bool {
return Describe("[routing_isolation_segments]", func() {
BeforeEach(func() {
if !Config.GetIncludeRoutingIsolationSegments() {
Skip(skip_messages.SkipRoutingIsolationSegmentsMessage)
}
})
Describe(description, callback)
})
}
func ZipkinDescribe(description string, callback func()) bool {
return Describe("[routing]", func() {
BeforeEach(func() {
if !Config.GetIncludeRouting() {
Skip(skip_messages.SkipRoutingMessage)
}
if !Config.GetIncludeZipkin() {
Skip(skip_messages.SkipZipkinMessage)
}
})
Describe(description, callback)
})
}
func SecurityGroupsDescribe(description string, callback func()) bool {
return Describe("[security_groups]", func() {
BeforeEach(func() {
if !Config.GetIncludeSecurityGroups() {
Skip(skip_messages.SkipSecurityGroupsMessage)
}
})
Describe(description, callback)
})
}
func CommaDelimitedSecurityGroupsDescribe(description string, callback func()) bool {
return Describe("[comma_delimited_security_groups]", func() {
BeforeEach(func() {
if !Config.GetCommaDelimitedASGsEnabled() {
Skip(skip_messages.SkipCommaDelimitedSecurityGroupsMessage)
}
})
Describe(description, callback)
})
}
func ServiceDiscoveryDescribe(description string, callback func()) bool {
return Describe("[service discovery]", func() {
BeforeEach(func() {
if !Config.GetIncludeServiceDiscovery() {
Skip(skip_messages.SkipServiceDiscoveryMessage)
}
})
Describe(description, callback)
})
}
func ServicesDescribe(description string, callback func()) bool {
return Describe("[services]", func() {
BeforeEach(func() {
if !Config.GetIncludeServices() {
Skip(skip_messages.SkipServicesMessage)
}
})
Describe(description, callback)
})
}
func ServiceInstanceSharingDescribe(description string, callback func()) bool {
return Describe("[service instance sharing]", func() {
BeforeEach(func() {
if !Config.GetIncludeServiceInstanceSharing() {
Skip(skip_messages.SkipServiceInstanceSharingMessage)
}
})
Describe(description, callback)
})
}
func UserProvidedServicesDescribe(description string, callback func()) bool {
return Describe("[user provided services]", func() {
BeforeEach(func() {
if !Config.GetIncludeUserProvidedServices() {
Skip(skip_messages.SkipUserProvidedServicesMessage)
}
})
Describe(description, callback)
})
}
func SshDescribe(description string, callback func()) bool {
return Describe("[ssh]", func() {
BeforeEach(func() {
if !Config.GetIncludeSsh() {
Skip(skip_messages.SkipSSHMessage)
}
})
Describe(description, callback)
})
}
func V3Describe(description string, callback func()) bool {
return Describe("[v3]", func() {
BeforeEach(func() {
if !Config.GetIncludeV3() {
Skip(skip_messages.SkipV3Message)
}
})
Describe(description, callback)
})
}
func TasksDescribe(description string, callback func()) bool {
return Describe("[tasks]", func() {
BeforeEach(func() {
if !Config.GetIncludeTasks() {
Skip(skip_messages.SkipTasksMessage)
}
})
Describe(description, callback)
})
}
func GuidForAppName(appName string) string {
cfApp := cf.Cf("app", appName, "--guid")
Expect(cfApp.Wait()).To(Exit(0))
appGuid := strings.TrimSpace(string(cfApp.Out.Contents()))
Expect(appGuid).NotTo(Equal(""))
return appGuid
}
func CredhubDescribe(description string, callback func()) bool {
return Describe("[credhub]", func() {
BeforeEach(func() {
if !(Config.GetIncludeCredhubAssisted() || Config.GetIncludeCredhubNonAssisted()) {
Skip(skip_messages.SkipCredhubMessage)
}
})
Describe(description, callback)
})
}
func AssistedCredhubDescribe(description string, callback func()) bool {
return Describe("[assisted credhub]", func() {
BeforeEach(func() {
if !Config.GetIncludeCredhubAssisted() {
Skip(skip_messages.SkipAssistedCredhubMessage)
}
})
Describe(description, callback)
})
}
func NonAssistedCredhubDescribe(description string, callback func()) bool {
return Describe("[non-assisted credhub]", func() {
BeforeEach(func() {
if !Config.GetIncludeCredhubNonAssisted() {
Skip(skip_messages.SkipNonAssistedCredhubMessage)
}
})
Describe(description, callback)
})
}
func WindowsCredhubDescribe(description string, callback func()) bool {
return Describe("[windows credhub]", func() {
BeforeEach(func() {
if !Config.GetIncludeWindows() {
Skip(skip_messages.SkipWindowsMessage)
}
if !(Config.GetIncludeCredhubAssisted() || Config.GetIncludeCredhubNonAssisted()) {
Skip(skip_messages.SkipCredhubMessage)
}
})
Describe(description, callback)
})
}
func WindowsAssistedCredhubDescribe(description string, callback func()) bool {
return Describe("[windows assisted credhub]", func() {
BeforeEach(func() {
if !Config.GetIncludeCredhubAssisted() {
Skip(skip_messages.SkipAssistedCredhubMessage)
}
})
Describe(description, callback)
})
}
func WindowsNonAssistedCredhubDescribe(description string, callback func()) bool {
return Describe("[windows non-assisted credhub]", func() {
BeforeEach(func() {
if !Config.GetIncludeCredhubNonAssisted() {
Skip(skip_messages.SkipNonAssistedCredhubMessage)
}
})
Describe(description, callback)
})
}
func WindowsDescribe(description string, callback func()) bool {
return Describe("[windows]", func() {
BeforeEach(func() {
if !Config.GetIncludeWindows() {
Skip(skip_messages.SkipWindowsMessage)
}
})
Describe(description, callback)
})
}
func VolumeServicesDescribe(description string, callback func()) bool {
return Describe("[volume_services]", func() {
BeforeEach(func() {
if !Config.GetIncludeVolumeServices() {
Skip(skip_messages.SkipVolumeServicesMessage)
}
if Config.GetIncludeDocker() {
Skip(skip_messages.SkipVolumeServicesDockerEnabledMessage)
}
})
Describe(description, callback)
})
}
func GetNServerResponses(n int, domainName, externalPort1 string) ([]string, error) {
var responses []string
for i := 0; i < n; i++ {
resp, err := SendAndReceive(domainName, externalPort1)
if err != nil {
return nil, err
}
responses = append(responses, resp)
}
return responses, nil
}
func MapTCPRoute(appName, domainName string) string {
createRouteSession := cf.Cf("map-route", appName, domainName).Wait()
Expect(createRouteSession).To(Exit(0))
r := regexp.MustCompile(fmt.Sprintf(`.+%s:(\d+).+`, domainName))
return r.FindStringSubmatch(string(createRouteSession.Out.Contents()))[1]
}
func SendAndReceive(addr string, externalPort string) (string, error) {
address := fmt.Sprintf("%s:%s", addr, externalPort)
conn, err := net.Dial("tcp", address)
if err != nil {
return "", err
}
defer conn.Close()
message := []byte(fmt.Sprintf("Time is %d", time.Now().Nanosecond()))
_, err = conn.Write(message)
if err != nil {
if ne, ok := err.(*net.OpError); ok {
if ne.Temporary() {
return SendAndReceive(addr, externalPort)
}
}
return "", err
}
buff := make([]byte, 1024)
_, err = conn.Read(buff)
if err != nil {
if ne, ok := err.(*net.OpError); ok {
if ne.Temporary() {
return SendAndReceive(addr, externalPort)
}
}
return "", err
}
return string(buff), nil
}