github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/certs_test.go (about) 1 package parser 2 3 import ( 4 "bytes" 5 "errors" 6 "testing" 7 "time" 8 9 "github.com/arschles/assert" 10 "github.com/teamhephy/workflow-cli/pkg/testutil" 11 ) 12 13 // Create fake implementations of each method that return the argument 14 // we expect to have called the function (as an error to satisfy the interface). 15 16 func (d FakeDeisCmd) CertsList(int, time.Time) error { 17 return errors.New("certs:list") 18 } 19 20 func (d FakeDeisCmd) CertAdd(string, string, string) error { 21 return errors.New("certs:add") 22 } 23 24 func (d FakeDeisCmd) CertRemove(string) error { 25 return errors.New("certs:remove") 26 } 27 28 func (d FakeDeisCmd) CertInfo(string) error { 29 return errors.New("certs:info") 30 } 31 32 func (d FakeDeisCmd) CertAttach(string, string) error { 33 return errors.New("certs:attach") 34 } 35 36 func (d FakeDeisCmd) CertDetach(string, string) error { 37 return errors.New("certs:detach") 38 } 39 40 func TestCerts(t *testing.T) { 41 t.Parallel() 42 43 cf, server, err := testutil.NewTestServerAndClient() 44 if err != nil { 45 t.Fatal(err) 46 } 47 defer server.Close() 48 var b bytes.Buffer 49 cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf} 50 51 // cases defines the arguments and expected return of the call. 52 // if expected is "", it defaults to args[0]. 53 cases := []struct { 54 args []string 55 expected string 56 }{ 57 { 58 args: []string{"certs:list"}, 59 expected: "", 60 }, 61 { 62 args: []string{"certs:add", "name", "cert", "key"}, 63 expected: "", 64 }, 65 { 66 args: []string{"certs:remove", "name"}, 67 expected: "", 68 }, 69 { 70 args: []string{"certs:info", "name"}, 71 expected: "", 72 }, 73 { 74 args: []string{"certs:attach", "name", "example.com"}, 75 expected: "", 76 }, 77 { 78 args: []string{"certs:detach", "name", "example.com"}, 79 expected: "", 80 }, 81 { 82 args: []string{"certs"}, 83 expected: "certs:list", 84 }, 85 } 86 87 // For each case, check that calling the route with the arguments 88 // returns the expected error, which is args[0] if not provided. 89 for _, c := range cases { 90 var expected string 91 if c.expected == "" { 92 expected = c.args[0] 93 } else { 94 expected = c.expected 95 } 96 err = Certs(c.args, cmdr) 97 assert.Err(t, errors.New(expected), err) 98 } 99 }