github.com/bdwilliams/libcompose@v0.3.1-0.20160826154243-d81a9bdacff0/docker/service/convert_test.go (about) 1 package service 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/docker/libcompose/config" 8 "github.com/docker/libcompose/docker/ctx" 9 "github.com/docker/libcompose/lookup" 10 "github.com/docker/libcompose/yaml" 11 shlex "github.com/flynn/go-shlex" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestParseCommand(t *testing.T) { 16 exp := []string{"sh", "-c", "exec /opt/bin/flanneld -logtostderr=true -iface=${NODE_IP}"} 17 cmd, err := shlex.Split("sh -c 'exec /opt/bin/flanneld -logtostderr=true -iface=${NODE_IP}'") 18 assert.Nil(t, err) 19 assert.Equal(t, exp, cmd) 20 } 21 22 func TestParseBindsAndVolumes(t *testing.T) { 23 ctx := &ctx.Context{} 24 ctx.ComposeFiles = []string{"foo/docker-compose.yml"} 25 ctx.ResourceLookup = &lookup.FileResourceLookup{} 26 27 abs, err := filepath.Abs(".") 28 assert.Nil(t, err) 29 cfg, hostCfg, err := Convert(&config.ServiceConfig{ 30 Volumes: &yaml.Volumes{ 31 Volumes: []*yaml.Volume{ 32 { 33 Destination: "/foo", 34 }, 35 { 36 Source: "/home", 37 Destination: "/home", 38 }, 39 { 40 Destination: "/bar/baz", 41 }, 42 { 43 Source: ".", 44 Destination: "/home", 45 }, 46 { 47 Source: "/usr/lib", 48 Destination: "/usr/lib", 49 AccessMode: "ro", 50 }, 51 }, 52 }, 53 }, ctx.Context, nil) 54 assert.Nil(t, err) 55 assert.Equal(t, map[string]struct{}{"/foo": {}, "/bar/baz": {}}, cfg.Volumes) 56 assert.Equal(t, []string{"/home:/home", abs + "/foo:/home", "/usr/lib:/usr/lib:ro"}, hostCfg.Binds) 57 } 58 59 func TestParseLabels(t *testing.T) { 60 ctx := &ctx.Context{} 61 ctx.ComposeFiles = []string{"foo/docker-compose.yml"} 62 ctx.ResourceLookup = &lookup.FileResourceLookup{} 63 bashCmd := "bash" 64 fooLabel := "foo.label" 65 fooLabelValue := "service.config.value" 66 sc := &config.ServiceConfig{ 67 Entrypoint: yaml.Command([]string{bashCmd}), 68 Labels: yaml.SliceorMap{fooLabel: "service.config.value"}, 69 } 70 cfg, _, err := Convert(sc, ctx.Context, nil) 71 assert.Nil(t, err) 72 73 cfg.Labels[fooLabel] = "FUN" 74 cfg.Entrypoint[0] = "less" 75 76 assert.Equal(t, fooLabelValue, sc.Labels[fooLabel]) 77 assert.Equal(t, "FUN", cfg.Labels[fooLabel]) 78 79 assert.Equal(t, yaml.Command{bashCmd}, sc.Entrypoint) 80 assert.Equal(t, []string{"less"}, []string(cfg.Entrypoint)) 81 }