github.com/smithx10/nomad@v0.9.1-rc1/command/namespace_list_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 ) 11 12 func TestNamespaceListCommand_Implements(t *testing.T) { 13 t.Parallel() 14 var _ cli.Command = &NamespaceListCommand{} 15 } 16 17 func TestNamespaceListCommand_Fails(t *testing.T) { 18 t.Parallel() 19 ui := new(cli.MockUi) 20 cmd := &NamespaceListCommand{Meta: Meta{Ui: ui}} 21 22 // Fails on misuse 23 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 24 t.Fatalf("expected exit code 1, got: %d", code) 25 } 26 if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { 27 t.Fatalf("expected help output, got: %s", out) 28 } 29 ui.ErrorWriter.Reset() 30 31 if code := cmd.Run([]string{"-address=nope"}); code != 1 { 32 t.Fatalf("expected exit code 1, got: %d", code) 33 } 34 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error retrieving namespaces") { 35 t.Fatalf("expected failed query error, got: %s", out) 36 } 37 ui.ErrorWriter.Reset() 38 } 39 40 func TestNamespaceListCommand_List(t *testing.T) { 41 t.Parallel() 42 43 // Create a server 44 srv, _, url := testServer(t, true, nil) 45 defer srv.Shutdown() 46 47 ui := new(cli.MockUi) 48 cmd := &NamespaceListCommand{Meta: Meta{Ui: ui}} 49 50 // List should contain default deployment 51 if code := cmd.Run([]string{"-address=" + url}); code != 0 { 52 t.Fatalf("expected exit 0, got: %d; %v", code, ui.ErrorWriter.String()) 53 } 54 out := ui.OutputWriter.String() 55 if !strings.Contains(out, "default") || !strings.Contains(out, "Default shared namespace") { 56 t.Fatalf("expected default namespace, got: %s", out) 57 } 58 ui.OutputWriter.Reset() 59 60 // List json 61 if code := cmd.Run([]string{"-address=" + url, "-json"}); code != 0 { 62 t.Fatalf("expected exit 0, got: %d; %v", code, ui.ErrorWriter.String()) 63 } 64 out = ui.OutputWriter.String() 65 if !strings.Contains(out, "CreateIndex") { 66 t.Fatalf("expected json output, got: %s", out) 67 } 68 ui.OutputWriter.Reset() 69 }