Skip to content

Commit a56886f

Browse files
committed
e2e: test CachedResource virtual resources with full objects
On-behalf-of: @SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
1 parent 5d726f2 commit a56886f

File tree

1 file changed

+58
-26
lines changed

1 file changed

+58
-26
lines changed

test/e2e/virtualresources/cachedresources/vr_cachedresources_test.go

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,30 @@ func TestCachedResources(t *testing.T) {
367367
// Eventually we should see two of each in the resourcesCounter,
368368
// i.e. one for each consumer workspace.
369369
t.Logf("Creating a Cowboy in %q", providerPath)
370-
cowboyOne, err := wildwestClusterClient.Cluster(providerPath).WildwestV1alpha1().Cowboys("default").Create(ctx, &wildwestv1alpha1.Cowboy{
370+
cowboyOne := createCowboy(t, ctx, wildwestClusterClient, providerPath, &wildwestv1alpha1.Cowboy{
371371
ObjectMeta: metav1.ObjectMeta{
372-
Name: "cowboys-1",
372+
Name: "cowboys-1",
373+
Namespace: "default",
373374
},
374-
}, metav1.CreateOptions{})
375+
Spec: wildwestv1alpha1.CowboySpec{
376+
Intent: "cowboys-1-spec",
377+
},
378+
Status: wildwestv1alpha1.CowboyStatus{
379+
Result: "cowboys-1-status",
380+
},
381+
})
375382
require.NoError(t, err)
376383
t.Logf("Creating a Sheriff in %q", providerPath)
377-
sheriffOne, err := createSheriff(ctx, kcpDynClusterClient, logicalcluster.Name(providerPath.String()), &wildwestv1alpha1.Sheriff{
384+
sheriffOne := createSheriff(t, ctx, kcpDynClusterClient, logicalcluster.Name(providerPath.String()), &wildwestv1alpha1.Sheriff{
378385
ObjectMeta: metav1.ObjectMeta{
379386
Name: "sheriffs-1",
380387
},
388+
Spec: wildwestv1alpha1.SheriffSpec{
389+
Intent: "sheriffs-1-spec",
390+
},
391+
Status: wildwestv1alpha1.SheriffStatus{
392+
Result: "sheriffs-1-status",
393+
},
381394
})
382395
require.NoError(t, err)
383396

@@ -530,22 +543,8 @@ func normalizeUnstructuredMap(origObj map[string]interface{}) map[string]interfa
530543
delete(meta, "uid")
531544
delete(meta, "generation")
532545
delete(meta, "managedFields")
533-
534-
ann, hasAnn := meta["annotations"].(map[string]interface{})
535-
if hasAnn {
536-
// TODO(gman0): HACK! https://github.com/kcp-dev/kcp/issues/3478
537-
// Partial metadata objects have this annotation added.
538-
// This will go away once we have full objects.
539-
delete(ann, "kcp.io/original-api-version")
540-
}
541546
}
542547

543-
// TODO(gman0): HACK! https://github.com/kcp-dev/kcp/issues/3478
544-
// We need to remove spec and status, because we're getting only metadata for now.
545-
// This will go away once we have full objects.
546-
delete(obj, "spec")
547-
delete(obj, "status")
548-
549548
return obj
550549
}
551550

@@ -566,11 +565,11 @@ func listSheriffs(ctx context.Context, c kcpdynamic.ClusterInterface, cluster lo
566565
return &sheriffs, nil
567566
}
568567

569-
func createSheriff(ctx context.Context, c kcpdynamic.ClusterInterface, cluster logicalcluster.Name, sheriff *wildwestv1alpha1.Sheriff) (*wildwestv1alpha1.Sheriff, error) {
568+
func createSheriff(t *testing.T, ctx context.Context, c kcpdynamic.ClusterInterface, cluster logicalcluster.Name, sheriff *wildwestv1alpha1.Sheriff) *wildwestv1alpha1.Sheriff {
569+
t.Helper()
570+
570571
m, err := runtime.DefaultUnstructuredConverter.ToUnstructured(sheriff)
571-
if err != nil {
572-
return nil, err
573-
}
572+
require.NoError(t, err)
574573
u := &unstructured.Unstructured{
575574
Object: m,
576575
}
@@ -580,11 +579,44 @@ func createSheriff(ctx context.Context, c kcpdynamic.ClusterInterface, cluster l
580579
u, err = c.Cluster(cluster.Path()).Resource(
581580
wildwestv1alpha1.SchemeGroupVersion.WithResource("sheriffs"),
582581
).Create(ctx, u, metav1.CreateOptions{})
583-
if err != nil {
584-
return nil, err
585-
}
582+
require.NoError(t, err)
586583

587584
createdSheriff := &wildwestv1alpha1.Sheriff{}
588585
err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, createdSheriff)
589-
return createdSheriff, err
586+
require.NoError(t, err)
587+
588+
createdSheriff.Status = sheriff.Status
589+
m, err = runtime.DefaultUnstructuredConverter.ToUnstructured(createdSheriff)
590+
require.NoError(t, err)
591+
u.Object = m
592+
593+
u, err = c.Cluster(cluster.Path()).Resource(
594+
wildwestv1alpha1.SchemeGroupVersion.WithResource("sheriffs"),
595+
).UpdateStatus(ctx, u, metav1.UpdateOptions{})
596+
require.NoError(t, err)
597+
598+
sheriffWithStatus := &wildwestv1alpha1.Sheriff{}
599+
err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, sheriffWithStatus)
600+
require.NoError(t, err)
601+
602+
require.Equal(t, sheriff.Spec, sheriffWithStatus.Spec, "created Sheriff should have Spec")
603+
require.Equal(t, sheriff.Status, sheriffWithStatus.Status, "created Sheriff should have Status")
604+
605+
return sheriffWithStatus
606+
}
607+
608+
func createCowboy(t *testing.T, ctx context.Context, c wildwestclientset.ClusterInterface, path logicalcluster.Path, cowboy *wildwestv1alpha1.Cowboy) *wildwestv1alpha1.Cowboy {
609+
t.Helper()
610+
611+
createdCowboy, err := c.Cluster(path).WildwestV1alpha1().Cowboys(cowboy.Namespace).Create(ctx, cowboy, metav1.CreateOptions{})
612+
require.NoError(t, err)
613+
614+
createdCowboy.Status = cowboy.Status
615+
cowboyWithStatus, err := c.Cluster(path).WildwestV1alpha1().Cowboys(cowboy.Namespace).UpdateStatus(ctx, createdCowboy, metav1.UpdateOptions{})
616+
require.NoError(t, err)
617+
618+
require.Equal(t, cowboy.Spec, cowboyWithStatus.Spec, "created Cowboy should have Spec")
619+
require.Equal(t, cowboy.Status, cowboyWithStatus.Status, "created Cowboy should have Status")
620+
621+
return cowboyWithStatus
590622
}

0 commit comments

Comments
 (0)