Skip to content

Commit

Permalink
Add unit test for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jwayong committed May 21, 2017
1 parent 4fa5bd5 commit bbfa085
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ func TestInspectContainerNetwork(t *testing.T) {
"MacAddress": "",
"Networks": {
"swl-net": {
"Aliases": [
"testalias",
"81e1bbe20b55"
],
"NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812",
"EndpointID": "683e3092275782a53c3b0968cc7e3a10f23264022ded9cb20490902f96fc5981",
"Gateway": "",
Expand All @@ -625,6 +629,8 @@ func TestInspectContainerNetwork(t *testing.T) {
id := "81e1bbe20b55"
expIP := "10.0.0.3"
expNetworkID := "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812"
expAlias0 = "testalias"
expAlias1 = "81e1bbe20b55"

container, err := client.InspectContainer(id)
if err != nil {
Expand Down Expand Up @@ -652,6 +658,17 @@ func TestInspectContainerNetwork(t *testing.T) {
t.Logf("%s %v", net, networkID)
}
}

var aliases []string
for _, net := range networks.MapKeys() {
if net.Interface().(string) == container.HostConfig.NetworkMode {
aliases = networks.MapIndex(net).FieldByName("Aliases").Interface().([]string)
}
}
if aliases[0] != expAlias0 || aliases[1] != expAlias1 {
t.Errorf("InspectContainerNetworks(%q): Expected Alias0 %s. Got %s, Alias1 %s. Got %s", id, expAlias0, aliases[0], expAlias1, aliases[1])
}

if networkID != expNetworkID {
t.Errorf("InspectContainerNetworks(%q): Expected %#v. Got %#v.", id, expNetworkID, networkID)
}
Expand Down

0 comments on commit bbfa085

Please sign in to comment.