Skip to content

Commit

Permalink
Add EnsureBackendService test
Browse files Browse the repository at this point in the history
  • Loading branch information
akwi committed Aug 22, 2024
1 parent 107bab6 commit d991dda
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions e2e/backend_service_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,69 @@ func TestBackendServiceUpdate(t *testing.T) {
wantBS = &compute.BackendService{LoadBalancingScheme: "INTERNAL_MANAGED"}
checkBackendService(t, ctx, theCloud, bs1ID, wantBS, compareLBScheme)
}

func TestEnsureBackendService(t *testing.T) {
t.Parallel()
ctx := context.Background()

resUniqueId := "ensure-bs-test"
graphBuilder := rgraph.NewBuilder()
hcID, err := buildHealthCheck(graphBuilder, resUniqueId+"-hc", 15)
if err != nil {
t.Fatalf("buildHealthCheck(_, %s-hc, 15) = (_, %v), want (_, nil)", resUniqueId, err)
}
bsID, err := buildBackendServiceWithLBScheme(graphBuilder, resUniqueId+"-bs", hcID, "INTERNAL_SELF_MANAGED")
if err != nil {
t.Fatalf("buildBackendServiceWithLBScheme(_, %s, _) = %v, want nil", resUniqueId+"-bs", err)
}
expectedActions := []exec.ActionMetadata{
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, bsID)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, hcID)},
}

graph, err := graphBuilder.Build()
if err != nil {
t.Fatalf("graphBuilder.Build() = %v want nil", err)
}

result, err := plan.Do(ctx, theCloud, graph)
if err != nil {
t.Fatalf("plan.Do(_, _, _) = %v, want nil", err)
}

t.Logf("\nPlan.Actions: %v", result.Actions)
t.Logf("\nPlan.Got: %v", result.Got)
t.Logf("\nPlan.Want: %v", result.Want)

err = expectActions(result.Actions, expectedActions)
if err != nil {
t.Fatalf("expectActions(_, _) = %v, want nil", err)
}

processGraphAndExpectActions(t, graphBuilder, expectedActions)
checkGCEBackendService(t, ctx, theCloud, hcID, bsID, 80)

expectedActions = []exec.ActionMetadata{
{Type: exec.ActionTypeMeta, Name: eventName(bsID)},
{Type: exec.ActionTypeMeta, Name: eventName(hcID)},
}

graph, err = graphBuilder.Build()
if err != nil {
t.Fatalf("graphBuilder.Build() = %v want nil", err)
}

result, err = plan.Do(ctx, theCloud, graph)
if err != nil {
t.Fatalf("plan.Do(_, _, _) = %v, want nil", err)
}

t.Logf("\nPlan.Actions: %v", result.Actions)
t.Logf("\nPlan.Got: %v", result.Got)
t.Logf("\nPlan.Want: %v", result.Want)

err = expectActions(result.Actions, expectedActions)
if err != nil {
t.Fatalf("expectActions(_, _) = %v, want nil", err)
}
}

0 comments on commit d991dda

Please sign in to comment.