github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/plugin/runner_test.go (about) 1 package plugin 2 3 import ( 4 "os" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("running plugins", func() { 14 Describe("panic handling", func() { 15 BeforeEach(func() { 16 Eventually(helpers.CF("install-plugin", "-f", panicTestPluginPath)).Should(Exit(0)) 17 }) 18 19 It("will exit 1 if the plugin panics", func() { 20 Eventually(helpers.CF("freak-out")).Should(Exit(1)) 21 }) 22 }) 23 24 Describe("CF_TRACE", func() { 25 BeforeEach(func() { 26 installTestPlugin() 27 }) 28 29 AfterEach(func() { 30 uninstallTestPlugin() 31 }) 32 33 When("the plugin is run with CF_TRACE=true", func() { 34 It("does not error", func() { 35 Eventually(helpers.CustomCF(helpers.CFEnv{ 36 EnvVars: map[string]string{"CF_TRACE": "true"}, 37 }, "CoolTest")).Should(Exit(0)) 38 }) 39 }) 40 }) 41 42 Describe("when running plugin commands while CF_HOME is set", func() { 43 When("CF_PLUGIN_HOME is unset", func() { 44 BeforeEach(func() { 45 Expect(os.Setenv("CF_PLUGIN_HOME", "")).NotTo(HaveOccurred()) 46 }) 47 48 When("a plugin is installed", func() { 49 BeforeEach(func() { 50 installTestPlugin() 51 }) 52 53 AfterEach(func() { 54 uninstallTestPlugin() 55 }) 56 57 It("lists the installed plugins", func() { 58 session := helpers.CF("plugins") 59 Eventually(session).Should(Say("CoolTest")) 60 Eventually(session).Should(Exit(0)) 61 }) 62 63 It("is able to run the CoolTest plugin command", func() { // v7 only 64 confirmTestPluginOutput("CoolTest", "I am a test plugin") 65 }) 66 67 It("is able to run an installed plugin command", func() { 68 confirmTestPluginOutput("ApiEndpoint", helpers.GetAPI()) 69 }) 70 }) 71 }) 72 73 When("CF_PLUGIN_HOME is set", func() { 74 When("a plugin is installed", func() { 75 BeforeEach(func() { 76 installTestPlugin() 77 }) 78 79 AfterEach(func() { 80 uninstallTestPlugin() 81 }) 82 83 It("lists the installed plugins", func() { 84 session := helpers.CF("plugins") 85 Eventually(session).Should(Say("TestPluginCommandWithAlias")) 86 Eventually(session).Should(Exit(0)) 87 }) 88 89 It("can call a command by its alias", func() { 90 confirmTestPluginOutput("Cool-V7", "You called Test Plugin Command V7 With Alias!") 91 }) 92 93 When("API is unset", func() { 94 var ( 95 apiURL string 96 ) 97 98 BeforeEach(func() { 99 apiURL = helpers.GetAPI() 100 Expect(apiURL).ToNot(BeEmpty()) 101 helpers.UnsetAPI() 102 }) 103 104 It("doesn't panic when trying to call a plugin", func() { 105 session := helpers.CF("CoolTest") 106 Eventually(session).Should(Exit(1)) 107 108 Expect(session.Err).To(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 109 Expect(session).To(Say("FAILED")) 110 }) 111 }) 112 }) 113 }) 114 }) 115 })