Skip to content

Commit c19bcfe

Browse files
committed
this test obviously failed since we fixed the CRD watching issue earlier, adjust it to the new logic
On-behalf-of: @SAP [email protected]
1 parent bfcb666 commit c19bcfe

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

test/e2e/apiresourceschema/apiresourceschema_test.go

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/apimachinery/pkg/types"
3737
"k8s.io/apimachinery/pkg/util/wait"
3838
ctrlruntime "sigs.k8s.io/controller-runtime"
39+
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
3940
)
4041

4142
func TestARSAreCreated(t *testing.T) {
@@ -147,51 +148,62 @@ func TestARSAreNotUpdated(t *testing.T) {
147148
// let the agent do its thing
148149
utils.RunAgent(ctx, t, "bob", orgKubconfig, envtestKubeconfig, apiExportName)
149150

150-
// wait for the APIExport to be updated
151-
t.Logf("Waiting for APIExport to be updated…")
151+
// check ARS
152+
t.Logf("Waiting for APIResourceSchema to be created…")
152153
orgClient := utils.GetClient(t, orgKubconfig)
153-
apiExportKey := types.NamespacedName{Name: apiExportName}
154154

155-
var arsName string
156155
err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 1*time.Minute, false, func(ctx context.Context) (done bool, err error) {
157-
apiExport := &kcpapisv1alpha1.APIExport{}
158-
err = orgClient.Get(ctx, apiExportKey, apiExport)
156+
schemas := &kcpapisv1alpha1.APIResourceSchemaList{}
157+
err = orgClient.List(ctx, schemas, ctrlruntimeclient.HasLabels{syncagentv1alpha1.AgentNameLabel})
159158
if err != nil {
160159
return false, err
161160
}
162161

163-
if len(apiExport.Spec.LatestResourceSchemas) == 0 {
164-
return false, nil
165-
}
166-
167-
arsName = apiExport.Spec.LatestResourceSchemas[0]
168-
169-
return true, nil
162+
return len(schemas.Items) == 1, nil
170163
})
171164
if err != nil {
172-
t.Fatalf("Failed to wait for APIExport to be updated: %v", err)
165+
t.Fatalf("Failed to wait for APIResourceSchema to be created: %v", err)
166+
}
167+
168+
if err := envtestClient.Get(ctx, ctrlruntimeclient.ObjectKeyFromObject(pr), pr); err != nil {
169+
t.Fatalf("Failed to fetch PublishedResource: %v", err)
170+
}
171+
172+
arsName := pr.Status.ResourceSchemaName
173+
if arsName == "" {
174+
t.Fatal("Expected PublishedResource status to contain ARS name, but value is empty.")
173175
}
174176

175177
// update the CRD
176178
t.Logf("Updating CRD (same version, but new schema)…")
177179
utils.ApplyCRD(t, ctx, envtestClient, "test/crds/crontab-improved.yaml")
178180

179-
// give the agent some time to do nothing
180-
time.Sleep(3 * time.Second)
181+
// wait for the 2nd ARS to appear
182+
t.Logf("Waiting for 2nd APIResourceSchema to be created…")
183+
err = wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 1*time.Minute, false, func(ctx context.Context) (done bool, err error) {
184+
schemas := &kcpapisv1alpha1.APIResourceSchemaList{}
185+
err = orgClient.List(ctx, schemas, ctrlruntimeclient.HasLabels{syncagentv1alpha1.AgentNameLabel})
186+
if err != nil {
187+
return false, err
188+
}
181189

182-
// validate that the APIExport has *not* changed
183-
apiExport := &kcpapisv1alpha1.APIExport{}
184-
err = orgClient.Get(ctx, apiExportKey, apiExport)
190+
return len(schemas.Items) == 2, nil
191+
})
185192
if err != nil {
186-
t.Fatalf("APIExport disappeared: %v", err)
193+
t.Fatalf("Failed to wait for 2nd APIResourceSchema to be created: %v", err)
194+
}
195+
196+
if err := envtestClient.Get(ctx, ctrlruntimeclient.ObjectKeyFromObject(pr), pr); err != nil {
197+
t.Fatalf("Failed to fetch PublishedResource: %v", err)
187198
}
188199

189-
if l := len(apiExport.Spec.LatestResourceSchemas); l != 1 {
190-
t.Fatalf("APIExport should still have 1 resource schema, but has %d.", l)
200+
newARSName := pr.Status.ResourceSchemaName
201+
if newARSName == "" {
202+
t.Fatal("Expected PublishedResource status to contain ARS name, but value is empty.")
191203
}
192204

193-
if currentName := apiExport.Spec.LatestResourceSchemas[0]; currentName != arsName {
194-
t.Fatalf("APIExport should still refer to the original ARS %q, but now contains %q.", arsName, currentName)
205+
if newARSName == arsName {
206+
t.Fatalf("Expected PublishedResource status to have been updated with new ARS name, but still contains %q.", arsName)
195207
}
196208
}
197209

0 commit comments

Comments
 (0)