forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathveth_endpoint_test.go
105 lines (85 loc) · 2.46 KB
/
veth_endpoint_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//go:build linux
// +build linux
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateVethNetworkEndpoint(t *testing.T) {
assert := assert.New(t)
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04}
expected := &VethEndpoint{
NetPair: NetworkInterfacePair{
TapInterface: TapInterface{
ID: "uniqueTestID-4",
Name: "br4_kata",
TAPIface: NetworkInterface{
Name: "tap4_kata",
},
},
VirtIface: NetworkInterface{
Name: "eth4",
HardAddr: macAddr.String(),
},
NetInterworkingModel: DefaultNetInterworkingModel,
},
EndpointType: VethEndpointType,
}
result, err := createVethNetworkEndpoint(4, "", DefaultNetInterworkingModel)
assert.NoError(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()
assert.Exactly(result, expected)
}
func TestCreateVethNetworkEndpointChooseIfaceName(t *testing.T) {
assert := assert.New(t)
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04}
expected := &VethEndpoint{
NetPair: NetworkInterfacePair{
TapInterface: TapInterface{
ID: "uniqueTestID-4",
Name: "br4_kata",
TAPIface: NetworkInterface{
Name: "tap4_kata",
},
},
VirtIface: NetworkInterface{
Name: "eth1",
HardAddr: macAddr.String(),
},
NetInterworkingModel: DefaultNetInterworkingModel,
},
EndpointType: VethEndpointType,
}
result, err := createVethNetworkEndpoint(4, "eth1", DefaultNetInterworkingModel)
assert.NoError(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()
assert.Exactly(result, expected)
}
func TestCreateVethNetworkEndpointInvalidArgs(t *testing.T) {
// nolint: govet
type endpointValues struct {
idx int
ifName string
}
assert := assert.New(t)
// all elements are expected to result in failure
failingValues := []endpointValues{
{-1, "bar"},
{-1, ""},
}
for _, d := range failingValues {
_, err := createVethNetworkEndpoint(d.idx, d.ifName, DefaultNetInterworkingModel)
assert.Error(err)
}
}