github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/cli/compose/convert/compose_test.go (about) 1 package convert 2 3 import ( 4 "testing" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/api/types/network" 8 composetypes "github.com/docker/docker/cli/compose/types" 9 "github.com/docker/docker/pkg/testutil/assert" 10 ) 11 12 func TestNamespaceScope(t *testing.T) { 13 scoped := Namespace{name: "foo"}.Scope("bar") 14 assert.Equal(t, scoped, "foo_bar") 15 } 16 17 func TestAddStackLabel(t *testing.T) { 18 labels := map[string]string{ 19 "something": "labeled", 20 } 21 actual := AddStackLabel(Namespace{name: "foo"}, labels) 22 expected := map[string]string{ 23 "something": "labeled", 24 LabelNamespace: "foo", 25 } 26 assert.DeepEqual(t, actual, expected) 27 } 28 29 func TestNetworks(t *testing.T) { 30 namespace := Namespace{name: "foo"} 31 serviceNetworks := map[string]struct{}{ 32 "normal": {}, 33 "outside": {}, 34 "default": {}, 35 } 36 source := networkMap{ 37 "normal": composetypes.NetworkConfig{ 38 Driver: "overlay", 39 DriverOpts: map[string]string{ 40 "opt": "value", 41 }, 42 Ipam: composetypes.IPAMConfig{ 43 Driver: "driver", 44 Config: []*composetypes.IPAMPool{ 45 { 46 Subnet: "10.0.0.0", 47 }, 48 }, 49 }, 50 Labels: map[string]string{ 51 "something": "labeled", 52 }, 53 }, 54 "outside": composetypes.NetworkConfig{ 55 External: composetypes.External{ 56 External: true, 57 Name: "special", 58 }, 59 }, 60 } 61 expected := map[string]types.NetworkCreate{ 62 "default": { 63 Labels: map[string]string{ 64 LabelNamespace: "foo", 65 }, 66 }, 67 "normal": { 68 Driver: "overlay", 69 IPAM: &network.IPAM{ 70 Driver: "driver", 71 Config: []network.IPAMConfig{ 72 { 73 Subnet: "10.0.0.0", 74 }, 75 }, 76 }, 77 Options: map[string]string{ 78 "opt": "value", 79 }, 80 Labels: map[string]string{ 81 LabelNamespace: "foo", 82 "something": "labeled", 83 }, 84 }, 85 } 86 87 networks, externals := Networks(namespace, source, serviceNetworks) 88 assert.DeepEqual(t, networks, expected) 89 assert.DeepEqual(t, externals, []string{"special"}) 90 }