Skip to content

Commit

Permalink
Use runCollect in e2e tests more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Sep 29, 2021
1 parent 3544d7d commit a296437
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 68 deletions.
9 changes: 2 additions & 7 deletions test/e2e/apply_and_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ func applyAndDestroyTest(c client.Client, invConfig InventoryConfig, inventoryNa
withNamespace(manifestToUnstructured(deployment1), namespaceName),
}

applyCh := applier.Run(context.TODO(), inventoryInfo, resources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), inventoryInfo, resources, apply.Options{
ReconcileTimeout: 2 * time.Minute,
EmitStatusEvents: true,
})

var applierEvents []event.Event
for e := range applyCh {
applierEvents = append(applierEvents, e)
}
}))

expEvents := []testutil.ExpEvent{
{
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/continue_on_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ func continueOnErrorTest(c client.Client, invConfig InventoryConfig, inventoryNa
withNamespace(manifestToUnstructured(pod1), namespaceName),
}

ch := applier.Run(context.TODO(), inv, resources, apply.Options{})

var applierEvents []event.Event
for e := range ch {
applierEvents = append(applierEvents, e)
}
applierEvents := runCollect(applier.Run(context.TODO(), inv, resources, apply.Options{}))

expEvents := []testutil.ExpEvent{
{
Expand Down
9 changes: 2 additions & 7 deletions test/e2e/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ func crdTest(_ client.Client, invConfig InventoryConfig, inventoryName, namespac
manifestToUnstructured(crd),
}

ch := applier.Run(context.TODO(), inv, resources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), inv, resources, apply.Options{
ReconcileTimeout: 2 * time.Minute,
EmitStatusEvents: false,
})

var applierEvents []event.Event
for e := range ch {
applierEvents = append(applierEvents, e)
}
}))

expEvents := []testutil.ExpEvent{
{
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/depends_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ func dependsOnTest(c client.Client, invConfig InventoryConfig, inventoryName, na
withDependsOn(withNamespace(manifestToUnstructured(pod3), namespaceName), fmt.Sprintf("/namespaces/%s/Pod/pod2", namespaceName)),
}

ch := applier.Run(context.TODO(), inv, resources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), inv, resources, apply.Options{
EmitStatusEvents: false,
})
}))

var applierEvents []event.Event
for e := range ch {
applierEvents = append(applierEvents, e)
}
expEvents := []testutil.ExpEvent{
{
// InitTask
Expand Down
33 changes: 9 additions & 24 deletions test/e2e/inventory_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,11 @@ func inventoryPolicyMustMatchTest(c client.Client, invConfig InventoryConfig, na
withReplicas(withNamespace(manifestToUnstructured(deployment1), namespaceName), 6),
}

ch := applier.Run(context.TODO(), secondInv, secondResources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), secondInv, secondResources, apply.Options{
ReconcileTimeout: 2 * time.Minute,
EmitStatusEvents: true,
InventoryPolicy: inventory.InventoryPolicyMustMatch,
})

var events []event.Event
for e := range ch {
events = append(events, e)
}
}))

By("Verify the events")
expEvents := []testutil.ExpEvent{
Expand Down Expand Up @@ -143,7 +138,7 @@ func inventoryPolicyMustMatchTest(c client.Client, invConfig InventoryConfig, na
},
},
}
received := testutil.EventsToExpEvents(events)
received := testutil.EventsToExpEvents(applierEvents)

// handle optional async InProgress StatusEvents
expected := testutil.ExpEvent{
Expand Down Expand Up @@ -194,16 +189,11 @@ func inventoryPolicyAdoptIfNoInventoryTest(c client.Client, invConfig InventoryC
withReplicas(withNamespace(manifestToUnstructured(deployment1), namespaceName), 6),
}

ch := applier.Run(context.TODO(), inv, resources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), inv, resources, apply.Options{
ReconcileTimeout: 2 * time.Minute,
EmitStatusEvents: true,
InventoryPolicy: inventory.AdoptIfNoInventory,
})

var events []event.Event
for e := range ch {
events = append(events, e)
}
}))

By("Verify the events")
expEvents := []testutil.ExpEvent{
Expand Down Expand Up @@ -296,7 +286,7 @@ func inventoryPolicyAdoptIfNoInventoryTest(c client.Client, invConfig InventoryC
}

// handle optional async InProgress StatusEvents
received := testutil.EventsToExpEvents(events)
received := testutil.EventsToExpEvents(applierEvents)
expected := testutil.ExpEvent{
EventType: event.StatusType,
StatusEvent: &testutil.ExpStatusEvent{
Expand Down Expand Up @@ -360,16 +350,11 @@ func inventoryPolicyAdoptAllTest(c client.Client, invConfig InventoryConfig, nam
withReplicas(withNamespace(manifestToUnstructured(deployment1), namespaceName), 6),
}

ch := applier.Run(context.TODO(), secondInv, secondResources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), secondInv, secondResources, apply.Options{
ReconcileTimeout: 2 * time.Minute,
EmitStatusEvents: true,
InventoryPolicy: inventory.AdoptAll,
})

var events []event.Event
for e := range ch {
events = append(events, e)
}
}))

By("Verify the events")
expEvents := []testutil.ExpEvent{
Expand Down Expand Up @@ -462,7 +447,7 @@ func inventoryPolicyAdoptAllTest(c client.Client, invConfig InventoryConfig, nam
}

// handle optional async InProgress StatusEvents
received := testutil.EventsToExpEvents(events)
received := testutil.EventsToExpEvents(applierEvents)
expected := testutil.ExpEvent{
EventType: event.StatusType,
StatusEvent: &testutil.ExpStatusEvent{
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ func mutationTest(c client.Client, invConfig InventoryConfig, inventoryName, nam
withNamespace(manifestToUnstructured(podB), namespaceName),
}

ch := applier.Run(context.TODO(), inv, resources, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), inv, resources, apply.Options{
EmitStatusEvents: false,
})
}))

var applierEvents []event.Event
for e := range ch {
applierEvents = append(applierEvents, e)
}
expEvents := []testutil.ExpEvent{
{
// InitTask
Expand Down
16 changes: 4 additions & 12 deletions test/e2e/prune_retrieve_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ func pruneRetrieveErrorTest(c client.Client, invConfig InventoryConfig, inventor
withNamespace(manifestToUnstructured(pod1), namespaceName),
}

ch := applier.Run(context.TODO(), inv, resource1, apply.Options{
applierEvents := runCollect(applier.Run(context.TODO(), inv, resource1, apply.Options{
EmitStatusEvents: false,
})
}))

var applierEvents []event.Event
for e := range ch {
applierEvents = append(applierEvents, e)
}
expEvents := []testutil.ExpEvent{
{
// InitTask
Expand Down Expand Up @@ -145,14 +141,10 @@ func pruneRetrieveErrorTest(c client.Client, invConfig InventoryConfig, inventor
withNamespace(manifestToUnstructured(pod2), namespaceName),
}

ch = applier.Run(context.TODO(), inv, resource2, apply.Options{
applierEvents2 := runCollect(applier.Run(context.TODO(), inv, resource2, apply.Options{
EmitStatusEvents: false,
})
}))

var applierEvents2 []event.Event
for e := range ch {
applierEvents2 = append(applierEvents2, e)
}
expEvents2 := []testutil.ExpEvent{
{
// InitTask
Expand Down

0 comments on commit a296437

Please sign in to comment.