@@ -29,6 +29,7 @@ import (
29
29
"time"
30
30
31
31
"github.com/ghodss/yaml"
32
+ "github.com/operator-framework/operator-sdk/internal/util/fileutil"
32
33
"github.com/operator-framework/operator-sdk/internal/util/projutil"
33
34
framework "github.com/operator-framework/operator-sdk/pkg/test"
34
35
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
@@ -41,9 +42,11 @@ import (
41
42
)
42
43
43
44
const (
44
- filemode os.FileMode = 0664
45
- dirmode os.FileMode = 0750
46
- crYAML string = "apiVersion: \" cache.example.com/v1alpha1\" \n kind: \" Memcached\" \n metadata:\n name: \" example-memcached\" \n spec:\n size: 3"
45
+ crYAML string = "apiVersion: \" cache.example.com/v1alpha1\" \n kind: \" Memcached\" \n metadata:\n name: \" example-memcached\" \n spec:\n size: 3"
46
+ retryInterval = time .Second * 5
47
+ timeout = time .Second * 60
48
+ cleanupRetryInterval = time .Second * 1
49
+ cleanupTimeout = time .Second * 10
47
50
)
48
51
49
52
func TestMemcached (t * testing.T ) {
@@ -64,7 +67,7 @@ func TestMemcached(t *testing.T) {
64
67
65
68
// Setup
66
69
absProjectPath := filepath .Join (gopath , "src/github.com/example-inc" )
67
- if err := os .MkdirAll (absProjectPath , dirmode ); err != nil {
70
+ if err := os .MkdirAll (absProjectPath , fileutil . DefaultDirFileMode ); err != nil {
68
71
t .Fatal (err )
69
72
}
70
73
if err := os .Chdir (absProjectPath ); err != nil {
@@ -108,7 +111,7 @@ func TestMemcached(t *testing.T) {
108
111
gopkgString := string (gopkg )
109
112
gopkgLoc := strings .LastIndex (gopkgString , "\n name = \" github.com/operator-framework/operator-sdk\" \n " )
110
113
gopkgString = gopkgString [:gopkgLoc ] + "\n source = \" https://github.com/" + prSlug + "\" \n revision = \" " + prSha + "\" \n " + gopkgString [gopkgLoc + 1 :]
111
- err = ioutil .WriteFile ("Gopkg.toml" , []byte (gopkgString ), filemode )
114
+ err = ioutil .WriteFile ("Gopkg.toml" , []byte (gopkgString ), fileutil . DefaultFileMode )
112
115
if err != nil {
113
116
t .Fatalf ("failed to write updated Gopkg.toml: %v" , err )
114
117
}
@@ -178,7 +181,7 @@ func TestMemcached(t *testing.T) {
178
181
}
179
182
}
180
183
os .Remove ("pkg/apis/cache/v1alpha1/memcached_types.go" )
181
- err = ioutil .WriteFile ("pkg/apis/cache/v1alpha1/memcached_types.go" , bytes .Join (memcachedTypesFileLines , []byte ("\n " )), filemode )
184
+ err = ioutil .WriteFile ("pkg/apis/cache/v1alpha1/memcached_types.go" , bytes .Join (memcachedTypesFileLines , []byte ("\n " )), fileutil . DefaultFileMode )
182
185
if err != nil {
183
186
t .Fatal (err )
184
187
}
@@ -190,7 +193,7 @@ func TestMemcached(t *testing.T) {
190
193
}
191
194
192
195
t .Log ("Copying test files to ./test" )
193
- if err = os .MkdirAll ("./test" , dirmode ); err != nil {
196
+ if err = os .MkdirAll ("./test" , fileutil . DefaultDirFileMode ); err != nil {
194
197
t .Fatalf ("could not create test/e2e dir: %v" , err )
195
198
}
196
199
cmdOut , err = exec .Command ("cp" , "-a" , filepath .Join (gopath , "src/github.com/operator-framework/operator-sdk/test/e2e/incluster-test-code" ), "./test/e2e" ).CombinedOutput ()
@@ -227,7 +230,7 @@ func TestMemcached(t *testing.T) {
227
230
// create crd
228
231
filename := file .Name ()
229
232
framework .Global .NamespacedManPath = & filename
230
- err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : time . Second * 10 , RetryInterval : time . Second * 1 })
233
+ err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : cleanupTimeout , RetryInterval : cleanupRetryInterval })
231
234
if err != nil {
232
235
t .Fatal (err )
233
236
}
@@ -247,7 +250,7 @@ func memcachedLeaderTest(t *testing.T, f *framework.Framework, ctx *framework.Te
247
250
return err
248
251
}
249
252
250
- err = e2eutil .WaitForOperatorDeployment (t , f .KubeClient , namespace , "memcached-operator" , 1 , time . Second * 5 , time . Second * 30 )
253
+ err = e2eutil .WaitForOperatorDeployment (t , f .KubeClient , namespace , "memcached-operator" , 1 , retryInterval , timeout )
251
254
if err != nil {
252
255
return err
253
256
}
@@ -263,7 +266,7 @@ func memcachedLeaderTest(t *testing.T, f *framework.Framework, ctx *framework.Te
263
266
return err
264
267
}
265
268
266
- err = e2eutil .WaitForOperatorDeployment (t , f .KubeClient , namespace , "memcached-operator" , 1 , time . Second * 5 , time . Second * 30 )
269
+ err = e2eutil .WaitForOperatorDeployment (t , f .KubeClient , namespace , "memcached-operator" , 1 , retryInterval , timeout )
267
270
if err != nil {
268
271
return err
269
272
}
@@ -320,14 +323,14 @@ func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.Tes
320
323
filename := "deploy/cr.yaml"
321
324
err := ioutil .WriteFile (filename ,
322
325
[]byte (crYAML ),
323
- filemode )
326
+ fileutil . DefaultFileMode )
324
327
if err != nil {
325
328
return err
326
329
}
327
330
328
331
// create memcached custom resource
329
332
framework .Global .NamespacedManPath = & filename
330
- err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : time . Second * 10 , RetryInterval : time . Second * 1 })
333
+ err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : cleanupTimeout , RetryInterval : cleanupRetryInterval })
331
334
if err != nil {
332
335
return err
333
336
}
@@ -338,7 +341,7 @@ func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.Tes
338
341
return err
339
342
}
340
343
// wait for example-memcached to reach 3 replicas
341
- err = e2eutil .WaitForDeployment (t , f .KubeClient , namespace , "example-memcached" , 3 , time . Second * 5 , time . Second * 30 )
344
+ err = e2eutil .WaitForDeployment (t , f .KubeClient , namespace , "example-memcached" , 3 , retryInterval , timeout )
342
345
if err != nil {
343
346
return err
344
347
}
@@ -367,7 +370,7 @@ func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.Tes
367
370
}
368
371
369
372
// wait for example-memcached to reach 4 replicas
370
- return e2eutil .WaitForDeployment (t , f .KubeClient , namespace , "example-memcached" , 4 , time . Second * 5 , time . Second * 30 )
373
+ return e2eutil .WaitForDeployment (t , f .KubeClient , namespace , "example-memcached" , 4 , retryInterval , timeout )
371
374
}
372
375
373
376
func MemcachedLocal (t * testing.T ) {
@@ -427,7 +430,7 @@ func MemcachedCluster(t *testing.T) {
427
430
t .Fatal (err )
428
431
}
429
432
operatorYAML = bytes .Replace (operatorYAML , []byte ("imagePullPolicy: Always" ), []byte ("imagePullPolicy: Never" ), 1 )
430
- err = ioutil .WriteFile ("deploy/operator.yaml" , operatorYAML , filemode )
433
+ err = ioutil .WriteFile ("deploy/operator.yaml" , operatorYAML , fileutil . DefaultFileMode )
431
434
if err != nil {
432
435
t .Fatal (err )
433
436
}
@@ -461,7 +464,7 @@ func MemcachedCluster(t *testing.T) {
461
464
// create namespaced resources
462
465
filename := file .Name ()
463
466
framework .Global .NamespacedManPath = & filename
464
- err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : time . Second * 10 , RetryInterval : time . Second * 1 })
467
+ err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : cleanupTimeout , RetryInterval : cleanupRetryInterval })
465
468
if err != nil {
466
469
t .Fatal (err )
467
470
}
@@ -472,7 +475,7 @@ func MemcachedCluster(t *testing.T) {
472
475
t .Fatal (err )
473
476
}
474
477
// wait for memcached-operator to be ready
475
- err = e2eutil .WaitForOperatorDeployment (t , framework .Global .KubeClient , namespace , "memcached-operator" , 1 , time . Second * 5 , time . Second * 30 )
478
+ err = e2eutil .WaitForOperatorDeployment (t , framework .Global .KubeClient , namespace , "memcached-operator" , 1 , retryInterval , timeout )
476
479
if err != nil {
477
480
t .Fatal (err )
478
481
}
@@ -494,7 +497,7 @@ func MemcachedClusterTest(t *testing.T) {
494
497
// create sa
495
498
filename := "deploy/service_account.yaml"
496
499
framework .Global .NamespacedManPath = & filename
497
- err := ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : time . Second * 10 , RetryInterval : time . Second * 1 })
500
+ err := ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : cleanupTimeout , RetryInterval : cleanupRetryInterval })
498
501
if err != nil {
499
502
t .Fatal (err )
500
503
}
@@ -503,15 +506,15 @@ func MemcachedClusterTest(t *testing.T) {
503
506
// create rbac
504
507
filename = "deploy/role.yaml"
505
508
framework .Global .NamespacedManPath = & filename
506
- err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : time . Second * 10 , RetryInterval : time . Second * 1 })
509
+ err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : cleanupTimeout , RetryInterval : cleanupRetryInterval })
507
510
if err != nil {
508
511
t .Fatal (err )
509
512
}
510
513
t .Log ("Created role" )
511
514
512
515
filename = "deploy/role_binding.yaml"
513
516
framework .Global .NamespacedManPath = & filename
514
- err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : time . Second * 10 , RetryInterval : time . Second * 1 })
517
+ err = ctx .InitializeClusterResources (& framework.CleanupOptions {TestContext : ctx , Timeout : cleanupTimeout , RetryInterval : cleanupRetryInterval })
515
518
if err != nil {
516
519
t .Fatal (err )
517
520
}
0 commit comments