@@ -120,6 +120,7 @@ func TestEmptyDefaultCACertificate(t *testing.T) {
120120 Name : "myroute" ,
121121 UID : types .UID ("abc" ),
122122 ResourceVersion : "1" ,
123+ Generation : 1 ,
123124 },
124125 Spec : routeapi.RouteSpec {
125126 Host : "myhost.com" ,
@@ -1112,3 +1113,45 @@ func TestExternalCertRemoval(t *testing.T) {
11121113 }
11131114 }
11141115}
1116+
1117+ func TestRouteGenerationManagement (t * testing.T ) {
1118+ ctx := apirequest .NewContext ()
1119+ strategy := NewStrategy (testAllocator {}, & testSAR {allow : true }, & testSecretGetter {}, true )
1120+
1121+ simpleRoute := & routeapi.Route {}
1122+ strategy .Validate (ctx , simpleRoute )
1123+ if simpleRoute .Spec .Host != "mygeneratedhost.com" {
1124+ t .Fatalf ("Expected host to be allocated, got %s" , simpleRoute .Spec .Host )
1125+ }
1126+
1127+ if simpleRoute .Generation > 0 {
1128+ t .Fatalf ("Expected generation to not be allocated yet, got %d" , simpleRoute .Generation )
1129+ }
1130+
1131+ // PrepareForCreate should set a generation 1
1132+ strategy .PrepareForCreate (ctx , simpleRoute )
1133+ if simpleRoute .Generation != 1 {
1134+ t .Fatalf ("Expected generation after create to be 1, got %d" , simpleRoute .Generation )
1135+ }
1136+
1137+ newRoute := simpleRoute .DeepCopy ()
1138+ // Changing annotations and labels should not bump the generation
1139+ newRoute .Annotations = map [string ]string {
1140+ "someannotation" : "novalue" ,
1141+ }
1142+ newRoute .Labels = map [string ]string {
1143+ "somelabel" : "novalue" ,
1144+ }
1145+
1146+ strategy .PrepareForUpdate (ctx , newRoute , simpleRoute )
1147+ if newRoute .Generation != 1 {
1148+ t .Fatalf ("Expected generation after metadata update to still be 1, got %d" , newRoute .Generation )
1149+ }
1150+
1151+ // Updating the spec should bump the generation
1152+ newRoute .Spec .Path = "/xpto"
1153+ strategy .PrepareForUpdate (ctx , newRoute , simpleRoute )
1154+ if newRoute .Generation != 2 {
1155+ t .Fatalf ("Expected generation after spec update to be 2, got %d" , newRoute .Generation )
1156+ }
1157+ }
0 commit comments