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