github.com/drycc/workflow-cli@v1.5.3-0.20240322092846-d4ee25983af9/parser/apps_test.go (about) 1 package parser 2 3 import ( 4 "bytes" 5 "errors" 6 "testing" 7 8 "github.com/drycc/workflow-cli/pkg/testutil" 9 "github.com/stretchr/testify/assert" 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 FakeDryccCmd) AppCreate(string, string, bool) error { 16 return errors.New("apps:create") 17 } 18 19 func (d FakeDryccCmd) AppsList(int) error { 20 return errors.New("apps:list") 21 } 22 23 func (d FakeDryccCmd) AppInfo(string) error { 24 return errors.New("apps:info") 25 } 26 27 func (d FakeDryccCmd) AppOpen(string) error { 28 return errors.New("apps:open") 29 } 30 31 func (d FakeDryccCmd) AppLogs(string, int, bool, int) error { 32 return errors.New("apps:logs") 33 } 34 35 func (d FakeDryccCmd) AppRun(string, string, []string, uint32, uint32) error { 36 return errors.New("apps:run") 37 } 38 39 func (d FakeDryccCmd) AppDestroy(string, string) error { 40 return errors.New("apps:destroy") 41 } 42 43 func (d FakeDryccCmd) AppTransfer(string, string) error { 44 return errors.New("apps:transfer") 45 } 46 47 func TestApps(t *testing.T) { 48 t.Parallel() 49 50 cf, server, err := testutil.NewTestServerAndClient() 51 if err != nil { 52 t.Fatal(err) 53 } 54 defer server.Close() 55 var b bytes.Buffer 56 cmdr := FakeDryccCmd{WOut: &b, ConfigFile: cf} 57 58 // cases defines the arguments and expected return of the call. 59 // if expected is "", it defaults to args[0]. 60 cases := []struct { 61 args []string 62 expected string 63 }{ 64 { 65 args: []string{"apps:create"}, 66 expected: "", 67 }, 68 { 69 args: []string{"apps:list"}, 70 expected: "", 71 }, 72 { 73 args: []string{"apps:info"}, 74 expected: "", 75 }, 76 { 77 args: []string{"apps:open"}, 78 expected: "", 79 }, 80 { 81 args: []string{"apps:logs"}, 82 expected: "", 83 }, 84 { 85 args: []string{"apps:logs", "--lines=1"}, 86 expected: "", 87 }, 88 { 89 args: []string{"apps:run", "ls"}, 90 expected: "", 91 }, 92 { 93 args: []string{"apps:destroy"}, 94 expected: "", 95 }, 96 { 97 args: []string{"apps:transfer", "test-user"}, 98 expected: "", 99 }, 100 { 101 args: []string{"apps"}, 102 expected: "apps:list", 103 }, 104 } 105 106 // For each case, check that calling the route with the arguments 107 // returns the expected error, which is args[0] if not provided. 108 for _, c := range cases { 109 var expected string 110 if c.expected == "" { 111 expected = c.args[0] 112 } else { 113 expected = c.expected 114 } 115 err = Apps(c.args, cmdr) 116 assert.Error(t, errors.New(expected), err) 117 } 118 }