Skip to content

Commit

Permalink
Merge pull request #183 from AwesomePatrol/fix-tcproute-test
Browse files Browse the repository at this point in the history
Fix TCP Route test
  • Loading branch information
google-oss-prow[bot] authored Apr 17, 2024
2 parents 7e8e3d8 + 72a3f0f commit abfa33a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
34 changes: 23 additions & 11 deletions e2e/tcproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ import (

const (
meshName = "test-mesh"
negName = "k8s1-3894226e-default-foo-backend-80-28ec9cf3"
negName2 = "k8s1-54982af5-default-bar-svc-8080-5aabd6b1"
zone = "us-central1-c"
region = "us-central1"
zone = region + "-c"
routeCIDR = "10.240.3.83/32"
routeCIRD2 = "10.240.4.83/32"
)
Expand Down Expand Up @@ -114,18 +113,23 @@ func TestTcpRoute(t *testing.T) {
}

func buildNEG(graphBuilder *rgraph.Builder, name, zone string) (*cloud.ResourceID, error) {
negID := networkendpointgroup.ID(testFlags.project, meta.ZonalKey(name, zone))
negID := networkendpointgroup.ID(testFlags.project, meta.ZonalKey(resourceName(name), zone))
negMut := networkendpointgroup.NewMutableNetworkEndpointGroup(testFlags.project, negID.Key)
negMut.Access(func(x *compute.NetworkEndpointGroup) {
x.Zone = zone
x.NetworkEndpointType = "GCE_VM_IP_PORT"
x.Name = negID.Key.Name
x.Network = defaultNetworkURL()
x.Subnetwork = defaultSubnetworkURL()
x.Description = "neg for rGraph test"
})

negRes, err := negMut.Freeze()
if err != nil {
return nil, err
}
negBuilder := networkendpointgroup.NewBuilder(negID)
negBuilder.SetOwnership(rnode.OwnershipExternal)
negBuilder.SetOwnership(rnode.OwnershipManaged)
negBuilder.SetState(rnode.NodeExists)
negBuilder.SetResource(negRes)
graphBuilder.Add(negBuilder)
Expand Down Expand Up @@ -294,10 +298,14 @@ func TestRgraphTCPRouteAddBackends(t *testing.T) {
t.Logf("theCloud.Meshes().Delete(ctx, %s): %v", meshKey, err)
})
graphBuilder := rgraph.NewBuilder()
negID, err := buildNEG(graphBuilder, negName, zone)
negID, err := buildNEG(graphBuilder, "neg-test", zone)
if err != nil {
t.Fatalf("buildNEG(_, %s, %s) = (_, %v), want (_, nil)", negName, zone, err)
t.Fatalf("buildNEG(_, neg-test, %s) = (_, %v), want (_, nil)", zone, err)
}
t.Cleanup(func() {
err := theCloud.NetworkEndpointGroups().Delete(ctx, negID.Key)
t.Logf("theCloud.NetworkEndpointGroups().Delete(ctx, %s): %v", negID.Key, err)
})

hcID, err := buildHealthCheck(graphBuilder, "hc-test", 15)
if err != nil {
Expand Down Expand Up @@ -330,16 +338,20 @@ func TestRgraphTCPRouteAddBackends(t *testing.T) {
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, tcprID)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, bsID)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, hcID)},
{Type: exec.ActionTypeMeta, Name: eventName(negID)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, negID)},
}
processGraphAndExpectActions(t, graphBuilder, expectedActions)

checkGCEBackendService(t, ctx, theCloud, hcID, bsID, 80)
checkAppNetTCPRoute(t, ctx, theCloud, tcprID.Key.Name, meshURL, bsID)
negID2, err := buildNEG(graphBuilder, negName2, zone)
negID2, err := buildNEG(graphBuilder, "neg-test-2", zone)
if err != nil {
t.Fatalf("buildNEG(_, %s, %s) = (_, %v), want (_, nil)", negName2, zone, err)
t.Fatalf("buildNEG(_, neg-test-2, %s) = (_, %v), want (_, nil)", zone, err)
}
t.Cleanup(func() {
err := theCloud.NetworkEndpointGroups().Delete(ctx, negID2.Key)
t.Logf("theCloud.NetworkEndpointGroups().Delete(ctx, %s): %v", negID2.Key, err)
})

hcID2, err := buildHealthCheck(graphBuilder, "hc-test-2", 15)
if err != nil {
Expand Down Expand Up @@ -370,8 +382,8 @@ func TestRgraphTCPRouteAddBackends(t *testing.T) {
{Type: exec.ActionTypeUpdate, Name: actionName(exec.ActionTypeUpdate, tcprID)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, bsID2)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, hcID2)},
{Type: exec.ActionTypeCreate, Name: actionName(exec.ActionTypeCreate, negID2)},
{Type: exec.ActionTypeMeta, Name: eventName(negID)},
{Type: exec.ActionTypeMeta, Name: eventName(negID2)},
{Type: exec.ActionTypeMeta, Name: eventName(bsID)},
{Type: exec.ActionTypeMeta, Name: eventName(hcID)},
}
Expand Down
8 changes: 8 additions & 0 deletions e2e/test-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,11 @@ Outer:
t.Fatalf("Rule ServiceName %s, not found in expected: %v", rule.Action.Destinations[0].ServiceName, svcIds)
}
}

func defaultNetworkURL() string {
return cloud.NewNetworksResourceID(testFlags.project, "default").SelfLink(meta.VersionGA)
}

func defaultSubnetworkURL() string {
return cloud.NewSubnetworksResourceID(testFlags.project, region, "default").SelfLink(meta.VersionGA)
}

0 comments on commit abfa33a

Please sign in to comment.