Skip to content

Commit

Permalink
refactor: use SkipWaitForDelete
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Pana <[email protected]>
  • Loading branch information
acpana committed Mar 26, 2024
1 parent 3af9ce4 commit 15d70be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
4 changes: 2 additions & 2 deletions config/tests/samples/create/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type Harness struct {
*testing.T
Ctx context.Context

Events *test.MemoryEventSink
Project testgcp.GCPProject
Events *test.MemoryEventSink
Project testgcp.GCPProject
VCRRecorder *recorder.Recorder

client client.Client
Expand Down
11 changes: 0 additions & 11 deletions config/tests/samples/create/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,6 @@ func DeleteResources(t *Harness, opts CreateDeleteTestOptions) {
wg.Wait()
}

func DeleteResourceWithoutWaitingForReady(t *Harness, u *unstructured.Unstructured) {
logger := log.FromContext(t.Ctx)

logger.Info("Deleting resource", "kind", u.GetKind(), "name", u.GetName())
if err := t.GetClient().Delete(t.Ctx, u); err != nil {
if !apierrors.IsNotFound(err) {
t.Errorf("error deleting: %v", err)
}
}
}

func waitForDeleteToComplete(t *Harness, wg *sync.WaitGroup, u *unstructured.Unstructured) {
defer log.FromContext(t.Ctx).Info("Done waiting for resource to delete", "kind", u.GetKind(), "name", u.GetName())
defer wg.Done()
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestE2EScript(t *testing.T) {
create.SetupNamespacesAndApplyDefaults(h, script.Objects, project)

t.Cleanup(func() {
create.DeleteResources(h, script.Objects)
create.DeleteResources(h, create.CreateDeleteTestOptions{Create: script.Objects})
})

var eventsByStep [][]*test.LogEntry
Expand All @@ -98,12 +98,12 @@ func TestE2EScript(t *testing.T) {
create.WaitForReady(h, obj)

case "DELETE":
create.DeleteResources(h, []*unstructured.Unstructured{obj})
create.DeleteResources(h, create.CreateDeleteTestOptions{Create: []*unstructured.Unstructured{obj}})
exportResource = nil
shouldGetKubeObject = false

case "DELETE-NO-WAIT":
create.DeleteResourceWithoutWaitingForReady(h, obj)
create.DeleteResources(h, create.CreateDeleteTestOptions{Create: []*unstructured.Unstructured{obj}, SkipWaitForDelete: true})

// Allow some time for reconcile
// Maybe we should instead wait for observedState
Expand All @@ -115,7 +115,7 @@ func TestE2EScript(t *testing.T) {

case "ABANDON":
setAnnotation(h, obj, "cnrm.cloud.google.com/deletion-policy", "abandon")
create.DeleteResources(h, []*unstructured.Unstructured{obj})
create.DeleteResources(h, create.CreateDeleteTestOptions{Create: []*unstructured.Unstructured{obj}})
// continue to export the resource
shouldGetKubeObject = false

Expand Down Expand Up @@ -192,7 +192,7 @@ func TestE2EScript(t *testing.T) {

}

create.DeleteResources(h, script.Objects)
create.DeleteResources(h, create.CreateDeleteTestOptions{Create: script.Objects})

h.NoExtraGoldenFiles(filepath.Join(script.SourceDir, "_*.yaml"))
})
Expand Down

0 comments on commit 15d70be

Please sign in to comment.