github.com/awslabs/clencli@v0.0.0-20210514234156-7ecf17182a20/tests/cmd_gitignore_test.go (about) 1 package tests 2 3 import ( 4 "testing" 5 6 "github.com/awslabs/clencli/cobra/controller" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestGitIgnoreCmd(t *testing.T) { 11 tests := map[string]struct { 12 args []string 13 out string 14 err string 15 }{ 16 // argument 17 "empty": {args: []string{"gitignore"}, out: "", err: "no flag or argument provided"}, 18 "empty arg": {args: []string{"gitignore", ""}, out: "", err: "unknown argument provided"}, 19 "wrong arg": {args: []string{"gitignore", "foo"}, out: "", err: "unknown argument provided"}, 20 21 // // flags 22 "wrong flag": {args: []string{"gitignore", "--input"}, out: "", err: "flag needs an argument: --input"}, 23 24 // // # projects 25 "no project name": {args: []string{"gitignore", "--input", ""}, out: "", err: "no flag or argument provided"}, 26 } 27 28 for name, tc := range tests { 29 t.Run(name, func(t *testing.T) { 30 out, err := executeCommand(t, controller.GitIgnoreCmd(), tc.args) 31 assert.Contains(t, out, tc.out) 32 assert.Contains(t, err.Error(), tc.err) 33 }) 34 } 35 } 36 37 func TestGitIgnoreList(t *testing.T) { 38 args := []string{"gitignore", "list"} 39 out, err := executeCommand(t, controller.GitIgnoreCmd(), args) 40 assert.Nil(t, err) 41 assert.NotEmpty(t, out) 42 } 43 44 func TestGitIgnoreInput(t *testing.T) { 45 args := []string{"gitignore", "--input", "terraform"} 46 out, err := executeCommand(t, controller.GitIgnoreCmd(), args) 47 assert.Nil(t, err) 48 assert.NotEmpty(t, out) 49 }