github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/shortcuts_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) ShortcutsList() error { 16 return errors.New("shortcuts:list") 17 } 18 19 func TestShortcuts(t *testing.T) { 20 t.Parallel() 21 22 cf, server, err := testutil.NewTestServerAndClient() 23 if err != nil { 24 t.Fatal(err) 25 } 26 defer server.Close() 27 var b bytes.Buffer 28 cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf} 29 30 // cases defines the arguments and expected return of the call. 31 // if expected is "", it defaults to args[0]. 32 cases := []struct { 33 args []string 34 expected string 35 }{ 36 { 37 args: []string{"shortcuts:list"}, 38 expected: "", 39 }, 40 { 41 args: []string{"shortcuts"}, 42 expected: "shortcuts:list", 43 }, 44 } 45 46 // For each case, check that calling the route with the arguments 47 // returns the expected error, which is args[0] if not provided. 48 for _, c := range cases { 49 var expected string 50 if c.expected == "" { 51 expected = c.args[0] 52 } else { 53 expected = c.expected 54 } 55 err = Shortcuts(c.args, cmdr) 56 assert.Err(t, errors.New(expected), err) 57 } 58 }