github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/config_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) ConfigList(string, string) error { 16 return errors.New("config:list") 17 } 18 19 func (d FakeDeisCmd) ConfigSet(string, []string) error { 20 return errors.New("config:set") 21 } 22 23 func (d FakeDeisCmd) ConfigUnset(string, []string) error { 24 return errors.New("config:unset") 25 } 26 27 func (d FakeDeisCmd) ConfigPull(string, bool, bool) error { 28 return errors.New("config:pull") 29 } 30 31 func (d FakeDeisCmd) ConfigPush(string, string) error { 32 return errors.New("config:push") 33 } 34 35 func TestConfig(t *testing.T) { 36 t.Parallel() 37 38 cf, server, err := testutil.NewTestServerAndClient() 39 if err != nil { 40 t.Fatal(err) 41 } 42 defer server.Close() 43 var b bytes.Buffer 44 cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf} 45 46 // cases defines the arguments and expected return of the call. 47 // if expected is "", it defaults to args[0]. 48 cases := []struct { 49 args []string 50 expected string 51 }{ 52 { 53 args: []string{"config:list"}, 54 expected: "", 55 }, 56 { 57 args: []string{"config:set", "var=value"}, 58 expected: "", 59 }, 60 { 61 args: []string{"config:unset", "var"}, 62 expected: "", 63 }, 64 { 65 args: []string{"config:pull"}, 66 expected: "", 67 }, 68 { 69 args: []string{"config:push"}, 70 expected: "", 71 }, 72 { 73 args: []string{"config"}, 74 expected: "config:list", 75 }, 76 } 77 78 // For each case, check that calling the route with the arguments 79 // returns the expected error, which is args[0] if not provided. 80 for _, c := range cases { 81 var expected string 82 if c.expected == "" { 83 expected = c.args[0] 84 } else { 85 expected = c.expected 86 } 87 err = Config(c.args, cmdr) 88 assert.Err(t, errors.New(expected), err) 89 } 90 }