github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/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("not authenticated and not targeting an org or space", func() { 31 It("fails with the appropriate errors", func() { 32 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "logs", "app-name") 33 }) 34 }) 35 36 When("authenticated as a user and targeting an org and space", 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")).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 116 When("authenticated as a client and targeting an org and space", func() { 117 var ( 118 orgName string 119 spaceName string 120 clientName string 121 ) 122 123 BeforeEach(func() { 124 orgName = helpers.NewOrgName() 125 spaceName = helpers.NewSpaceName() 126 clientName = helpers.LoginCFWithClientCredentials() 127 helpers.CreateOrgAndSpace(orgName, spaceName) 128 helpers.TargetOrgAndSpace(orgName, spaceName) 129 }) 130 131 AfterEach(func() { 132 helpers.QuickDeleteOrg(orgName) 133 }) 134 135 When("the specified app exists", func() { 136 var appName string 137 138 BeforeEach(func() { 139 appName = helpers.PrefixedRandomName("app") 140 helpers.WithHelloWorldApp(func(appDir string) { 141 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "-u", "http")).Should(Exit(0)) 142 }) 143 }) 144 145 Context("without the --recent flag", func() { 146 It("streams logs out to the screen", func() { 147 session := helpers.CF("logs", appName) 148 defer session.Terminate() 149 150 Eventually(session).Should(Say("Retrieving logs for app %s in org %s / space %s as %s...", appName, orgName, spaceName, clientName)) 151 152 response, err := http.Get(fmt.Sprintf("http://%s.%s", appName, helpers.DefaultSharedDomain())) 153 Expect(err).NotTo(HaveOccurred()) 154 Expect(response.StatusCode).To(Equal(http.StatusOK)) 155 Eventually(session).Should(Say(`%s \[APP/PROC/WEB/0\]\s+OUT .*? \"GET / HTTP/1.1\" 200 \d+`, helpers.ISO8601Regex)) 156 }) 157 }) 158 159 Context("with the --recent flag", func() { 160 It("displays the most recent logs and closes the stream", func() { 161 session := helpers.CF("logs", appName, "--recent") 162 Eventually(session).Should(Say("Retrieving logs for app %s in org %s / space %s as %s...", appName, orgName, spaceName, clientName)) 163 Eventually(session).Should(Say(`%s \[API/\d+\]\s+OUT Created app with guid %s`, helpers.ISO8601Regex, helpers.GUIDRegex)) 164 Eventually(session).Should(Exit(0)) 165 }) 166 }) 167 }) 168 }) 169 170 })