github.com/ralexstokes/docker@v1.6.2/runconfig/parse_test.go (about) 1 package runconfig 2 3 import ( 4 "io/ioutil" 5 "testing" 6 7 flag "github.com/docker/docker/pkg/mflag" 8 "github.com/docker/docker/pkg/parsers" 9 ) 10 11 func parseRun(args []string) (*Config, *HostConfig, *flag.FlagSet, error) { 12 cmd := flag.NewFlagSet("run", flag.ContinueOnError) 13 cmd.SetOutput(ioutil.Discard) 14 cmd.Usage = nil 15 return Parse(cmd, args) 16 } 17 18 func TestParseLxcConfOpt(t *testing.T) { 19 opts := []string{"lxc.utsname=docker", "lxc.utsname = docker "} 20 21 for _, o := range opts { 22 k, v, err := parsers.ParseKeyValueOpt(o) 23 if err != nil { 24 t.FailNow() 25 } 26 if k != "lxc.utsname" { 27 t.Fail() 28 } 29 if v != "docker" { 30 t.Fail() 31 } 32 } 33 } 34 35 func TestNetHostname(t *testing.T) { 36 if _, _, _, err := parseRun([]string{"-h=name", "img", "cmd"}); err != nil { 37 t.Fatalf("Unexpected error: %s", err) 38 } 39 40 if _, _, _, err := parseRun([]string{"--net=host", "img", "cmd"}); err != nil { 41 t.Fatalf("Unexpected error: %s", err) 42 } 43 44 if _, _, _, err := parseRun([]string{"-h=name", "--net=bridge", "img", "cmd"}); err != nil { 45 t.Fatalf("Unexpected error: %s", err) 46 } 47 48 if _, _, _, err := parseRun([]string{"-h=name", "--net=none", "img", "cmd"}); err != nil { 49 t.Fatalf("Unexpected error: %s", err) 50 } 51 52 if _, _, _, err := parseRun([]string{"-h=name", "--net=host", "img", "cmd"}); err != ErrConflictNetworkHostname { 53 t.Fatalf("Expected error ErrConflictNetworkHostname, got: %s", err) 54 } 55 56 if _, _, _, err := parseRun([]string{"-h=name", "--net=container:other", "img", "cmd"}); err != ErrConflictNetworkHostname { 57 t.Fatalf("Expected error ErrConflictNetworkHostname, got: %s", err) 58 } 59 }