Fixed cli tests

This commit is contained in:
Diptanu Choudhury
2017-02-16 15:18:38 -08:00
parent 6debb3e03b
commit 8557a89d38
3 changed files with 33 additions and 2 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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