github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/isolated/isolated_suite_test.go (about)

     1  package isolated
     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/gexec"
    12  )
    13  
    14  const (
    15  	CFEventuallyTimeout   = 300 * time.Second
    16  	CFConsistentlyTimeout = 500 * time.Millisecond
    17  	RealIsolationSegment  = "persistent_isolation_segment"
    18  	DockerImage           = "cloudfoundry/diego-docker-app-custom"
    19  )
    20  
    21  var (
    22  	// Suite Level
    23  	apiURL            string
    24  	skipSSLValidation string
    25  	ReadOnlyOrg       string
    26  	ReadOnlySpace     string
    27  
    28  	// Per Test Level
    29  	homeDir string
    30  )
    31  
    32  func TestIsolated(t *testing.T) {
    33  	RegisterFailHandler(Fail)
    34  	RunSpecs(t, "Isolated Integration Suite")
    35  }
    36  
    37  var _ = SynchronizedBeforeSuite(func() []byte {
    38  	return nil
    39  }, func(_ []byte) {
    40  	// Ginkgo Globals
    41  	SetDefaultEventuallyTimeout(CFEventuallyTimeout)
    42  	SetDefaultConsistentlyDuration(CFConsistentlyTimeout)
    43  
    44  	// Setup common environment variables
    45  	helpers.TurnOffColors()
    46  
    47  	helpers.SetupSynchronizedSuite(func() {
    48  		helpers.EnableFeatureFlag("diego_docker")
    49  		helpers.EnableFeatureFlag("service_instance_sharing")
    50  	})
    51  
    52  	ReadOnlyOrg, ReadOnlySpace = helpers.SetupReadOnlyOrgAndSpace()
    53  })
    54  
    55  var _ = SynchronizedAfterSuite(func() {
    56  	helpers.SetAPI()
    57  	helpers.LoginCF()
    58  	helpers.QuickDeleteOrg(ReadOnlyOrg)
    59  }, func() {
    60  })
    61  
    62  var _ = BeforeEach(func() {
    63  	homeDir = helpers.SetHomeDir()
    64  	apiURL, skipSSLValidation = helpers.SetAPI()
    65  })
    66  
    67  var _ = AfterEach(func() {
    68  	GinkgoWriter.Write([]byte("==============================Global After Each=============================="))
    69  	helpers.DestroyHomeDir(homeDir)
    70  })
    71  
    72  var foundDefaultDomain string
    73  
    74  func defaultSharedDomain() string {
    75  	// TODO: Move this into helpers when other packages need it, figure out how
    76  	// to cache cuz this is a wacky call otherwise
    77  	if foundDefaultDomain == "" {
    78  		session := helpers.CF("domains")
    79  		Eventually(session).Should(Exit(0))
    80  
    81  		regex, err := regexp.Compile(`(.+?)\s+shared`)
    82  		Expect(err).ToNot(HaveOccurred())
    83  
    84  		matches := regex.FindStringSubmatch(string(session.Out.Contents()))
    85  		Expect(matches).To(HaveLen(2))
    86  
    87  		foundDefaultDomain = matches[1]
    88  	}
    89  	return foundDefaultDomain
    90  }
    91  
    92  func setupCF(org string, space string) {
    93  	helpers.LoginCF()
    94  	if org != ReadOnlyOrg && space != ReadOnlySpace {
    95  		helpers.CreateOrgAndSpace(org, space)
    96  	}
    97  	helpers.TargetOrgAndSpace(org, space)
    98  }