Skip to content

Commit

Permalink
Use test CRDs with OpenAPI schema in testenv
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed May 30, 2022
1 parent b74e38d commit b5d1d11
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/test/envtest/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func newEnvironment(uncachedObjs ...client.Object) *Environment {
builder.GenericInfrastructureClusterTemplateCRD.DeepCopy(),
builder.GenericRemediationCRD.DeepCopy(),
builder.GenericRemediationTemplateCRD.DeepCopy(),
builder.TestInfrastructureClusterCRD.DeepCopy(),
builder.TestInfrastructureMachineTemplateCRD.DeepCopy(),
builder.TestInfrastructureMachineCRD.DeepCopy(),
builder.TestBootstrapConfigTemplateCRD.DeepCopy(),
builder.TestBootstrapConfigCRD.DeepCopy(),
builder.TestControlPlaneCRD.DeepCopy(),
},
// initialize webhook here to be able to test the envtest install via webhookOptions
// This should set LocalServingCertDir and LocalServingPort that are used below.
Expand Down Expand Up @@ -384,11 +390,16 @@ func (e *Environment) CreateAndWait(ctx context.Context, obj client.Object, opts
return nil
}

// PatchAndWait patches the given object and waits for the cache to be updated accordingly.
//
// NOTE: Waiting for the cache to be updated helps in preventing test flakes due to the cache sync delays.
func (e *Environment) PatchAndWait(ctx context.Context, obj client.Object, opts ...client.PatchOption) error {
if err := e.Client.Patch(ctx, obj, client.Apply, opts...); err != nil {
return err
}

// TODO: get current object, if any --> store resourceVersion

// Makes sure the cache is updated with the new object
objCopy := obj.DeepCopyObject().(client.Object)
key := client.ObjectKeyFromObject(obj)
Expand All @@ -401,6 +412,7 @@ func (e *Environment) PatchAndWait(ctx context.Context, obj client.Object, opts
}
return false, err
}
// TODO: check resource version is changes
return true, nil
}); err != nil {
return errors.Wrapf(err, "object %s, %s is not being added to the testenv client cache", obj.GetObjectKind().GroupVersionKind().String(), key)
Expand Down

0 comments on commit b5d1d11

Please sign in to comment.