github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v7/isolated/logs_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     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  var _ = Describe("Logs Command", func() {
    15  	Describe("help", func() {
    16  		It("displays command usage to output", func() {
    17  			session := helpers.CF("logs", "--help")
    18  			Eventually(session).Should(Say("NAME:"))
    19  			Eventually(session).Should(Say("logs - Tail or show recent logs for an app"))
    20  			Eventually(session).Should(Say("USAGE:"))
    21  			Eventually(session).Should(Say("cf logs APP_NAME"))
    22  			Eventually(session).Should(Say("OPTIONS:"))
    23  			Eventually(session).Should(Say(`--recent\s+Dump recent logs instead of tailing`))
    24  			Eventually(session).Should(Say("SEE ALSO:"))
    25  			Eventually(session).Should(Say("app, apps, ssh"))
    26  			Eventually(session).Should(Exit(0))
    27  		})
    28  	})
    29  
    30  	When("the environment is not setup correctly", func() {
    31  		It("fails with the appropriate errors", func() {
    32  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "logs", "app-name")
    33  		})
    34  	})
    35  
    36  	When("the environment is set up correctly", func() {
    37  		var (
    38  			orgName   string
    39  			spaceName string
    40  		)
    41  
    42  		BeforeEach(func() {
    43  			orgName = helpers.NewOrgName()
    44  			spaceName = helpers.NewSpaceName()
    45  			helpers.SetupCF(orgName, spaceName)
    46  		})
    47  
    48  		AfterEach(func() {
    49  			helpers.QuickDeleteOrg(orgName)
    50  		})
    51  
    52  		When("input is invalid", func() {
    53  			Context("because no app name is provided", func() {
    54  				It("gives an incorrect usage message", func() {
    55  					session := helpers.CF("logs")
    56  					Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    57  					Eventually(session).Should(Say("NAME:"))
    58  					Eventually(session).Should(Say("logs - Tail or show recent logs for an app"))
    59  					Eventually(session).Should(Say("USAGE:"))
    60  					Eventually(session).Should(Say("cf logs APP_NAME"))
    61  					Eventually(session).Should(Say("OPTIONS:"))
    62  					Eventually(session).Should(Say(`--recent\s+Dump recent logs instead of tailing`))
    63  					Eventually(session).Should(Say("SEE ALSO:"))
    64  					Eventually(session).Should(Say("app, apps, ssh"))
    65  					Eventually(session).Should(Exit(1))
    66  				})
    67  			})
    68  
    69  			Context("because the app does not exist", func() {
    70  				It("fails with an app not found message", func() {
    71  					session := helpers.CF("logs", "dora")
    72  					Eventually(session).Should(Say("FAILED"))
    73  					Eventually(session.Err).Should(Say("App 'dora' not found"))
    74  					Eventually(session).Should(Exit(1))
    75  				})
    76  			})
    77  		})
    78  
    79  		When("the specified app exists", func() {
    80  			var appName string
    81  
    82  			BeforeEach(func() {
    83  				appName = helpers.PrefixedRandomName("app")
    84  				helpers.WithHelloWorldApp(func(appDir string) {
    85  					Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "-u", "http", "--endpoint", "/")).Should(Exit(0))
    86  				})
    87  			})
    88  
    89  			Context("without the --recent flag", func() {
    90  				It("streams logs out to the screen", func() {
    91  					session := helpers.CF("logs", appName)
    92  					defer session.Terminate()
    93  
    94  					userName, _ := helpers.GetCredentials()
    95  					Eventually(session).Should(Say("Retrieving logs for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    96  
    97  					response, err := http.Get(fmt.Sprintf("http://%s.%s", appName, helpers.DefaultSharedDomain()))
    98  					Expect(err).NotTo(HaveOccurred())
    99  					Expect(response.StatusCode).To(Equal(http.StatusOK))
   100  					Eventually(session).Should(Say(`%s \[APP/PROC/WEB/0\]\s+OUT .*? \"GET / HTTP/1.1\" 200 \d+`, helpers.ISO8601Regex))
   101  				})
   102  			})
   103  
   104  			Context("with the --recent flag", func() {
   105  				It("displays the most recent logs and closes the stream", func() {
   106  					session := helpers.CF("logs", appName, "--recent")
   107  					userName, _ := helpers.GetCredentials()
   108  					Eventually(session).Should(Say("Retrieving logs for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   109  					Eventually(session).Should(Say(`%s \[API/\d+\]\s+OUT Created app with guid %s`, helpers.ISO8601Regex, helpers.GUIDRegex))
   110  					Eventually(session).Should(Exit(0))
   111  				})
   112  			})
   113  		})
   114  	})
   115  })