| 886 | } |
| 887 | |
| 888 | func TestParseHealth(t *testing.T) { |
| 889 | checkOk := func(args ...string) *container.HealthConfig { |
| 890 | config, _, _, err := parseRun(args) |
| 891 | if err != nil { |
| 892 | t.Fatalf("%#v: %v", args, err) |
| 893 | } |
| 894 | return config.Healthcheck |
| 895 | } |
| 896 | checkError := func(expected string, args ...string) { |
| 897 | config, _, _, err := parseRun(args) |
| 898 | if err == nil { |
| 899 | t.Fatalf("Expected error, but got %#v", config) |
| 900 | } |
| 901 | if err.Error() != expected { |
| 902 | t.Fatalf("Expected %#v, got %#v", expected, err) |
| 903 | } |
| 904 | } |
| 905 | health := checkOk("--no-healthcheck", "img", "cmd") |
| 906 | if health == nil || len(health.Test) != 1 || health.Test[0] != "NONE" { |
| 907 | t.Fatalf("--no-healthcheck failed: %#v", health) |
| 908 | } |
| 909 | |
| 910 | health = checkOk("--health-cmd=/check.sh -q", "img", "cmd") |
| 911 | if len(health.Test) != 2 || health.Test[0] != "CMD-SHELL" || health.Test[1] != "/check.sh -q" { |
| 912 | t.Fatalf("--health-cmd: got %#v", health.Test) |
| 913 | } |
| 914 | if health.Timeout != 0 { |
| 915 | t.Fatalf("--health-cmd: timeout = %s", health.Timeout) |
| 916 | } |
| 917 | |
| 918 | checkError("--no-healthcheck conflicts with --health-* options", |
| 919 | "--no-healthcheck", "--health-cmd=/check.sh -q", "img", "cmd") |
| 920 | |
| 921 | health = checkOk("--health-timeout=2s", "--health-retries=3", "--health-interval=4.5s", "--health-start-period=5s", "--health-start-interval=1s", "img", "cmd") |
| 922 | if health.Timeout != 2*time.Second || health.Retries != 3 || health.Interval != 4500*time.Millisecond || health.StartPeriod != 5*time.Second || health.StartInterval != 1*time.Second { |
| 923 | t.Fatalf("--health-*: got %#v", health) |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | func TestParseLoggingOpts(t *testing.T) { |
| 928 | // logging opts ko |