github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/command/namespace_apply_test.go (about) 1 // +build pro ent 2 3 package command 4 5 import ( 6 "strings" 7 "testing" 8 9 "github.com/mitchellh/cli" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestNamespaceApplyCommand_Implements(t *testing.T) { 14 t.Parallel() 15 var _ cli.Command = &NamespaceApplyCommand{} 16 } 17 18 func TestNamespaceApplyCommand_Fails(t *testing.T) { 19 t.Parallel() 20 ui := new(cli.MockUi) 21 cmd := &NamespaceApplyCommand{Meta: Meta{Ui: ui}} 22 23 // Fails on misuse 24 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 25 t.Fatalf("expected exit code 1, got: %d", code) 26 } 27 if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { 28 t.Fatalf("expected help output, got: %s", out) 29 } 30 ui.ErrorWriter.Reset() 31 32 if code := cmd.Run([]string{"-address=nope"}); code != 1 { 33 t.Fatalf("expected exit code 1, got: %d", code) 34 } 35 if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { 36 t.Fatalf("name required error, got: %s", out) 37 } 38 ui.ErrorWriter.Reset() 39 } 40 41 func TestNamespaceApplyCommand_Good(t *testing.T) { 42 t.Parallel() 43 44 // Create a server 45 srv, client, url := testServer(t, true, nil) 46 defer srv.Shutdown() 47 48 ui := new(cli.MockUi) 49 cmd := &NamespaceApplyCommand{Meta: Meta{Ui: ui}} 50 51 // Create a namespace 52 name, desc := "foo", "bar" 53 if code := cmd.Run([]string{"-address=" + url, "-description=" + desc, name}); code != 0 { 54 t.Fatalf("expected exit 0, got: %d; %v", code, ui.ErrorWriter.String()) 55 } 56 57 namespaces, _, err := client.Namespaces().List(nil) 58 assert.Nil(t, err) 59 assert.Len(t, namespaces, 2) 60 }