Skip to content

Commit

Permalink
Update names of ncproxy proxy resources with test name included
Browse files Browse the repository at this point in the history
Signed-off-by: Kathryn Baldauf <[email protected]>
  • Loading branch information
katiewasnothere committed Oct 5, 2021
1 parent 851b2a5 commit 6ad0944
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 52 deletions.
99 changes: 55 additions & 44 deletions cmd/ncproxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func createTestEndpoint(name, networkID string) (*hcn.HostComputeEndpoint, error
return endpoint.Create()
}

func createTestNATNetwork() (*hcn.HostComputeNetwork, error) {
func createTestNATNetwork(name string) (*hcn.HostComputeNetwork, error) {
ipam := hcn.Ipam{
Type: "Static",
Subnets: getTestSubnets(),
}
ipams := []hcn.Ipam{ipam}
network := &hcn.HostComputeNetwork{
Type: hcn.NAT,
Name: "test-nat-network-name",
Name: name,
MacPool: hcn.MacPool{
Ranges: []hcn.MacRange{
{
Expand All @@ -99,9 +99,9 @@ func TestAddNIC(t *testing.T) {
gService := newGRPCService(agentCache)

var (
containerID = "test-container"
testNICID = "test-nic-id"
testEndpointName = "test-endpoint-name"
containerID = t.Name() + "-containerID"
testNICID = t.Name() + "-nicID"
testEndpointName = t.Name() + "-endpoint"
)

// create mocked compute agent service
Expand Down Expand Up @@ -181,9 +181,9 @@ func TestDeleteNIC(t *testing.T) {
gService := newGRPCService(agentCache)

var (
containerID = "test-container"
testNICID = "test-nic-id"
testEndpointName = "test-endpoint-name"
containerID = t.Name() + "-containerID"
testNICID = t.Name() + "-nicID"
testEndpointName = t.Name() + "-endpoint"
)

// create mocked compute agent service
Expand Down Expand Up @@ -266,8 +266,8 @@ func TestModifyNIC(t *testing.T) {
gService := newGRPCService(agentCache)

var (
containerID = "test-container"
testNICID = "test-nic-id"
containerID = t.Name() + "-containerID"
testNICID = t.Name() + "-nicID"
)

// create mock compute agent service
Expand All @@ -282,7 +282,8 @@ func TestModifyNIC(t *testing.T) {
mockedService.EXPECT().ModifyNIC(gomock.Any(), gomock.Any()).Return(&computeagent.ModifyNICInternalResponse{}, nil).AnyTimes()

// create test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
Expand All @@ -291,7 +292,7 @@ func TestModifyNIC(t *testing.T) {
}()

// create test endpoint
endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
endpoint, err := createTestEndpoint(endpointName, network.Id)
if err != nil {
t.Fatalf("failed to create test endpoint with %v", err)
Expand Down Expand Up @@ -400,7 +401,7 @@ func TestCreateNetwork(t *testing.T) {
tests := []config{
{
name: "CreateNetwork returns no error",
networkName: "test-network-name",
networkName: t.Name() + "-network",
errorExpected: false,
},
{
Expand Down Expand Up @@ -432,7 +433,7 @@ func TestCreateNetwork(t *testing.T) {
}
// cleanup the created network
if err = network.Delete(); err != nil {
t.Fatalf("failed to cleanup network %v created by test with %v", network.Name, err)
t.Fatalf("failed to cleanup network %v created by test with %v", test.networkName, err)
}
}
})
Expand All @@ -447,7 +448,8 @@ func TestCreateEndpoint(t *testing.T) {
gService := newGRPCService(agentCache)

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
Expand All @@ -466,7 +468,7 @@ func TestCreateEndpoint(t *testing.T) {
tests := []config{
{
name: "CreateEndpoint returns no error",
networkName: network.Name,
networkName: networkName,
ipaddress: "192.168.100.4",
macaddress: "00-15-5D-52-C0-00",
errorExpected: false,
Expand All @@ -480,14 +482,14 @@ func TestCreateEndpoint(t *testing.T) {
},
{
name: "CreateEndpoint returns error when ip address is empty",
networkName: network.Name,
networkName: networkName,
ipaddress: "",
macaddress: "00-15-5D-52-C0-00",
errorExpected: true,
},
{
name: "CreateEndpoint returns error when mac address is empty",
networkName: network.Name,
networkName: networkName,
ipaddress: "192.168.100.4",
macaddress: "",
errorExpected: true,
Expand All @@ -496,7 +498,7 @@ func TestCreateEndpoint(t *testing.T) {

for i, test := range tests {
t.Run(test.name, func(_ *testing.T) {
endpointName := "test-endpoint-name-" + strconv.Itoa(i)
endpointName := t.Name() + "-endpoint-" + strconv.Itoa(i)
req := &ncproxygrpc.CreateEndpointRequest{
Name: endpointName,
Macaddress: test.macaddress,
Expand Down Expand Up @@ -545,15 +547,16 @@ func TestAddEndpoint_NoError(t *testing.T) {
}()

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
defer func() {
_ = network.Delete()
}()

endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
endpoint, err := createTestEndpoint(endpointName, network.Id)
if err != nil {
t.Fatalf("failed to create test endpoint with %v", err)
Expand Down Expand Up @@ -627,7 +630,7 @@ func TestAddEndpoint_Error_NoEndpoint(t *testing.T) {
}()

req := &ncproxygrpc.AddEndpointRequest{
Name: "test-endpoint-name",
Name: t.Name() + "-endpoint",
NamespaceID: namespace.Id,
}

Expand All @@ -645,15 +648,16 @@ func TestAddEndpoint_Error_EmptyNamespaceID(t *testing.T) {
gService := newGRPCService(agentCache)

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
defer func() {
_ = network.Delete()
}()

endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
endpoint, err := createTestEndpoint(endpointName, network.Id)
if err != nil {
t.Fatalf("failed to create test endpoint with %v", err)
Expand Down Expand Up @@ -681,15 +685,16 @@ func TestDeleteEndpoint_NoError(t *testing.T) {
gService := newGRPCService(agentCache)

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
defer func() {
_ = network.Delete()
}()

endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
endpoint, err := createTestEndpoint(endpointName, network.Id)
if err != nil {
t.Fatalf("failed to create test endpoint with %v", err)
Expand Down Expand Up @@ -722,15 +727,16 @@ func TestDeleteEndpoint_Error_NoEndpoint(t *testing.T) {
gService := newGRPCService(agentCache)

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
defer func() {
_ = network.Delete()
}()

endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
req := &ncproxygrpc.DeleteEndpointRequest{
Name: endpointName,
}
Expand Down Expand Up @@ -767,7 +773,8 @@ func TestDeleteNetwork_NoError(t *testing.T) {
gService := newGRPCService(agentCache)

// create the test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
Expand All @@ -778,7 +785,7 @@ func TestDeleteNetwork_NoError(t *testing.T) {
}()

req := &ncproxygrpc.DeleteNetworkRequest{
Name: network.Name,
Name: networkName,
}
_, err = gService.DeleteNetwork(ctx, req)
if err != nil {
Expand All @@ -793,7 +800,7 @@ func TestDeleteNetwork_Error_NoNetwork(t *testing.T) {
agentCache := newComputeAgentCache()
gService := newGRPCService(agentCache)

fakeNetworkName := "test-network-name"
fakeNetworkName := t.Name() + "-network"

req := &ncproxygrpc.DeleteNetworkRequest{
Name: fakeNetworkName,
Expand Down Expand Up @@ -828,15 +835,16 @@ func TestGetEndpoint_NoError(t *testing.T) {
gService := newGRPCService(agentCache)

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
defer func() {
_ = network.Delete()
}()

endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
endpoint, err := createTestEndpoint(endpointName, network.Id)
if err != nil {
t.Fatalf("failed to create test endpoint with %v", err)
Expand All @@ -861,7 +869,7 @@ func TestGetEndpoint_Error_NoEndpoint(t *testing.T) {
agentCache := newComputeAgentCache()
gService := newGRPCService(agentCache)

endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
req := &ncproxygrpc.GetEndpointRequest{
Name: endpointName,
}
Expand Down Expand Up @@ -895,7 +903,8 @@ func TestGetEndpoints_NoError(t *testing.T) {
gService := newGRPCService(agentCache)

// test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
Expand All @@ -904,7 +913,7 @@ func TestGetEndpoints_NoError(t *testing.T) {
}()

// test endpoint
endpointName := "test-endpoint-name"
endpointName := t.Name() + "-endpoint"
endpoint, err := createTestEndpoint(endpointName, network.Id)
if err != nil {
t.Fatalf("failed to create test endpoint with %v", err)
Expand Down Expand Up @@ -932,7 +941,8 @@ func TestGetNetwork_NoError(t *testing.T) {
gService := newGRPCService(agentCache)

// create the test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
Expand All @@ -943,7 +953,7 @@ func TestGetNetwork_NoError(t *testing.T) {
}()

req := &ncproxygrpc.GetNetworkRequest{
Name: network.Name,
Name: networkName,
}
_, err = gService.GetNetwork(ctx, req)
if err != nil {
Expand All @@ -958,7 +968,7 @@ func TestGetNetwork_Error_NoNetwork(t *testing.T) {
agentCache := newComputeAgentCache()
gService := newGRPCService(agentCache)

fakeNetworkName := "test-network-name"
fakeNetworkName := t.Name() + "-network"

req := &ncproxygrpc.GetNetworkRequest{
Name: fakeNetworkName,
Expand Down Expand Up @@ -993,7 +1003,8 @@ func TestGetNetworks_NoError(t *testing.T) {
gService := newGRPCService(agentCache)

// create the test network
network, err := createTestNATNetwork()
networkName := t.Name() + "-network"
network, err := createTestNATNetwork(networkName)
if err != nil {
t.Fatalf("failed to create test network with %v", err)
}
Expand All @@ -1008,7 +1019,7 @@ func TestGetNetworks_NoError(t *testing.T) {
if err != nil {
t.Fatalf("expected no error, instead got %v", err)
}
if !networkExists(network.Name, resp.Networks) {
if !networkExists(networkName, resp.Networks) {
t.Fatalf("failed to find created network")
}
}
Expand All @@ -1029,9 +1040,9 @@ func TestRegisterComputeAgent(t *testing.T) {
return &ttrpc.Client{}
}

containerID := "test-container-id"
containerID := t.Name() + "-containerID"
req := &ncproxyttrpc.RegisterComputeAgentRequest{
AgentAddress: "test-agent-address",
AgentAddress: t.Name() + "-agent-address",
ContainerID: containerID,
}
if _, err := tService.RegisterComputeAgent(ctx, req); err != nil {
Expand Down Expand Up @@ -1067,7 +1078,7 @@ func TestConfigureNetworking(t *testing.T) {
requestType ncproxyttrpc.RequestTypeInternal
errorExpected bool
}
containerID := "test-container-id"
containerID := t.Name() + "-containerID"
tests := []config{
{
name: "Configure Networking setup returns no error",
Expand Down
Loading

0 comments on commit 6ad0944

Please sign in to comment.