mirror of
https://github.com/moby/moby.git
synced 2026-08-07 16:41:50 +00:00
To support this, a new netlabel is added: `com.docker.network.endpoint.ifname`. It gives the ability to specify the interface name to be set by netdrivers when the interface is added / moved into the container's network namespace. All builtin netdrivers support it. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
61 lines
971 B
Go
61 lines
971 B
Go
package netlabel
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestGetIfname(t *testing.T) {
|
|
testcases := []struct {
|
|
name string
|
|
opts map[string]interface{}
|
|
expIfname string
|
|
}{
|
|
{
|
|
name: "nil opts",
|
|
opts: nil,
|
|
expIfname: "",
|
|
},
|
|
{
|
|
name: "no ifname",
|
|
opts: map[string]interface{}{},
|
|
expIfname: "",
|
|
},
|
|
{
|
|
name: "ifname set",
|
|
opts: map[string]interface{}{
|
|
Ifname: "foobar",
|
|
},
|
|
expIfname: "foobar",
|
|
},
|
|
{
|
|
name: "ifname set to empty string",
|
|
opts: map[string]interface{}{
|
|
Ifname: "",
|
|
},
|
|
expIfname: "",
|
|
},
|
|
{
|
|
name: "ifname set to nil",
|
|
opts: map[string]interface{}{
|
|
Ifname: nil,
|
|
},
|
|
expIfname: "",
|
|
},
|
|
{
|
|
name: "ifname set to int",
|
|
opts: map[string]interface{}{
|
|
Ifname: 42,
|
|
},
|
|
expIfname: "",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testcases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
assert.Equal(t, tc.expIfname, GetIfname(tc.opts))
|
|
})
|
|
}
|
|
}
|