@@ -377,3 +377,59 @@ func TestProjection(t *testing.T) {
377377 t .Errorf ("Expected ARS to have short names %v, but has %v." , pr .Spec .Projection .ShortNames , ars .Spec .Names .ShortNames )
378378 }
379379}
380+
381+ func TestNonCRDResource (t * testing.T ) {
382+ const (
383+ apiExportName = "example.com"
384+ originalVersion = "v1"
385+ )
386+
387+ ctx := context .Background ()
388+ ctrlruntime .SetLogger (logr .Discard ())
389+
390+ // setup a test environment in kcp
391+ orgKubconfig := utils .CreateOrganization (t , ctx , "ars-non-crd" , apiExportName )
392+
393+ // start a service cluster
394+ envtestKubeconfig , envtestClient , _ := utils .RunEnvtest (t , nil )
395+
396+ // publish rbac Roles
397+ t .Logf ("Publishing Roles…" )
398+ pr := & syncagentv1alpha1.PublishedResource {
399+ ObjectMeta : metav1.ObjectMeta {
400+ Name : "publish-roles" ,
401+ },
402+ Spec : syncagentv1alpha1.PublishedResourceSpec {
403+ Resource : syncagentv1alpha1.SourceResourceDescriptor {
404+ APIGroup : "rbac.authorization.k8s.io" ,
405+ Version : "v1" ,
406+ Kind : "Role" ,
407+ },
408+ },
409+ }
410+
411+ if err := envtestClient .Create (ctx , pr ); err != nil {
412+ t .Fatalf ("Failed to create PublishedResource: %v" , err )
413+ }
414+
415+ // let the agent do its thing
416+ utils .RunAgent (ctx , t , "bob" , orgKubconfig , envtestKubeconfig , apiExportName )
417+
418+ // wait for the APIExport to be updated
419+ t .Logf ("Waiting for APIExport to be updated…" )
420+ orgClient := utils .GetClient (t , orgKubconfig )
421+ apiExportKey := types.NamespacedName {Name : apiExportName }
422+
423+ err := wait .PollUntilContextTimeout (ctx , 500 * time .Millisecond , 1 * time .Minute , false , func (ctx context.Context ) (done bool , err error ) {
424+ apiExport := & kcpapisv1alpha1.APIExport {}
425+ err = orgClient .Get (ctx , apiExportKey , apiExport )
426+ if err != nil {
427+ return false , err
428+ }
429+
430+ return len (apiExport .Spec .LatestResourceSchemas ) > 0 , nil
431+ })
432+ if err != nil {
433+ t .Fatalf ("Failed to wait for APIExport to be updated: %v" , err )
434+ }
435+ }
0 commit comments