github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/plugin/plugin_suite_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/liamawhite/cli-with-i18n/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("github.com/liamawhite/cli-with-i18n/integration/assets/test_plugin")
    49  	Expect(err).ToNot(HaveOccurred())
    50  
    51  	overrideTestPluginPath, err = Build("github.com/liamawhite/cli-with-i18n/integration/assets/test_plugin_with_command_overrides")
    52  	Expect(err).ToNot(HaveOccurred())
    53  
    54  	panicTestPluginPath, err = Build("github.com/liamawhite/cli-with-i18n/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  	helpers.DestroyHomeDir(homeDir)
    71  })
    72  
    73  func installTestPlugin() {
    74  	session := helpers.CF("install-plugin", "-f", testPluginPath)
    75  	Eventually(session).Should(Exit(0))
    76  }
    77  
    78  func uninstallTestPlugin() {
    79  	session := helpers.CF("uninstall-plugin", "CF-CLI-Integration-Test-Plugin")
    80  	Eventually(session).Should(Exit(0))
    81  }
    82  
    83  func createTargetedOrgAndSpace() (string, string) {
    84  	org := helpers.NewOrgName()
    85  	space := helpers.NewSpaceName()
    86  	helpers.CreateOrgAndSpace(org, space)
    87  	helpers.TargetOrgAndSpace(org, space)
    88  	return org, space
    89  }
    90  
    91  var foundDefaultDomain string
    92  
    93  func defaultSharedDomain() string {
    94  	// TODO: Move this into helpers when other packages need it, figure out how
    95  	// to cache cuz this is a wacky call otherwise
    96  	if foundDefaultDomain == "" {
    97  		session := helpers.CF("domains")
    98  		Eventually(session).Should(Exit(0))
    99  
   100  		regex, err := regexp.Compile(`(.+?)\s+shared`)
   101  		Expect(err).ToNot(HaveOccurred())
   102  
   103  		matches := regex.FindStringSubmatch(string(session.Out.Contents()))
   104  		Expect(matches).To(HaveLen(2))
   105  
   106  		foundDefaultDomain = matches[1]
   107  	}
   108  	return foundDefaultDomain
   109  }
   110  
   111  func confirmTestPluginOutput(command string, output ...string) {
   112  	session := helpers.CF(command)
   113  	for _, val := range output {
   114  		Eventually(session).Should(Say(val))
   115  	}
   116  	Eventually(session).Should(Exit(0))
   117  }
   118  
   119  func confirmTestPluginOutputWithArg(command string, arg string, output ...string) {
   120  	session := helpers.CF(command, arg)
   121  	for _, val := range output {
   122  		Eventually(session).Should(Say(val))
   123  	}
   124  	Eventually(session).Should(Exit(0))
   125  }