github.com/cloudfoundry/cli@v7.1.0+incompatible/cf/commands/pluginrepo/remove_plugin_repo_test.go (about)

     1  package pluginrepo_test
     2  
     3  import (
     4  	testcmd "code.cloudfoundry.org/cli/cf/util/testhelpers/commands"
     5  	testconfig "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration"
     6  	testterm "code.cloudfoundry.org/cli/cf/util/testhelpers/terminal"
     7  
     8  	"code.cloudfoundry.org/cli/cf/commandregistry"
     9  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
    10  	"code.cloudfoundry.org/cli/cf/models"
    11  	"code.cloudfoundry.org/cli/cf/requirements/requirementsfakes"
    12  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
    13  
    14  	. "github.com/onsi/ginkgo"
    15  	. "github.com/onsi/gomega"
    16  )
    17  
    18  var _ = Describe("delte-plugin-repo", func() {
    19  	var (
    20  		ui                  *testterm.FakeUI
    21  		config              coreconfig.Repository
    22  		requirementsFactory *requirementsfakes.FakeFactory
    23  		deps                commandregistry.Dependency
    24  	)
    25  
    26  	updateCommandDependency := func(pluginCall bool) {
    27  		deps.UI = ui
    28  		deps.Config = config
    29  		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("remove-plugin-repo").SetDependency(deps, pluginCall))
    30  	}
    31  
    32  	BeforeEach(func() {
    33  		ui = &testterm.FakeUI{}
    34  		requirementsFactory = new(requirementsfakes.FakeFactory)
    35  		config = testconfig.NewRepositoryWithDefaults()
    36  	})
    37  
    38  	var callRemovePluginRepo = func(args ...string) bool {
    39  		return testcmd.RunCLICommand("remove-plugin-repo", args, requirementsFactory, updateCommandDependency, false, ui)
    40  	}
    41  
    42  	Context("When repo name is valid", func() {
    43  		BeforeEach(func() {
    44  			config.SetPluginRepo(models.PluginRepo{
    45  				Name: "repo1",
    46  				URL:  "http://someserver1.com:1234",
    47  			})
    48  
    49  			config.SetPluginRepo(models.PluginRepo{
    50  				Name: "repo2",
    51  				URL:  "http://server2.org:8080",
    52  			})
    53  		})
    54  
    55  		It("deletes the repo from the config", func() {
    56  			callRemovePluginRepo("repo1")
    57  			Expect(len(config.PluginRepos())).To(Equal(1))
    58  			Expect(config.PluginRepos()[0].Name).To(Equal("repo2"))
    59  			Expect(config.PluginRepos()[0].URL).To(Equal("http://server2.org:8080"))
    60  		})
    61  	})
    62  
    63  	Context("When named repo doesn't exist", func() {
    64  		BeforeEach(func() {
    65  			config.SetPluginRepo(models.PluginRepo{
    66  				Name: "repo1",
    67  				URL:  "http://someserver1.com:1234",
    68  			})
    69  
    70  			config.SetPluginRepo(models.PluginRepo{
    71  				Name: "repo2",
    72  				URL:  "http://server2.org:8080",
    73  			})
    74  		})
    75  
    76  		It("doesn't change the config the config", func() {
    77  			callRemovePluginRepo("fake-repo")
    78  
    79  			Expect(len(config.PluginRepos())).To(Equal(2))
    80  			Expect(config.PluginRepos()[0].Name).To(Equal("repo1"))
    81  			Expect(config.PluginRepos()[0].URL).To(Equal("http://someserver1.com:1234"))
    82  			Expect(ui.Outputs()).To(ContainSubstrings([]string{"fake-repo", "does not exist as a repo"}))
    83  		})
    84  	})
    85  })