github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/plugin/plugin_suite_test.go (about) 1 package plugin 2 3 import ( 4 "testing" 5 "time" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 const ( 15 CFEventuallyTimeout = 180 * time.Second 16 CFConsistentlyTimeout = 500 * time.Millisecond 17 ) 18 19 var ( 20 // Suite Level 21 testPluginPath string 22 overrideTestPluginPath string 23 panicTestPluginPath string 24 apiURL string 25 skipSSLValidation string 26 27 // Per Test Level 28 homeDir string 29 ) 30 31 func TestGlobal(t *testing.T) { 32 RegisterFailHandler(Fail) 33 reporters := []Reporter{} 34 35 honeyCombReporter := helpers.GetHoneyCombReporter("Plugin Suite") 36 37 if honeyCombReporter != nil { 38 reporters = append(reporters, honeyCombReporter) 39 } 40 41 RunSpecsWithDefaultAndCustomReporters(t, "Plugin Suite", reporters) 42 } 43 44 var _ = SynchronizedBeforeSuite(func() []byte { 45 return nil 46 }, func(path []byte) { 47 // Ginkgo Globals 48 SetDefaultEventuallyTimeout(CFEventuallyTimeout) 49 SetDefaultConsistentlyDuration(CFConsistentlyTimeout) 50 51 // Setup common environment variables 52 helpers.TurnOffColors() 53 54 var err error 55 testPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin") 56 Expect(err).ToNot(HaveOccurred()) 57 58 overrideTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_command_overrides") 59 Expect(err).ToNot(HaveOccurred()) 60 61 panicTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_panic") 62 Expect(err).ToNot(HaveOccurred()) 63 }) 64 65 var _ = AfterSuite(func() { 66 CleanupBuildArtifacts() 67 }) 68 69 var _ = BeforeEach(func() { 70 homeDir = helpers.SetHomeDir() 71 apiURL, skipSSLValidation = helpers.SetAPI() 72 helpers.LoginCF() 73 Eventually(helpers.CF("remove-plugin-repo", "CF-Community")).Should(Exit(0)) 74 }) 75 76 var _ = AfterEach(func() { 77 GinkgoWriter.Write([]byte("==============================Global After Each==============================")) 78 helpers.DestroyHomeDir(homeDir) 79 }) 80 81 func installTestPlugin() { 82 session := helpers.CF("install-plugin", "-f", testPluginPath) 83 Eventually(session).Should(Exit(0)) 84 } 85 86 func uninstallTestPlugin() { 87 session := helpers.CF("uninstall-plugin", "CF-CLI-Integration-Test-Plugin") 88 Eventually(session).Should(Exit(0)) 89 } 90 91 func createTargetedOrgAndSpace() (string, string) { 92 org := helpers.NewOrgName() 93 space := helpers.NewSpaceName() 94 helpers.CreateOrgAndSpace(org, space) 95 helpers.TargetOrgAndSpace(org, space) 96 return org, space 97 } 98 99 func confirmTestPluginOutput(command string, output ...string) { 100 session := helpers.CF(command) 101 for _, val := range output { 102 Eventually(session).Should(Say(val)) 103 } 104 Eventually(session).Should(Exit(0)) 105 } 106 107 func confirmTestPluginOutputWithArg(command string, arg string, output ...string) { 108 session := helpers.CF(command, arg) 109 for _, val := range output { 110 Eventually(session).Should(Say(val)) 111 } 112 Eventually(session).Should(Exit(0)) 113 }