github.com/pluralsh/plural-cli@v0.9.5/cmd/plural/repos_test.go (about) 1 package plural_test 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/mock" 9 10 "github.com/pluralsh/plural-cli/cmd/plural" 11 "github.com/pluralsh/plural-cli/pkg/api" 12 "github.com/pluralsh/plural-cli/pkg/test/mocks" 13 ) 14 15 func TestListRepositories(t *testing.T) { 16 tests := []struct { 17 name string 18 args []string 19 repos []*api.Repository 20 expectedResponse string 21 }{ 22 { 23 name: `test "repos list"`, 24 args: []string{plural.ApplicationName, "repos", "list"}, 25 repos: []*api.Repository{ 26 { 27 Id: "123", 28 Name: "test", 29 Description: "test application", 30 Publisher: &api.Publisher{ 31 Id: "456", 32 Name: "test", 33 }, 34 Recipes: []*api.Recipe{ 35 { 36 Id: "789", 37 Name: "r1", 38 }, 39 { 40 Id: "101", 41 Name: "r2", 42 }, 43 }, 44 }, 45 }, 46 expectedResponse: `+------+------------------+-----------+---------+ 47 | REPO | DESCRIPTION | PUBLISHER | BUNDLES | 48 +------+------------------+-----------+---------+ 49 | test | test application | test | r1, r2 | 50 +------+------------------+-----------+---------+ 51 `, 52 }, 53 } 54 for _, test := range tests { 55 t.Run(test.name, func(t *testing.T) { 56 client := mocks.NewClient(t) 57 client.On("ListRepositories", mock.AnythingOfType("string")).Return(test.repos, nil) 58 app := plural.CreateNewApp(&plural.Plural{Client: client}) 59 app.HelpName = plural.ApplicationName 60 os.Args = test.args 61 res, err := captureStdout(app, os.Args) 62 assert.NoError(t, err) 63 assert.Equal(t, test.expectedResponse, res) 64 }) 65 } 66 } 67 68 // func TestResetRepositories(t *testing.T) { 69 // tests := []struct { 70 // name string 71 // args []string 72 // count int 73 // expectedResponse string 74 // }{ 75 // { 76 // name: `test "repos reset"`, 77 // args: []string{plural.ApplicationName, "repos", "reset"}, 78 // count: 5, 79 // expectedResponse: `Deleted 5 installations in app.plural.sh 80 // (you can recreate these at any time and any running infrastructure is not affected, plural will simply no longer deliver upgrades) 81 // `, 82 // }, 83 // } 84 // for _, test := range tests { 85 // t.Run(test.name, func(t *testing.T) { 86 // client := mocks.NewClient(t) 87 // client.On("ResetInstallations").Return(test.count, nil) 88 // app := plural.CreateNewApp(&plural.Plural{Client: client}) 89 // app.HelpName = plural.ApplicationName 90 // os.Args = test.args 91 // res, err := captureStdout(app, os.Args) 92 // assert.NoError(t, err) 93 // assert.Equal(t, test.expectedResponse, res) 94 // }) 95 // } 96 // }