@@ -62,6 +62,7 @@ func TestPostInvalidObjectMeta(t *testing.T) {
62
62
63
63
obj := fixtures .NewNoxuInstance ("default" , "foo" )
64
64
unstructured .SetNestedField (obj .UnstructuredContent (), int64 (42 ), "metadata" , "unknown" )
65
+ unstructured .SetNestedField (obj .UnstructuredContent (), nil , "metadata" , "generation" )
65
66
unstructured .SetNestedField (obj .UnstructuredContent (), map [string ]interface {}{"foo" : int64 (42 ), "bar" : "abc" }, "metadata" , "labels" )
66
67
_ , err = instantiateCustomResource (t , obj , noxuResourceClient , noxuDefinition )
67
68
if err == nil {
@@ -86,6 +87,14 @@ func TestPostInvalidObjectMeta(t *testing.T) {
86
87
} else if found {
87
88
t .Errorf ("unexpected metadata.unknown=%#v: expected this to be pruned" , unknown )
88
89
}
90
+
91
+ if generation , found , err := unstructured .NestedInt64 (obj .UnstructuredContent (), "metadata" , "generation" ); err != nil {
92
+ t .Errorf ("unexpected error getting metadata.generation: %v" , err )
93
+ } else if ! found {
94
+ t .Errorf ("expected metadata.generation=1: got: %d" , generation )
95
+ } else if generation != 1 {
96
+ t .Errorf ("unexpected metadata.generation=%d: expected this to be set to 1" , generation )
97
+ }
89
98
}
90
99
91
100
func TestInvalidObjectMetaInStorage (t * testing.T ) {
@@ -150,6 +159,8 @@ func TestInvalidObjectMetaInStorage(t *testing.T) {
150
159
151
160
original := fixtures .NewNoxuInstance ("default" , "foo" )
152
161
unstructured .SetNestedField (original .UnstructuredContent (), int64 (42 ), "metadata" , "unknown" )
162
+ unstructured .SetNestedField (original .UnstructuredContent (), nil , "metadata" , "generation" )
163
+
153
164
unstructured .SetNestedField (original .UnstructuredContent (), map [string ]interface {}{"foo" : int64 (42 ), "bar" : "abc" }, "metadata" , "annotations" )
154
165
unstructured .SetNestedField (original .UnstructuredContent (), map [string ]interface {}{"invalid" : "x y" }, "metadata" , "labels" )
155
166
unstructured .SetNestedField (original .UnstructuredContent (), int64 (42 ), "embedded" , "metadata" , "unknown" )
@@ -193,6 +204,16 @@ func TestInvalidObjectMetaInStorage(t *testing.T) {
193
204
t .Errorf ("Unexpected to find embedded.metadata.unknown=%#v" , unknown )
194
205
}
195
206
207
+ t .Logf ("Checking that metadata.generation=1" )
208
+
209
+ if generation , found , err := unstructured .NestedInt64 (obj .UnstructuredContent (), "metadata" , "generation" ); err != nil {
210
+ t .Errorf ("unexpected error getting metadata.generation: %v" , err )
211
+ } else if ! found {
212
+ t .Errorf ("expected metadata.generation=1: got: %d" , generation )
213
+ } else if generation != 1 {
214
+ t .Errorf ("unexpected metadata.generation=%d: expected this to be set to 1" , generation )
215
+ }
216
+
196
217
t .Logf ("Checking that ObjectMeta is pruned from wrongly-typed annotations" )
197
218
198
219
if annotations , found , err := unstructured .NestedStringMap (obj .UnstructuredContent (), "metadata" , "annotations" ); err != nil {
0 commit comments