@@ -35,10 +35,11 @@ import (
35
35
36
36
func TestValidateObjectMetadata (t * testing.T ) {
37
37
cases := []struct {
38
- name string
39
- objectMeta metav1.Object
40
- ctx context.Context
41
- expectErr * apis.FieldError
38
+ name string
39
+ objectMeta metav1.Object
40
+ allowAutoscaling bool
41
+ ctx context.Context
42
+ expectErr * apis.FieldError
42
43
}{{
43
44
name : "invalid name - dots" ,
44
45
objectMeta : & metav1.ObjectMeta {
@@ -150,8 +151,9 @@ func TestValidateObjectMetadata(t *testing.T) {
150
151
},
151
152
},
152
153
}, {
153
- name : "revision initial scale not parseable" ,
154
- ctx : config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : true }}),
154
+ name : "revision initial scale not parseable" ,
155
+ ctx : config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : true }}),
156
+ allowAutoscaling : true ,
155
157
objectMeta : & metav1.ObjectMeta {
156
158
GenerateName : "some-name" ,
157
159
Annotations : map [string ]string {
@@ -160,8 +162,9 @@ func TestValidateObjectMetadata(t *testing.T) {
160
162
},
161
163
expectErr : apis .ErrInvalidValue ("invalid" , "annotations." + autoscaling .InitialScaleAnnotationKey ),
162
164
}, {
163
- name : "negative revision initial scale" ,
164
- ctx : config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : true }}),
165
+ name : "negative revision initial scale" ,
166
+ ctx : config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : true }}),
167
+ allowAutoscaling : true ,
165
168
objectMeta : & metav1.ObjectMeta {
166
169
GenerateName : "some-name" ,
167
170
Annotations : map [string ]string {
@@ -170,31 +173,43 @@ func TestValidateObjectMetadata(t *testing.T) {
170
173
},
171
174
expectErr : apis .ErrInvalidValue ("-2" , "annotations." + autoscaling .InitialScaleAnnotationKey ),
172
175
}, {
173
- name : "cluster allows zero revision initial scale" ,
174
- ctx : config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : true }}),
176
+ name : "cluster allows zero revision initial scale" ,
177
+ ctx : config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : true }}),
178
+ allowAutoscaling : true ,
175
179
objectMeta : & metav1.ObjectMeta {
176
180
GenerateName : "some-name" ,
177
181
Annotations : map [string ]string {
178
182
autoscaling .InitialScaleAnnotationKey : "0" ,
179
183
},
180
184
},
181
185
}, {
182
- name : "cluster does not allows zero revision initial scale" ,
186
+ name : "cluster does not allow zero revision initial scale" ,
187
+ allowAutoscaling : true ,
183
188
objectMeta : & metav1.ObjectMeta {
184
189
GenerateName : "some-name" ,
185
190
Annotations : map [string ]string {
186
191
autoscaling .InitialScaleAnnotationKey : "0" ,
187
192
},
188
193
},
189
194
expectErr : apis .ErrInvalidValue ("0" , "annotations." + autoscaling .InitialScaleAnnotationKey ),
195
+ }, {
196
+ name : "autoscaling annotations on a resource that doesn't allow them" ,
197
+ allowAutoscaling : false ,
198
+ objectMeta : & metav1.ObjectMeta {
199
+ GenerateName : "some-name" ,
200
+ Annotations : map [string ]string {
201
+ autoscaling .InitialScaleAnnotationKey : "0" ,
202
+ },
203
+ },
204
+ expectErr : apis .ErrInvalidKeyName (autoscaling .InitialScaleAnnotationKey , "annotations" , `autoscaling annotations must be put under "spec.template.metadata.annotations" to work` ),
190
205
}}
191
206
192
207
for _ , c := range cases {
193
208
t .Run (c .name , func (t * testing.T ) {
194
209
if c .ctx == nil {
195
210
c .ctx = config .ToContext (context .Background (), & config.Config {Autoscaler : & autoscalerconfig.Config {AllowZeroInitialScale : false }})
196
211
}
197
- err := ValidateObjectMetadata (c .ctx , c .objectMeta )
212
+ err := ValidateObjectMetadata (c .ctx , c .objectMeta , c . allowAutoscaling )
198
213
if got , want := err .Error (), c .expectErr .Error (); got != want {
199
214
t .Errorf ("\n Got: %q\n want: %q" , got , want )
200
215
}
0 commit comments