github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/integration/shared/plugin/uninstall_plugin_command_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	"code.cloudfoundry.org/cli/util/generic"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("uninstall-plugin command", func() {
    16  	Describe("help", func() {
    17  		When("--help flag is provided", func() {
    18  			It("displays command usage to output", func() {
    19  				session := helpers.CF("uninstall-plugin", "--help")
    20  				Eventually(session).Should(Say("NAME:"))
    21  				Eventually(session).Should(Say("uninstall-plugin - Uninstall CLI plugin"))
    22  				Eventually(session).Should(Say("USAGE:"))
    23  				Eventually(session).Should(Say("cf uninstall-plugin PLUGIN-NAME"))
    24  				Eventually(session).Should(Say("SEE ALSO:"))
    25  				Eventually(session).Should(Say("plugins"))
    26  				Eventually(session).Should(Exit(0))
    27  			})
    28  		})
    29  	})
    30  
    31  	When("the plugin is not installed", func() {
    32  		It("informs the user that no such plugin is present and exits 1", func() {
    33  			session := helpers.CF("uninstall-plugin", "bananarama")
    34  			Eventually(session.Err).Should(Say(`Plugin bananarama does not exist\.`))
    35  			Eventually(session).Should(Exit(1))
    36  		})
    37  	})
    38  
    39  	When("the plugin is installed", func() {
    40  		BeforeEach(func() {
    41  			helpers.InstallConfigurablePlugin("configurable_plugin", "banana-plugin-name-1", "2.0.1", []helpers.PluginCommand{
    42  				{Name: "banana-command-1", Help: "banana-command-1"},
    43  			})
    44  			helpers.InstallConfigurablePlugin("configurable_plugin", "banana-plugin-name-2", "1.4.3", []helpers.PluginCommand{
    45  				{Name: "banana-command-2", Help: "banana-command-2"},
    46  			})
    47  		})
    48  
    49  		When("no errors are encountered", func() {
    50  			It("does not list the plugin after it is uninstalled", func() {
    51  				session := helpers.CF("uninstall-plugin", "banana-plugin-name-1")
    52  				Eventually(session).Should(Say(`Uninstalling plugin banana-plugin-name-1\.\.\.`))
    53  				// Test that RPC works
    54  				Eventually(session).Should(Say("[0-9]{1,5} CLI-MESSAGE-UNINSTALL"))
    55  				Eventually(session).Should(Say("OK"))
    56  				Eventually(session).Should(Say(`Plugin banana-plugin-name-1 2\.0\.1 successfully uninstalled\.`))
    57  				Eventually(session).Should(Exit(0))
    58  
    59  				session = helpers.CF("plugins")
    60  				Consistently(session).ShouldNot(Say("banana-plugin-name-1"))
    61  				Eventually(session).Should(Say("banana-plugin-name-2"))
    62  				Eventually(session).Should(Exit(0))
    63  			})
    64  
    65  			It("matches the plugin name case insensitive", func() {
    66  				session := helpers.CF("uninstall-plugin", "BaNaNa-PlUgIn-NaMe-1")
    67  				Eventually(session).Should(Say(`Uninstalling plugin banana-plugin-name-1\.\.\.`))
    68  				Eventually(session).Should(Say("OK"))
    69  				Eventually(session).Should(Say(`Plugin banana-plugin-name-1 2\.0\.1 successfully uninstalled\.`))
    70  				Eventually(session).Should(Exit(0))
    71  			})
    72  		})
    73  
    74  		When("the plugin encounters an error during cleanup", func() {
    75  			BeforeEach(func() {
    76  				helpers.InstallConfigurablePlugin("configurable_plugin_fails_uninstall", "failing-plugin", "2.0.1", []helpers.PluginCommand{
    77  					{Name: "failing-command-1", Help: "failing-command-1"},
    78  				})
    79  			})
    80  
    81  			It("exits with an error but still uninstalls the plugin", func() {
    82  				session := helpers.CF("uninstall-plugin", "failing-plugin")
    83  				Eventually(session).Should(Say(`Uninstalling plugin failing-plugin\.\.\.`))
    84  				Eventually(session.Err).Should(Say("I'm failing...I'm failing..."))
    85  				Eventually(session).Should(Say("FAILED"))
    86  				Eventually(session.Err).Should(Say(`The plugin's uninstall method returned an unexpected error\.`))
    87  				Eventually(session.Err).Should(Say(`The plugin uninstall will proceed\. Contact the plugin author if you need help\.`))
    88  				Eventually(session.Err).Should(Say("exit status 1"))
    89  				Eventually(session).Should(Exit(1))
    90  
    91  				binaryPath := generic.ExecutableFilename(
    92  					filepath.Join(homeDir, ".cf", "plugins", "failing-plugin"))
    93  				_, err := os.Stat(binaryPath)
    94  				Expect(os.IsNotExist(err)).To(BeTrue())
    95  
    96  				session = helpers.CF("plugins")
    97  				Eventually(session).Should(Say("banana-plugin-name-1"))
    98  				Eventually(session).Should(Say("banana-plugin-name-2"))
    99  				Consistently(session).ShouldNot(Say("failing-plugin"))
   100  				Eventually(session).Should(Exit(0))
   101  			})
   102  		})
   103  
   104  		When("the plugin binary has been deleted", func() {
   105  			BeforeEach(func() {
   106  				helpers.InstallConfigurablePlugin(
   107  					"configurable_plugin",
   108  					"banana-plugin-name-1",
   109  					"2.0.1",
   110  					[]helpers.PluginCommand{
   111  						{
   112  							Name: "banana-command-1",
   113  							Help: "banana-command-1"},
   114  					})
   115  
   116  				binaryPath := generic.ExecutableFilename(
   117  					filepath.Join(homeDir, ".cf", "plugins", "banana-plugin-name-1"))
   118  				Expect(os.Remove(binaryPath)).ToNot(HaveOccurred())
   119  			})
   120  
   121  			It("uninstalls the plugin with no warning or error and exits 0", func() {
   122  				session := helpers.CF("uninstall-plugin", "banana-plugin-name-1")
   123  				Eventually(session).Should(Exit(0))
   124  			})
   125  		})
   126  	})
   127  })