github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/plugin/plugin_suite_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  const (
    15  	CFEventuallyTimeout   = 180 * time.Second
    16  	CFConsistentlyTimeout = 500 * time.Millisecond
    17  )
    18  
    19  var (
    20  	// Suite Level
    21  	testPluginPath         string
    22  	overrideTestPluginPath string
    23  	panicTestPluginPath    string
    24  	apiURL                 string
    25  	skipSSLValidation      string
    26  
    27  	// Per Test Level
    28  	homeDir string
    29  )
    30  
    31  func TestGlobal(t *testing.T) {
    32  	RegisterFailHandler(Fail)
    33  	RunSpecs(t, "Plugin Suite")
    34  }
    35  
    36  var _ = SynchronizedBeforeSuite(func() []byte {
    37  	return nil
    38  }, func(path []byte) {
    39  	// Ginkgo Globals
    40  	SetDefaultEventuallyTimeout(CFEventuallyTimeout)
    41  	SetDefaultConsistentlyDuration(CFConsistentlyTimeout)
    42  
    43  	// Setup common environment variables
    44  	helpers.TurnOffColors()
    45  
    46  	var err error
    47  	testPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin")
    48  	Expect(err).ToNot(HaveOccurred())
    49  
    50  	overrideTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_command_overrides")
    51  	Expect(err).ToNot(HaveOccurred())
    52  
    53  	panicTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_panic")
    54  	Expect(err).ToNot(HaveOccurred())
    55  })
    56  
    57  var _ = AfterSuite(func() {
    58  	CleanupBuildArtifacts()
    59  })
    60  
    61  var _ = BeforeEach(func() {
    62  	homeDir = helpers.SetHomeDir()
    63  	apiURL, skipSSLValidation = helpers.SetAPI()
    64  	helpers.LoginCF()
    65  	Eventually(helpers.CF("remove-plugin-repo", "CF-Community")).Should(Exit(0))
    66  })
    67  
    68  var _ = AfterEach(func() {
    69  	GinkgoWriter.Write([]byte("==============================Global After Each=============================="))
    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  func confirmTestPluginOutput(command string, output ...string) {
    92  	session := helpers.CF(command)
    93  	for _, val := range output {
    94  		Eventually(session).Should(Say(val))
    95  	}
    96  	Eventually(session).Should(Exit(0))
    97  }
    98  
    99  func confirmTestPluginOutputWithArg(command string, arg string, output ...string) {
   100  	session := helpers.CF(command, arg)
   101  	for _, val := range output {
   102  		Eventually(session).Should(Say(val))
   103  	}
   104  	Eventually(session).Should(Exit(0))
   105  }