github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/plugin/plugin_suite_test.go (about) 1 package plugin 2 3 import ( 4 "regexp" 5 "testing" 6 "time" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 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 const ( 16 CFEventuallyTimeout = 180 * time.Second 17 CFConsistentlyTimeout = 500 * time.Millisecond 18 ) 19 20 var ( 21 // Suite Level 22 testPluginPath string 23 overrideTestPluginPath string 24 panicTestPluginPath string 25 apiURL string 26 skipSSLValidation string 27 28 // Per Test Level 29 homeDir string 30 ) 31 32 func TestGlobal(t *testing.T) { 33 RegisterFailHandler(Fail) 34 RunSpecs(t, "Plugin Suite") 35 } 36 37 var _ = SynchronizedBeforeSuite(func() []byte { 38 return nil 39 }, func(path []byte) { 40 // Ginkgo Globals 41 SetDefaultEventuallyTimeout(CFEventuallyTimeout) 42 SetDefaultConsistentlyDuration(CFConsistentlyTimeout) 43 44 // Setup common environment variables 45 helpers.TurnOffColors() 46 47 var err error 48 testPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin") 49 Expect(err).ToNot(HaveOccurred()) 50 51 overrideTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_command_overrides") 52 Expect(err).ToNot(HaveOccurred()) 53 54 panicTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_panic") 55 Expect(err).ToNot(HaveOccurred()) 56 }) 57 58 var _ = AfterSuite(func() { 59 CleanupBuildArtifacts() 60 }) 61 62 var _ = BeforeEach(func() { 63 homeDir = helpers.SetHomeDir() 64 apiURL, skipSSLValidation = helpers.SetAPI() 65 helpers.LoginCF() 66 Eventually(helpers.CF("remove-plugin-repo", "CF-Community")).Should(Exit(0)) 67 }) 68 69 var _ = AfterEach(func() { 70 GinkgoWriter.Write([]byte("==============================Global After Each==============================")) 71 helpers.DestroyHomeDir(homeDir) 72 }) 73 74 func installTestPlugin() { 75 session := helpers.CF("install-plugin", "-f", testPluginPath) 76 Eventually(session).Should(Exit(0)) 77 } 78 79 func uninstallTestPlugin() { 80 session := helpers.CF("uninstall-plugin", "CF-CLI-Integration-Test-Plugin") 81 Eventually(session).Should(Exit(0)) 82 } 83 84 func createTargetedOrgAndSpace() (string, string) { 85 org := helpers.NewOrgName() 86 space := helpers.NewSpaceName() 87 helpers.CreateOrgAndSpace(org, space) 88 helpers.TargetOrgAndSpace(org, space) 89 return org, space 90 } 91 92 var foundDefaultDomain string 93 94 func defaultSharedDomain() string { 95 // TODO: Move this into helpers when other packages need it, figure out how 96 // to cache cuz this is a wacky call otherwise 97 if foundDefaultDomain == "" { 98 session := helpers.CF("domains") 99 Eventually(session).Should(Exit(0)) 100 101 regex, err := regexp.Compile(`(.+?)\s+shared`) 102 Expect(err).ToNot(HaveOccurred()) 103 104 matches := regex.FindStringSubmatch(string(session.Out.Contents())) 105 Expect(matches).To(HaveLen(2)) 106 107 foundDefaultDomain = matches[1] 108 } 109 return foundDefaultDomain 110 } 111 112 func confirmTestPluginOutput(command string, output ...string) { 113 session := helpers.CF(command) 114 for _, val := range output { 115 Eventually(session).Should(Say(val)) 116 } 117 Eventually(session).Should(Exit(0)) 118 } 119 120 func confirmTestPluginOutputWithArg(command string, arg string, output ...string) { 121 session := helpers.CF(command, arg) 122 for _, val := range output { 123 Eventually(session).Should(Say(val)) 124 } 125 Eventually(session).Should(Exit(0)) 126 }