github.com/loafoe/cli@v7.1.0+incompatible/integration/shared/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      bool
    26  
    27  	// Per Test Level
    28  	homeDir string
    29  )
    30  
    31  func TestPlugin(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 _ = SynchronizedAfterSuite(func() {
    58  	CleanupBuildArtifacts()
    59  },
    60  	func() {},
    61  )
    62  
    63  var _ = BeforeEach(func() {
    64  	homeDir = helpers.SetHomeDir()
    65  	apiURL, skipSSLValidation = helpers.SetAPI()
    66  	helpers.LoginCF()
    67  	Eventually(helpers.CF("remove-plugin-repo", "CF-Community")).Should(Exit(0))
    68  })
    69  
    70  var _ = AfterEach(func() {
    71  	GinkgoWriter.Write([]byte("==============================Global After Each=============================="))
    72  	helpers.DestroyHomeDir(homeDir)
    73  })
    74  
    75  func installTestPlugin() {
    76  	session := helpers.CF("install-plugin", "-f", testPluginPath)
    77  	Eventually(session).Should(Exit(0))
    78  }
    79  
    80  func uninstallTestPlugin() {
    81  	session := helpers.CF("uninstall-plugin", "CF-CLI-Integration-Test-Plugin")
    82  	Eventually(session).Should(Exit(0))
    83  }
    84  
    85  func createTargetedOrgAndSpace() (string, string) {
    86  	org := helpers.NewOrgName()
    87  	space := helpers.NewSpaceName()
    88  	username, _ := helpers.GetCredentials()
    89  	helpers.CreateOrgAndSpace(org, space)
    90  	helpers.TargetOrgAndSpace(org, space)
    91  	helpers.SetOrgRole(username, org, "OrgManager", helpers.ClientCredentialsTestMode())
    92  	helpers.SetSpaceRole(username, org, space, "SpaceDeveloper", helpers.ClientCredentialsTestMode())
    93  	helpers.SetSpaceRole(username, org, space, "SpaceManager", helpers.ClientCredentialsTestMode())
    94  	return org, space
    95  }
    96  
    97  func confirmTestPluginOutput(command string, output ...string) {
    98  	session := helpers.CF(command)
    99  	for _, val := range output {
   100  		Eventually(session).Should(Say(val))
   101  	}
   102  	Eventually(session).Should(Exit(0))
   103  }
   104  
   105  func confirmTestPluginOutputWithArg(command string, arg string, output ...string) {
   106  	session := helpers.CF(command, arg)
   107  	for _, val := range output {
   108  		Eventually(session).Should(Say(val))
   109  	}
   110  	Eventually(session).Should(Exit(0))
   111  }