github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/events_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("events command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		appName   string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  		appName = helpers.PrefixedRandomName("app1")
    23  	})
    24  
    25  	Describe("help", func() {
    26  		When("--help flag is set", func() {
    27  			It("appears in cf help -a", func() {
    28  				session := helpers.CF("help", "-a")
    29  				Eventually(session).Should(Exit(0))
    30  				Expect(session).To(HaveCommandInCategoryWithDescription("events", "APPS", "Show recent app events"))
    31  			})
    32  
    33  			It("Displays command usage to output", func() {
    34  				session := helpers.CF("events", "--help")
    35  
    36  				Eventually(session).Should(Say("NAME:"))
    37  				Eventually(session).Should(Say("events - Show recent app events"))
    38  				Eventually(session).Should(Say("USAGE:"))
    39  				Eventually(session).Should(Say("cf events APP_NAME"))
    40  				Eventually(session).Should(Say("SEE ALSO:"))
    41  				Eventually(session).Should(Say("app, logs, map-route, unmap-route"))
    42  
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	When("the environment is not setup correctly", func() {
    49  		It("fails with the appropriate errors", func() {
    50  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "events", appName)
    51  		})
    52  	})
    53  
    54  	When("the environment is set up correctly", func() {
    55  		var userName string
    56  
    57  		BeforeEach(func() {
    58  			helpers.SetupCF(orgName, spaceName)
    59  			userName, _ = helpers.GetCredentials()
    60  		})
    61  
    62  		AfterEach(func() {
    63  			helpers.QuickDeleteOrg(orgName)
    64  		})
    65  
    66  		Context("with an existing app", func() {
    67  			BeforeEach(func() {
    68  				session := helpers.CF("create-app", appName)
    69  				Eventually(session).Should(Exit(0))
    70  				session = helpers.CF("rename", appName, "other-app-name")
    71  				Eventually(session).Should(Exit(0))
    72  				session = helpers.CF("rename", "other-app-name", appName)
    73  				Eventually(session).Should(Exit(0))
    74  			})
    75  
    76  			It("displays events in the list", func() {
    77  
    78  				// Order of output is hard to assert here so we will just asseert we output only the events we expect and then rely on the unit
    79  				// tests to validate we are passing the `order_by=-created_at` query param to CAPI. The actual ordering is CAPIs concern.
    80  				session := helpers.CF("events", appName)
    81  
    82  				if helpers.ClientCredentialsTestMode() {
    83  					Eventually(session).Should(Say(`Getting events for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    84  					Eventually(session).Should(Say(`time\s+event\s+actor\s+description`))
    85  					Eventually(session).Should(Say(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{2}[-+]\d{4}\s+audit\.app\.(update|create)`))
    86  					Eventually(session).Should(Say(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{2}[-+]\d{4}\s+audit\.app\.(update|create)`))
    87  					Eventually(session).Should(Say(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{2}[-+]\d{4}\s+audit\.app\.(update|create)`))
    88  				} else {
    89  					Eventually(session).Should(Say(`Getting events for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    90  					Eventually(session).Should(Say(`time\s+event\s+actor\s+description`))
    91  					Eventually(session).Should(Say(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{2}[-+]\d{4}\s+audit\.app\.(update|create)\s+%s`, userName))
    92  					Eventually(session).Should(Say(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{2}[-+]\d{4}\s+audit\.app\.(update|create)\s+%s`, userName))
    93  					Eventually(session).Should(Say(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{2}[-+]\d{4}\s+audit\.app\.(update|create)\s+%s`, userName))
    94  				}
    95  				Eventually(session).Should(Exit(0))
    96  			})
    97  		})
    98  	})
    99  })