github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/command/fs_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func TestFSCommand_Implements(t *testing.T) { 11 var _ cli.Command = &FSCommand{} 12 } 13 14 func TestFSCommand_Fails(t *testing.T) { 15 srv, _, url := testServer(t, nil) 16 defer srv.Stop() 17 18 ui := new(cli.MockUi) 19 cmd := &FSCommand{Meta: Meta{Ui: ui}} 20 21 // Fails on lack of job ID 22 if code := cmd.Run([]string{"-job"}); code != 1 { 23 t.Fatalf("expected exit code 1, got: %d", code) 24 } 25 if out := ui.ErrorWriter.String(); !strings.Contains(out, "job ID is required") { 26 t.Fatalf("expected help output, got: %s", out) 27 } 28 ui.ErrorWriter.Reset() 29 30 // Fails on lack of allocation ID 31 if code := cmd.Run([]string{}); code != 1 { 32 t.Fatalf("expected exit code 1, got: %d", code) 33 } 34 if out := ui.ErrorWriter.String(); !strings.Contains(out, "allocation ID is required") { 35 t.Fatalf("expected help output, got: %s", out) 36 } 37 ui.ErrorWriter.Reset() 38 39 // Fails on misuse 40 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 41 t.Fatalf("expected exit code 1, got: %d", code) 42 } 43 if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { 44 t.Fatalf("expected help output, got: %s", out) 45 } 46 ui.ErrorWriter.Reset() 47 48 // Fails on connection failure 49 if code := cmd.Run([]string{"-address=nope", "foobar"}); code != 1 { 50 t.Fatalf("expected exit code 1, got: %d", code) 51 } 52 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying allocation") { 53 t.Fatalf("expected failed query error, got: %s", out) 54 } 55 ui.ErrorWriter.Reset() 56 57 // Fails on missing alloc 58 if code := cmd.Run([]string{"-address=" + url, "26470238-5CF2-438F-8772-DC67CFB0705C"}); code != 1 { 59 t.Fatalf("expected exit 1, got: %d", code) 60 } 61 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { 62 t.Fatalf("expected not found error, got: %s", out) 63 } 64 ui.ErrorWriter.Reset() 65 66 // Fail on identifier with too few characters 67 if code := cmd.Run([]string{"-address=" + url, "2"}); code != 1 { 68 t.Fatalf("expected exit 1, got: %d", code) 69 } 70 if out := ui.ErrorWriter.String(); !strings.Contains(out, "must contain at least two characters.") { 71 t.Fatalf("expected too few characters error, got: %s", out) 72 } 73 ui.ErrorWriter.Reset() 74 75 // Identifiers with uneven length should produce a query result 76 if code := cmd.Run([]string{"-address=" + url, "123"}); code != 1 { 77 t.Fatalf("expected exit 1, got: %d", code) 78 } 79 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { 80 t.Fatalf("expected not found error, got: %s", out) 81 } 82 83 }