@@ -12,7 +12,33 @@ import (
12
12
kubefake "k8s.io/client-go/kubernetes/fake"
13
13
)
14
14
15
- //nolint: goconst, funlen, gocyclo
15
+ var (
16
+ testS3Storage = imageregistryv1.ImageRegistryConfigStorage {
17
+ S3 : & imageregistryv1.ImageRegistryConfigStorageS3 {
18
+ Bucket : "foo" ,
19
+ Region : "bar" ,
20
+ RegionEndpoint : "point" ,
21
+ KeyID : "key" ,
22
+ },
23
+ }
24
+ testAzureStorage = imageregistryv1.ImageRegistryConfigStorage {
25
+ Azure : & imageregistryv1.ImageRegistryConfigStorageAzure {
26
+ AccountName : "account" ,
27
+ Container : "container" ,
28
+ CloudName : "cloud" ,
29
+ },
30
+ }
31
+ testGCSStorage = imageregistryv1.ImageRegistryConfigStorage {
32
+ GCS : & imageregistryv1.ImageRegistryConfigStorageGCS {
33
+ Bucket : "bucket" ,
34
+ Region : "region" ,
35
+ ProjectID : "foo" ,
36
+ KeyID : "bar" ,
37
+ },
38
+ }
39
+ )
40
+
41
+ //nolint: goconst, funlen, gocyclo, dupl
16
42
func Test_ImageRegistry_Gather (t * testing.T ) {
17
43
tests := []struct {
18
44
name string
@@ -42,27 +68,23 @@ func Test_ImageRegistry_Gather(t *testing.T) {
42
68
Name : "cluster" ,
43
69
},
44
70
Spec : imageregistryv1.ImageRegistrySpec {
45
- Storage : imageregistryv1.ImageRegistryConfigStorage {
46
- S3 : & imageregistryv1.ImageRegistryConfigStorageS3 {
47
- Bucket : "foo" ,
48
- Region : "bar" ,
49
- RegionEndpoint : "point" ,
50
- KeyID : "key" ,
51
- },
52
- },
71
+ Storage : testS3Storage ,
72
+ },
73
+ Status : imageregistryv1.ImageRegistryStatus {
74
+ Storage : testS3Storage ,
53
75
},
54
76
},
55
77
evalOutput : func (t * testing.T , obj * imageregistryv1.Config ) {
56
- if obj .Spec .Storage .S3 .Bucket != "xxx" {
78
+ if obj .Spec .Storage .S3 .Bucket != "xxx" || obj . Status . Storage . S3 . Bucket != "xxx" {
57
79
t .Errorf ("expected s3 bucket anonymized, got %q" , obj .Spec .Storage .S3 .Bucket )
58
80
}
59
- if obj .Spec .Storage .S3 .Region != "xxx" {
81
+ if obj .Spec .Storage .S3 .Region != "xxx" || obj . Status . Storage . S3 . Region != "xxx" {
60
82
t .Errorf ("expected s3 region anonymized, got %q" , obj .Spec .Storage .S3 .Region )
61
83
}
62
- if obj .Spec .Storage .S3 .RegionEndpoint != "xxxxx" {
84
+ if obj .Spec .Storage .S3 .RegionEndpoint != "xxxxx" || obj . Status . Storage . S3 . RegionEndpoint != "xxxxx" {
63
85
t .Errorf ("expected s3 region endpoint anonymized, got %q" , obj .Spec .Storage .S3 .RegionEndpoint )
64
86
}
65
- if obj .Spec .Storage .S3 .KeyID != "xxx" {
87
+ if obj .Spec .Storage .S3 .KeyID != "xxx" || obj . Status . Storage . S3 . KeyID != "xxx" {
66
88
t .Errorf ("expected s3 keyID anonymized, got %q" , obj .Spec .Storage .S3 .KeyID )
67
89
}
68
90
},
@@ -74,21 +96,22 @@ func Test_ImageRegistry_Gather(t *testing.T) {
74
96
Name : "cluster" ,
75
97
},
76
98
Spec : imageregistryv1.ImageRegistrySpec {
77
- Storage : imageregistryv1.ImageRegistryConfigStorage {
78
- Azure : & imageregistryv1.ImageRegistryConfigStorageAzure {
79
- AccountName : "account" ,
80
- Container : "container" ,
81
- },
82
- },
99
+ Storage : testAzureStorage ,
100
+ },
101
+ Status : imageregistryv1.ImageRegistryStatus {
102
+ Storage : testAzureStorage ,
83
103
},
84
104
},
85
105
evalOutput : func (t * testing.T , obj * imageregistryv1.Config ) {
86
- if obj .Spec .Storage .Azure .AccountName != "xxxxxxx" {
106
+ if obj .Spec .Storage .Azure .AccountName != "xxxxxxx" || obj . Status . Storage . Azure . AccountName != "xxxxxxx" {
87
107
t .Errorf ("expected azure account name anonymized, got %q" , obj .Spec .Storage .Azure .AccountName )
88
108
}
89
- if obj .Spec .Storage .Azure .Container = = "xxxxxxx " {
109
+ if obj .Spec .Storage .Azure .Container != "xxxxxxxxx" || obj . Status . Storage . Azure . Container ! = "xxxxxxxxx " {
90
110
t .Errorf ("expected azure container anonymized, got %q" , obj .Spec .Storage .Azure .Container )
91
111
}
112
+ if obj .Spec .Storage .Azure .CloudName != "xxxxx" || obj .Status .Storage .Azure .CloudName != "xxxxx" {
113
+ t .Errorf ("expected azure cloud name anonymized, got %q" , obj .Spec .Storage .Azure .CloudName )
114
+ }
92
115
},
93
116
},
94
117
{
@@ -98,24 +121,20 @@ func Test_ImageRegistry_Gather(t *testing.T) {
98
121
Name : "cluster" ,
99
122
},
100
123
Spec : imageregistryv1.ImageRegistrySpec {
101
- Storage : imageregistryv1.ImageRegistryConfigStorage {
102
- GCS : & imageregistryv1.ImageRegistryConfigStorageGCS {
103
- Bucket : "bucket" ,
104
- Region : "region" ,
105
- ProjectID : "foo" ,
106
- KeyID : "bar" ,
107
- },
108
- },
124
+ Storage : testGCSStorage ,
125
+ },
126
+ Status : imageregistryv1.ImageRegistryStatus {
127
+ Storage : testGCSStorage ,
109
128
},
110
129
},
111
130
evalOutput : func (t * testing.T , obj * imageregistryv1.Config ) {
112
- if obj .Spec .Storage .GCS .Bucket != "xxxxxx" {
131
+ if obj .Spec .Storage .GCS .Bucket != "xxxxxx" || obj . Status . Storage . GCS . Bucket != "xxxxxx" {
113
132
t .Errorf ("expected gcs bucket anonymized, got %q" , obj .Spec .Storage .GCS .Bucket )
114
133
}
115
- if obj .Spec .Storage .GCS .ProjectID != "xxx" {
134
+ if obj .Spec .Storage .GCS .ProjectID != "xxx" || obj . Status . Storage . GCS . ProjectID != "xxx" {
116
135
t .Errorf ("expected gcs projectID endpoint anonymized, got %q" , obj .Spec .Storage .GCS .ProjectID )
117
136
}
118
- if obj .Spec .Storage .GCS .KeyID != "xxx" {
137
+ if obj .Spec .Storage .GCS .KeyID != "xxx" || obj . Status . Storage . GCS . KeyID != "xxx" {
119
138
t .Errorf ("expected gcs keyID anonymized, got %q" , obj .Spec .Storage .GCS .KeyID )
120
139
}
121
140
},
0 commit comments