From 8557a89d38a0dcd4be475193b27a94fef1b5702b Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 16 Feb 2017 15:18:38 -0800 Subject: [PATCH] Fixed cli tests --- command/plan_test.go | 9 ++++++++- command/run_test.go | 9 ++++++++- command/validate_test.go | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/command/plan_test.go b/command/plan_test.go index 3bd7511ba..f8aed7e5b 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -1,11 +1,13 @@ package command import ( + "fmt" "io/ioutil" "os" "strings" "testing" + "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/cli" ) @@ -17,6 +19,11 @@ func TestPlanCommand_Fails(t *testing.T) { ui := new(cli.MockUi) cmd := &PlanCommand{Meta: Meta{Ui: ui}} + // Create a server + s := testutil.NewTestServer(t, nil) + defer s.Stop() + os.Setenv("NOMAD_ADDR", fmt.Sprintf("http://%s", s.HTTPAddr)) + // Fails on misuse if code := cmd.Run([]string{"some", "bad", "args"}); code != 255 { t.Fatalf("expected exit code 1, got: %d", code) @@ -64,7 +71,7 @@ func TestPlanCommand_Fails(t *testing.T) { if code := cmd.Run([]string{fh2.Name()}); code != 255 { t.Fatalf("expect exit 255, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error validating") { + if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error during plan") { t.Fatalf("expect validation error, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/run_test.go b/command/run_test.go index f8a5212be..a8e5e7a6d 100644 --- a/command/run_test.go +++ b/command/run_test.go @@ -1,11 +1,13 @@ package command import ( + "fmt" "io/ioutil" "os" "strings" "testing" + "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/cli" ) @@ -52,6 +54,11 @@ func TestRunCommand_Fails(t *testing.T) { ui := new(cli.MockUi) cmd := &RunCommand{Meta: Meta{Ui: ui}} + // Create a server + s := testutil.NewTestServer(t, nil) + defer s.Stop() + os.Setenv("NOMAD_ADDR", fmt.Sprintf("http://%s", s.HTTPAddr)) + // Fails on misuse if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) @@ -99,7 +106,7 @@ func TestRunCommand_Fails(t *testing.T) { if code := cmd.Run([]string{fh2.Name()}); code != 1 { t.Fatalf("expect exit 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error validating") { + if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error submitting job") { t.Fatalf("expect validation error, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/validate_test.go b/command/validate_test.go index 11be97511..c4f4069ca 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -1,11 +1,13 @@ package command import ( + "fmt" "io/ioutil" "os" "strings" "testing" + "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/cli" ) @@ -17,6 +19,11 @@ func TestValidateCommand(t *testing.T) { ui := new(cli.MockUi) cmd := &ValidateCommand{Meta: Meta{Ui: ui}} + // Create a server + s := testutil.NewTestServer(t, nil) + defer s.Stop() + os.Setenv("NOMAD_ADDR", fmt.Sprintf("http://%s", s.HTTPAddr)) + fh, err := ioutil.TempFile("", "nomad") if err != nil { t.Fatalf("err: %s", err) @@ -30,6 +37,9 @@ job "job1" { count = 1 task "task1" { driver = "exec" + config { + command = "/bin/sleep" + } resources = { cpu = 1000 memory = 512 @@ -113,6 +123,10 @@ func TestValidateCommand_From_STDIN(t *testing.T) { Meta: Meta{Ui: ui}, JobGetter: JobGetter{testStdin: stdinR}, } + // Create a server + s := testutil.NewTestServer(t, nil) + defer s.Stop() + os.Setenv("NOMAD_ADDR", fmt.Sprintf("http://%s", s.HTTPAddr)) go func() { stdinW.WriteString(` @@ -123,6 +137,9 @@ job "job1" { count = 1 task "task1" { driver = "exec" + config { + command = "/bin/echo" + } resources = { cpu = 1000 memory = 512