2016-12-05 21:14:08 +00:00
|
|
|
package convert
|
2016-11-30 20:33:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
composetypes "github.com/aanand/compose-file/types"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/network"
|
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNamespaceScope(t *testing.T) {
|
|
|
|
scoped := Namespace{name: "foo"}.Scope("bar")
|
|
|
|
assert.Equal(t, scoped, "foo_bar")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddStackLabel(t *testing.T) {
|
|
|
|
labels := map[string]string{
|
|
|
|
"something": "labeled",
|
|
|
|
}
|
|
|
|
actual := AddStackLabel(Namespace{name: "foo"}, labels)
|
|
|
|
expected := map[string]string{
|
|
|
|
"something": "labeled",
|
2016-11-30 21:34:29 +00:00
|
|
|
LabelNamespace: "foo",
|
2016-11-30 20:33:54 +00:00
|
|
|
}
|
|
|
|
assert.DeepEqual(t, actual, expected)
|
|
|
|
}
|
|
|
|
|
2016-12-05 21:14:08 +00:00
|
|
|
func TestNetworks(t *testing.T) {
|
2016-11-30 20:33:54 +00:00
|
|
|
namespace := Namespace{name: "foo"}
|
2016-12-01 18:15:18 +00:00
|
|
|
source := networkMap{
|
2016-11-30 20:33:54 +00:00
|
|
|
"normal": composetypes.NetworkConfig{
|
|
|
|
Driver: "overlay",
|
|
|
|
DriverOpts: map[string]string{
|
|
|
|
"opt": "value",
|
|
|
|
},
|
|
|
|
Ipam: composetypes.IPAMConfig{
|
|
|
|
Driver: "driver",
|
|
|
|
Config: []*composetypes.IPAMPool{
|
|
|
|
{
|
|
|
|
Subnet: "10.0.0.0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Labels: map[string]string{
|
|
|
|
"something": "labeled",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"outside": composetypes.NetworkConfig{
|
|
|
|
External: composetypes.External{
|
|
|
|
External: true,
|
|
|
|
Name: "special",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expected := map[string]types.NetworkCreate{
|
|
|
|
"default": {
|
|
|
|
Labels: map[string]string{
|
2016-11-30 21:34:29 +00:00
|
|
|
LabelNamespace: "foo",
|
2016-11-30 20:33:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"normal": {
|
|
|
|
Driver: "overlay",
|
|
|
|
IPAM: &network.IPAM{
|
|
|
|
Driver: "driver",
|
|
|
|
Config: []network.IPAMConfig{
|
|
|
|
{
|
|
|
|
Subnet: "10.0.0.0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Options: map[string]string{
|
|
|
|
"opt": "value",
|
|
|
|
},
|
|
|
|
Labels: map[string]string{
|
2016-11-30 21:34:29 +00:00
|
|
|
LabelNamespace: "foo",
|
2016-11-30 20:33:54 +00:00
|
|
|
"something": "labeled",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-12-05 21:14:08 +00:00
|
|
|
networks, externals := Networks(namespace, source)
|
2016-11-30 20:33:54 +00:00
|
|
|
assert.DeepEqual(t, networks, expected)
|
|
|
|
assert.DeepEqual(t, externals, []string{"special"})
|
|
|
|
}
|