github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/actor/pluginaction/list_test.go (about)

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