CheckEnvironmentTargetedCorrectly will confirm if the command requires an API to be targeted and logged in to run. It can optionally check if the command requires org and space to be targeted.
(targetedOrganizationRequired bool, targetedSpaceRequired bool, testOrg string, command ...string)
| 42 | // API to be targeted and logged in to run. It can optionally check if the |
| 43 | // command requires org and space to be targeted. |
| 44 | func CheckEnvironmentTargetedCorrectly(targetedOrganizationRequired bool, targetedSpaceRequired bool, testOrg string, command ...string) { |
| 45 | LoginCF() |
| 46 | |
| 47 | if targetedOrganizationRequired { |
| 48 | By("errors if org is not targeted") |
| 49 | session := CF(command...) |
| 50 | Eventually(session).Should(Say("FAILED")) |
| 51 | Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) |
| 52 | Eventually(session).Should(Exit(1)) |
| 53 | |
| 54 | if targetedSpaceRequired { |
| 55 | By("errors if space is not targeted") |
| 56 | TargetOrg(testOrg) |
| 57 | session := CF(command...) |
| 58 | Eventually(session).Should(Say("FAILED")) |
| 59 | Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) |
| 60 | Eventually(session).Should(Exit(1)) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | By("errors if user not logged in") |
| 65 | LogoutCF() |
| 66 | session := CF(command...) |
| 67 | Eventually(session).Should(Say("FAILED")) |
| 68 | Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' or 'cf login --sso' to log in\\.")) |
| 69 | Eventually(session).Should(Exit(1)) |
| 70 | |
| 71 | By("errors if cli not targeted") |
| 72 | UnsetAPI() |
| 73 | session = CF(command...) |
| 74 | Eventually(session).Should(Say("FAILED")) |
| 75 | Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) |
| 76 | Eventually(session).Should(Exit(1)) |
| 77 | } |
| 78 | |
| 79 | // UnrefactoredCheckEnvironmentTargetedCorrectly will confirm if the command requires an |
| 80 | // API to be targeted and logged in to run. It can optionally check if the |
no test coverage detected