github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/ps_test.go (about) 1 package parser 2 3 import ( 4 "bytes" 5 "errors" 6 "testing" 7 8 "github.com/arschles/assert" 9 "github.com/teamhephy/workflow-cli/pkg/testutil" 10 ) 11 12 // Create fake implementations of each method that return the argument 13 // we expect to have called the function (as an error to satisfy the interface). 14 15 func (d FakeDeisCmd) PsList(string, int) error { 16 return errors.New("ps:list") 17 } 18 19 func (d FakeDeisCmd) PsScale(string, []string) error { 20 return errors.New("ps:scale") 21 } 22 23 func (d FakeDeisCmd) PsRestart(string, string) error { 24 return errors.New("ps:restart") 25 } 26 27 func TestPs(t *testing.T) { 28 t.Parallel() 29 30 cf, server, err := testutil.NewTestServerAndClient() 31 if err != nil { 32 t.Fatal(err) 33 } 34 defer server.Close() 35 var b bytes.Buffer 36 cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf} 37 38 // cases defines the arguments and expected return of the call. 39 // if expected is "", it defaults to args[0]. 40 cases := []struct { 41 args []string 42 expected string 43 }{ 44 { 45 args: []string{"ps:list"}, 46 expected: "", 47 }, 48 { 49 args: []string{"ps:restart", "web"}, 50 expected: "", 51 }, 52 { 53 args: []string{"ps:scale", "web", "5"}, 54 expected: "", 55 }, 56 { 57 args: []string{"ps:list"}, 58 expected: "", 59 }, 60 { 61 args: []string{"ps"}, 62 expected: "ps:list", 63 }, 64 } 65 66 // For each case, check that calling the route with the arguments 67 // returns the expected error, which is args[0] if not provided. 68 for _, c := range cases { 69 var expected string 70 if c.expected == "" { 71 expected = c.args[0] 72 } else { 73 expected = c.expected 74 } 75 err = Ps(c.args, cmdr) 76 assert.Err(t, errors.New(expected), err) 77 } 78 }