github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/pluginaction/list_test.go (about) 1 package pluginaction_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 . "code.cloudfoundry.org/cli/actor/pluginaction" 8 "code.cloudfoundry.org/cli/actor/pluginaction/pluginactionfakes" 9 "code.cloudfoundry.org/cli/api/plugin" 10 "code.cloudfoundry.org/cli/util/configv3" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Plugin actions", func() { 16 var ( 17 actor *Actor 18 fakeConfig *pluginactionfakes.FakeConfig 19 fakePluginClient *pluginactionfakes.FakePluginClient 20 ) 21 22 BeforeEach(func() { 23 fakeConfig = new(pluginactionfakes.FakeConfig) 24 fakePluginClient = new(pluginactionfakes.FakePluginClient) 25 actor = NewActor(fakeConfig, fakePluginClient) 26 }) 27 28 Describe("GetOutdatedPlugins", func() { 29 BeforeEach(func() { 30 fakeConfig.PluginRepositoriesReturns([]configv3.PluginRepository{ 31 {Name: "CF-Community", URL: "https://plugins.cloudfoundry.org"}, 32 {Name: "Coo Plugins", URL: "https://reallycooplugins.org"}, 33 }) 34 }) 35 36 When("getting a repository errors", func() { 37 BeforeEach(func() { 38 fakePluginClient.GetPluginRepositoryReturns(plugin.PluginRepository{}, errors.New("generic-error")) 39 }) 40 41 It("returns a 'GettingPluginRepositoryError", func() { 42 _, err := actor.GetOutdatedPlugins() 43 Expect(err).To(MatchError(actionerror.GettingPluginRepositoryError{Name: "CF-Community", Message: "generic-error"})) 44 }) 45 }) 46 47 When("no errors are encountered getting repositories", func() { 48 var callNumber int 49 BeforeEach(func() { 50 callNumber = 0 51 52 fakePluginClient.GetPluginRepositoryStub = func(name string) (plugin.PluginRepository, error) { 53 callNumber++ 54 if callNumber == 1 { 55 return plugin.PluginRepository{ 56 Plugins: []plugin.Plugin{ 57 {Name: "plugin-1", Version: "2.0.0"}, 58 {Name: "plugin-2", Version: "1.5.0"}, 59 {Name: "plugin-3", Version: "3.0.0"}, 60 }, 61 }, nil 62 } else { 63 return plugin.PluginRepository{ 64 Plugins: []plugin.Plugin{ 65 {Name: "plugin-1", Version: "1.5.0"}, 66 {Name: "plugin-2", Version: "2.0.0"}, 67 {Name: "plugin-3", Version: "3.0.0"}, 68 }, 69 }, nil 70 } 71 } 72 }) 73 74 When("there are outdated plugins", func() { 75 BeforeEach(func() { 76 fakeConfig.PluginsReturns([]configv3.Plugin{ 77 {Name: "plugin-1", Version: configv3.PluginVersion{Major: 1, Minor: 0, Build: 0}}, 78 {Name: "plugin-2", Version: configv3.PluginVersion{Major: 1, Minor: 0, Build: 0}}, 79 {Name: "plugin-3", Version: configv3.PluginVersion{Major: 3, Minor: 0, Build: 0}}, 80 }) 81 }) 82 83 It("returns the outdated plugins", func() { 84 outdatedPlugins, err := actor.GetOutdatedPlugins() 85 Expect(err).ToNot(HaveOccurred()) 86 87 Expect(outdatedPlugins).To(Equal([]OutdatedPlugin{ 88 {Name: "plugin-1", CurrentVersion: "1.0.0", LatestVersion: "2.0.0"}, 89 {Name: "plugin-2", CurrentVersion: "1.0.0", LatestVersion: "2.0.0"}, 90 })) 91 }) 92 }) 93 94 When("there are no outdated plugins", func() { 95 BeforeEach(func() { 96 fakeConfig.PluginsReturns([]configv3.Plugin{ 97 {Name: "plugin-1", Version: configv3.PluginVersion{Major: 2, Minor: 0, Build: 0}}, 98 {Name: "plugin-2", Version: configv3.PluginVersion{Major: 2, Minor: 0, Build: 0}}, 99 {Name: "plugin-3", Version: configv3.PluginVersion{Major: 3, Minor: 0, Build: 0}}, 100 }) 101 }) 102 103 It("returns no plugins", func() { 104 outdatedPlugins, err := actor.GetOutdatedPlugins() 105 Expect(err).ToNot(HaveOccurred()) 106 107 Expect(outdatedPlugins).To(BeEmpty()) 108 }) 109 }) 110 }) 111 }) 112 })