@@ -264,141 +264,133 @@ func randomName() string {
264264// TestValidCatalogEntry verifies that our catalog controller can validate valid
265265// catalogEntry by adding correct conditions, resources and exportPermissionClaims
266266func TestValidCatalogEntry (t * testing.T ) {
267- t .Parallel ()
268- for i := 0 ; i < 3 ; i ++ {
269- t .Run (fmt .Sprintf ("attempt-%d" , i ), func (t * testing.T ) {
270- t .Parallel ()
271- workspaceCluster := parentWorkspace (t ).Join (randomName ())
272- c := createWorkspace (t , workspaceCluster )
273-
274- // Create test apiResourceSchema
275- schema := & apisv1alpha1.APIResourceSchema {
276- ObjectMeta : metav1.ObjectMeta {
277- Name : "schema-test" ,
278- },
279- Spec : apisv1alpha1.APIResourceSchemaSpec {
280- Group : "catalog.kcp.dev" ,
281- Names : apiextensionsv1.CustomResourceDefinitionNames {
282- Plural : "tests" ,
283- Singular : "test" ,
284- Kind : "Test" ,
285- },
286- Scope : apiextensionsv1 .ClusterScoped ,
287- Versions : []apisv1alpha1.APIResourceVersion {{
288- Name : "v1" ,
289- Served : true ,
290- Storage : true ,
291- }},
267+ t .Run ("testing valid catalog entry" , func (t * testing.T ) {
268+ workspaceCluster := parentWorkspace (t ).Join (randomName ())
269+ c := createWorkspace (t , workspaceCluster )
270+
271+ // Create test apiResourceSchema
272+ schema := & apisv1alpha1.APIResourceSchema {
273+ ObjectMeta : metav1.ObjectMeta {
274+ Name : "schema-test" ,
275+ },
276+ Spec : apisv1alpha1.APIResourceSchemaSpec {
277+ Group : "catalog.kcp.dev" ,
278+ Names : apiextensionsv1.CustomResourceDefinitionNames {
279+ Plural : "tests" ,
280+ Singular : "test" ,
281+ Kind : "Test" ,
292282 },
293- }
294- err := createAPIResourceSchema (t , c , workspaceCluster , schema )
295- if err != nil {
296- t .Fatalf ("failed to create APIResourceSchema in cluster %q: %v" , workspaceCluster , err )
297- }
283+ Scope : apiextensionsv1 .ClusterScoped ,
284+ Versions : []apisv1alpha1.APIResourceVersion {{
285+ Name : "v1" ,
286+ Served : true ,
287+ Storage : true ,
288+ }},
289+ },
290+ }
291+ err := createAPIResourceSchema (t , c , workspaceCluster , schema )
292+ if err != nil {
293+ t .Fatalf ("failed to create APIResourceSchema in cluster %q: %v" , workspaceCluster , err )
294+ }
298295
299- // Create test APIExport
300- export := & apisv1alpha1.APIExport {
301- ObjectMeta : metav1.ObjectMeta {
302- Name : "export-test" ,
303- },
304- Spec : apisv1alpha1.APIExportSpec {
305- LatestResourceSchemas : []string {"tests.catalog.kcp.dev" },
306- PermissionClaims : []apisv1alpha1.PermissionClaim {
307- {
308- GroupResource : apisv1alpha1.GroupResource {Resource : "configmaps" },
309- },
296+ // Create test APIExport
297+ export := & apisv1alpha1.APIExport {
298+ ObjectMeta : metav1.ObjectMeta {
299+ Name : "export-test" ,
300+ },
301+ Spec : apisv1alpha1.APIExportSpec {
302+ LatestResourceSchemas : []string {"tests.catalog.kcp.dev" },
303+ PermissionClaims : []apisv1alpha1.PermissionClaim {
304+ {
305+ GroupResource : apisv1alpha1.GroupResource {Resource : "configmaps" },
310306 },
311307 },
312- }
313- err = createAPIExport (t , c , workspaceCluster , export )
314- if err != nil {
315- t .Fatalf ("failed to create APIExport in cluster %q: %v" , workspaceCluster , err )
316- }
308+ },
309+ }
310+ err = createAPIExport (t , c , workspaceCluster , export )
311+ if err != nil {
312+ t .Fatalf ("failed to create APIExport in cluster %q: %v" , workspaceCluster , err )
313+ }
317314
318- // Create catalogentry
319- path := "root:" + workspaceCluster .Base ()
320- newEntry := & catalogv1alpha1.CatalogEntry {
321- ObjectMeta : metav1.ObjectMeta {
322- Name : "entry-test" ,
323- },
324- Spec : catalogv1alpha1.CatalogEntrySpec {
325- Exports : []apisv1alpha1.ExportReference {
326- {
327- Workspace : & apisv1alpha1.WorkspaceExportReference {
328- Path : path ,
329- ExportName : "export-test" ,
330- },
315+ // Create catalogentry
316+ path := "root:" + workspaceCluster .Base ()
317+ newEntry := & catalogv1alpha1.CatalogEntry {
318+ ObjectMeta : metav1.ObjectMeta {
319+ Name : "entry-test" ,
320+ },
321+ Spec : catalogv1alpha1.CatalogEntrySpec {
322+ Exports : []apisv1alpha1.ExportReference {
323+ {
324+ Workspace : & apisv1alpha1.WorkspaceExportReference {
325+ Path : path ,
326+ ExportName : "export-test" ,
331327 },
332328 },
333329 },
334- }
335- entry , err := createCatalogEntry (t , c , workspaceCluster , newEntry )
330+ },
331+ }
332+ entry , err := createCatalogEntry (t , c , workspaceCluster , newEntry )
336333
337- // Check APIExportValid condition status to be True
338- if ! conditions .IsTrue (entry , catalogv1alpha1 .APIExportValidType ) {
339- t .Fatalf ("expect APIExportValid condition in entry %qin cluster %q to be True" , entry .GetName (), workspaceCluster )
340- }
341- // Check ExportPermissionClaims status
342- gr := metav1.GroupResource {
343- Group : schema .Spec .Group ,
344- Resource : schema .Spec .Names .Plural ,
345- }
346- if len (entry .Status .Resources ) > 0 {
347- assert .Equal (t , entry .Status .Resources [0 ], gr , "two resources should be the same" )
348- } else {
349- t .Fatalf ("expect entry %q in cluster %q to has one resource" , entry .GetName (), workspaceCluster )
350- }
351- // Check Resource status
352- if len (entry .Status .ExportPermissionClaims ) > 0 {
353- claim := apisv1alpha1.PermissionClaim {
354- GroupResource : apisv1alpha1.GroupResource {
355- Resource : "configmaps" ,
356- },
357- }
358- assert .Equal (t , entry .Status .ExportPermissionClaims [0 ], claim , "two ExportPermissionClaims should be the same" )
359- } else {
360- t .Fatalf ("expect entry %q in cluster %q to has one ExportPermissionClaim" , entry .GetName (), workspaceCluster )
334+ // Check APIExportValid condition status to be True
335+ if ! conditions .IsTrue (entry , catalogv1alpha1 .APIExportValidType ) {
336+ t .Fatalf ("expect APIExportValid condition in entry %qin cluster %q to be True" , entry .GetName (), workspaceCluster )
337+ }
338+ // Check ExportPermissionClaims status
339+ gr := metav1.GroupResource {
340+ Group : schema .Spec .Group ,
341+ Resource : schema .Spec .Names .Plural ,
342+ }
343+ if len (entry .Status .Resources ) > 0 {
344+ assert .Equal (t , entry .Status .Resources [0 ], gr , "two resources should be the same" )
345+ } else {
346+ t .Fatalf ("expect entry %q in cluster %q to has one resource" , entry .GetName (), workspaceCluster )
347+ }
348+ // Check Resource status
349+ if len (entry .Status .ExportPermissionClaims ) > 0 {
350+ claim := apisv1alpha1.PermissionClaim {
351+ GroupResource : apisv1alpha1.GroupResource {
352+ Resource : "configmaps" ,
353+ },
361354 }
362- })
363- }
355+ assert .Equal (t , entry .Status .ExportPermissionClaims [0 ], claim , "two ExportPermissionClaims should be the same" )
356+ } else {
357+ t .Fatalf ("expect entry %q in cluster %q to has one ExportPermissionClaim" , entry .GetName (), workspaceCluster )
358+ }
359+ })
364360}
365361
366362// TestInvalidCatalogEntry verifies that our catalog controller can validate
367363// invalid catalogEntry (bad export reference) but add a False condition in status
368364func TestInvalidCatalogEntry (t * testing.T ) {
369- t .Parallel ()
370- for i := 0 ; i < 3 ; i ++ {
371- t .Run (fmt .Sprintf ("attempt-%d" , i ), func (t * testing.T ) {
372- t .Parallel ()
373- workspaceCluster := parentWorkspace (t ).Join (randomName ())
374- c := createWorkspace (t , workspaceCluster )
375-
376- // Create catalogentry
377- path := "root:" + workspaceCluster .Base ()
378- newEntry := & catalogv1alpha1.CatalogEntry {
379- ObjectMeta : metav1.ObjectMeta {
380- Name : "entry-test" ,
381- },
382- Spec : catalogv1alpha1.CatalogEntrySpec {
383- Exports : []apisv1alpha1.ExportReference {
384- {
385- Workspace : & apisv1alpha1.WorkspaceExportReference {
386- Path : path ,
387- ExportName : "export-test" ,
388- },
365+ t .Run ("testing invalid catalog entry" , func (t * testing.T ) {
366+ workspaceCluster := parentWorkspace (t ).Join (randomName ())
367+ c := createWorkspace (t , workspaceCluster )
368+
369+ // Create catalogentry
370+ path := "root:" + workspaceCluster .Base ()
371+ newEntry := & catalogv1alpha1.CatalogEntry {
372+ ObjectMeta : metav1.ObjectMeta {
373+ Name : "entry-test" ,
374+ },
375+ Spec : catalogv1alpha1.CatalogEntrySpec {
376+ Exports : []apisv1alpha1.ExportReference {
377+ {
378+ Workspace : & apisv1alpha1.WorkspaceExportReference {
379+ Path : path ,
380+ ExportName : "export-test" ,
389381 },
390382 },
391383 },
392- }
393- entry , err := createCatalogEntry (t , c , workspaceCluster , newEntry )
394- if err != nil {
395- t .Fatalf ("catalogEntry %q failed to be reconciled in cluster %q: %v" , entry .GetName (), workspaceCluster , err )
396- }
384+ },
385+ }
386+ entry , err := createCatalogEntry (t , c , workspaceCluster , newEntry )
387+ if err != nil {
388+ t .Fatalf ("catalogEntry %q failed to be reconciled in cluster %q: %v" , entry .GetName (), workspaceCluster , err )
389+ }
397390
398- // Check APIExportValid condition status to be False due to bad export ref
399- if conditions .IsTrue (entry , catalogv1alpha1 .APIExportValidType ) {
400- t .Fatalf ("expect APIExportValid condition in entry %q in cluster %q to be False" , entry .GetName (), workspaceCluster )
401- }
402- })
403- }
391+ // Check APIExportValid condition status to be False due to bad export ref
392+ if conditions .IsTrue (entry , catalogv1alpha1 .APIExportValidType ) {
393+ t .Fatalf ("expect APIExportValid condition in entry %q in cluster %q to be False" , entry .GetName (), workspaceCluster )
394+ }
395+ })
404396}
0 commit comments