github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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  )
    19  
    20  var (
    21  	// Suite Level
    22  	apiURL            string
    23  	skipSSLValidation string
    24  	ReadOnlyOrg       string
    25  	ReadOnlySpace     string
    26  
    27  	// Per Test Level
    28  	homeDir string
    29  )
    30  
    31  func TestIsolated(t *testing.T) {
    32  	RegisterFailHandler(Fail)
    33  	RunSpecs(t, "Isolated Integration Suite")
    34  }
    35  
    36  var _ = SynchronizedBeforeSuite(func() []byte {
    37  	return nil
    38  }, func(_ []byte) {
    39  	// Ginkgo Globals
    40  	SetDefaultEventuallyTimeout(CFEventuallyTimeout)
    41  	SetDefaultConsistentlyDuration(CFConsistentlyTimeout)
    42  
    43  	// Setup common environment variables
    44  	helpers.TurnOffColors()
    45  
    46  	ReadOnlyOrg, ReadOnlySpace = helpers.SetupReadOnlyOrgAndSpace()
    47  })
    48  
    49  var _ = BeforeEach(func() {
    50  	homeDir = helpers.SetHomeDir()
    51  	apiURL, skipSSLValidation = helpers.SetAPI()
    52  })
    53  
    54  var _ = AfterEach(func() {
    55  	helpers.DestroyHomeDir(homeDir)
    56  })
    57  
    58  var foundDefaultDomain string
    59  
    60  func defaultSharedDomain() string {
    61  	// TODO: Move this into helpers when other packages need it, figure out how
    62  	// to cache cuz this is a wacky call otherwise
    63  	if foundDefaultDomain == "" {
    64  		session := helpers.CF("domains")
    65  		Eventually(session).Should(Exit(0))
    66  
    67  		regex, err := regexp.Compile(`(.+?)\s+shared`)
    68  		Expect(err).ToNot(HaveOccurred())
    69  
    70  		matches := regex.FindStringSubmatch(string(session.Out.Contents()))
    71  		Expect(matches).To(HaveLen(2))
    72  
    73  		foundDefaultDomain = matches[1]
    74  	}
    75  	return foundDefaultDomain
    76  }
    77  
    78  func setupCF(org string, space string) {
    79  	helpers.LoginCF()
    80  	if org != ReadOnlyOrg && space != ReadOnlySpace {
    81  		helpers.CreateOrgAndSpace(org, space)
    82  	}
    83  	helpers.TargetOrgAndSpace(org, space)
    84  }