This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split network_test.go into separate test files. Signed-off-by: Archana Shinde <[email protected]>
- Loading branch information
Showing
7 changed files
with
580 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package virtcontainers | ||
|
||
import ( | ||
"net" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestCreateBridgedMacvlanEndpoint(t *testing.T) { | ||
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04} | ||
|
||
expected := &BridgedMacvlanEndpoint{ | ||
NetPair: NetworkInterfacePair{ | ||
ID: "uniqueTestID-4", | ||
Name: "br4_kata", | ||
VirtIface: NetworkInterface{ | ||
Name: "eth4", | ||
HardAddr: macAddr.String(), | ||
}, | ||
TAPIface: NetworkInterface{ | ||
Name: "tap4_kata", | ||
}, | ||
NetInterworkingModel: DefaultNetInterworkingModel, | ||
}, | ||
EndpointType: BridgedMacvlanEndpointType, | ||
} | ||
|
||
result, err := createBridgedMacvlanNetworkEndpoint(4, "", DefaultNetInterworkingModel) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// the resulting ID will be random - so let's overwrite to test the rest of the flow | ||
result.NetPair.ID = "uniqueTestID-4" | ||
|
||
// the resulting mac address will be random - so lets overwrite it | ||
result.NetPair.VirtIface.HardAddr = macAddr.String() | ||
|
||
if reflect.DeepEqual(result, expected) == false { | ||
t.Fatalf("\nGot: %+v, \n\nExpected: %+v", result, expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package virtcontainers | ||
|
||
import "testing" | ||
|
||
func testEndpointTypeSet(t *testing.T, value string, expected EndpointType) { | ||
//var netModel NetworkModel | ||
var endpointType EndpointType | ||
|
||
err := endpointType.Set(value) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if endpointType != expected { | ||
t.Fatal() | ||
} | ||
} | ||
|
||
func TestPhysicalEndpointTypeSet(t *testing.T) { | ||
testEndpointTypeSet(t, "physical", PhysicalEndpointType) | ||
} | ||
|
||
func TestVirtualEndpointTypeSet(t *testing.T) { | ||
testEndpointTypeSet(t, "virtual", VirtualEndpointType) | ||
} | ||
|
||
func TestVhostUserEndpointTypeSet(t *testing.T) { | ||
testEndpointTypeSet(t, "vhost-user", VhostUserEndpointType) | ||
} | ||
|
||
func TestBridgedMacvlanEndpointTypeSet(t *testing.T) { | ||
testEndpointTypeSet(t, "macvlan", BridgedMacvlanEndpointType) | ||
} | ||
|
||
func TestMacvtapEndpointTypeSet(t *testing.T) { | ||
testEndpointTypeSet(t, "macvtap", MacvtapEndpointType) | ||
} | ||
|
||
func TestEndpointTypeSetFailure(t *testing.T) { | ||
var endpointType EndpointType | ||
|
||
err := endpointType.Set("wrong-value") | ||
if err == nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func testEndpointTypeString(t *testing.T, endpointType *EndpointType, expected string) { | ||
result := endpointType.String() | ||
|
||
if result != expected { | ||
t.Fatal() | ||
} | ||
} | ||
|
||
func TestPhysicalEndpointTypeString(t *testing.T) { | ||
endpointType := PhysicalEndpointType | ||
testEndpointTypeString(t, &endpointType, string(PhysicalEndpointType)) | ||
} | ||
|
||
func TestVirtualEndpointTypeString(t *testing.T) { | ||
endpointType := VirtualEndpointType | ||
testEndpointTypeString(t, &endpointType, string(VirtualEndpointType)) | ||
} | ||
|
||
func TestVhostUserEndpointTypeString(t *testing.T) { | ||
endpointType := VhostUserEndpointType | ||
testEndpointTypeString(t, &endpointType, string(VhostUserEndpointType)) | ||
} | ||
|
||
func TestBridgedMacvlanEndpointTypeString(t *testing.T) { | ||
endpointType := BridgedMacvlanEndpointType | ||
testEndpointTypeString(t, &endpointType, string(BridgedMacvlanEndpointType)) | ||
} | ||
|
||
func TestMacvtapEndpointTypeString(t *testing.T) { | ||
endpointType := MacvtapEndpointType | ||
testEndpointTypeString(t, &endpointType, string(MacvtapEndpointType)) | ||
} | ||
|
||
func TestIncorrectEndpointTypeString(t *testing.T) { | ||
var endpointType EndpointType | ||
testEndpointTypeString(t, &endpointType, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package virtcontainers | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestCreateMacvtapEndpoint(t *testing.T) { | ||
netInfo := NetworkInfo{ | ||
Iface: NetlinkIface{ | ||
Type: "macvtap", | ||
}, | ||
} | ||
expected := &MacvtapEndpoint{ | ||
EndpointType: MacvtapEndpointType, | ||
EndpointProperties: netInfo, | ||
} | ||
|
||
result, err := createMacvtapNetworkEndpoint(netInfo) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if reflect.DeepEqual(result, expected) == false { | ||
t.Fatalf("\nGot: %+v, \n\nExpected: %+v", result, expected) | ||
} | ||
} |
Oops, something went wrong.