github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/integration/shared/plugin/plugin_suite_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"os"
     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/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      bool
    27  
    28  	// Per Test Level
    29  	homeDir string
    30  )
    31  
    32  func TestPlugin(t *testing.T) {
    33  	RegisterFailHandler(Fail)
    34  	reporters := []Reporter{}
    35  
    36  	prBuilderReporter := helpers.GetPRBuilderReporter()
    37  	if prBuilderReporter != nil {
    38  		reporters = append(reporters, prBuilderReporter)
    39  	}
    40  
    41  	RunSpecsWithDefaultAndCustomReporters(t, "Plugin Suite", reporters)
    42  }
    43  
    44  var _ = SynchronizedBeforeSuite(func() []byte {
    45  	return nil
    46  }, func(path []byte) {
    47  	// Ginkgo Globals
    48  	SetDefaultEventuallyTimeout(CFEventuallyTimeout)
    49  	SetDefaultConsistentlyDuration(CFConsistentlyTimeout)
    50  
    51  	// Setup common environment variables
    52  	helpers.TurnOffColors()
    53  
    54  	var err error
    55  	testPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin")
    56  	Expect(err).ToNot(HaveOccurred())
    57  
    58  	overrideTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_command_overrides")
    59  	Expect(err).ToNot(HaveOccurred())
    60  
    61  	panicTestPluginPath, err = Build("code.cloudfoundry.org/cli/integration/assets/test_plugin_with_panic")
    62  	Expect(err).ToNot(HaveOccurred())
    63  })
    64  
    65  var _ = SynchronizedAfterSuite(func() {
    66  	CleanupBuildArtifacts()
    67  },
    68  	func() {
    69  		outputRoot := os.Getenv(helpers.PRBuilderOutputEnvVar)
    70  		if outputRoot != "" {
    71  			helpers.WriteFailureSummary(outputRoot, "summary_isplugins.txt")
    72  		}
    73  	},
    74  )
    75  
    76  var _ = BeforeEach(func() {
    77  	homeDir = helpers.SetHomeDir()
    78  	apiURL, skipSSLValidation = helpers.SetAPI()
    79  	helpers.LoginCF()
    80  	Eventually(helpers.CF("remove-plugin-repo", "CF-Community")).Should(Exit(0))
    81  })
    82  
    83  var _ = AfterEach(func() {
    84  	GinkgoWriter.Write([]byte("==============================Global After Each=============================="))
    85  	helpers.DestroyHomeDir(homeDir)
    86  })
    87  
    88  func installTestPlugin() {
    89  	session := helpers.CF("install-plugin", "-f", testPluginPath)
    90  	Eventually(session).Should(Exit(0))
    91  }
    92  
    93  func uninstallTestPlugin() {
    94  	session := helpers.CF("uninstall-plugin", "CF-CLI-Integration-Test-Plugin")
    95  	Eventually(session).Should(Exit(0))
    96  }
    97  
    98  func createTargetedOrgAndSpace() (string, string) {
    99  	org := helpers.NewOrgName()
   100  	space := helpers.NewSpaceName()
   101  	helpers.CreateOrgAndSpace(org, space)
   102  	helpers.TargetOrgAndSpace(org, space)
   103  	return org, space
   104  }
   105  
   106  func confirmTestPluginOutput(command string, output ...string) {
   107  	session := helpers.CF(command)
   108  	for _, val := range output {
   109  		Eventually(session).Should(Say(val))
   110  	}
   111  	Eventually(session).Should(Exit(0))
   112  }
   113  
   114  func confirmTestPluginOutputWithArg(command string, arg string, output ...string) {
   115  	session := helpers.CF(command, arg)
   116  	for _, val := range output {
   117  		Eventually(session).Should(Say(val))
   118  	}
   119  	Eventually(session).Should(Exit(0))
   120  }