github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/org_users_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("org-users command", func() { 14 Describe("help", func() { 15 When("--help flag is set", func() { 16 It("displays command usage to output", func() { 17 session := helpers.CF("org-users", "--help") 18 Eventually(session).Should(Say("NAME:")) 19 Eventually(session).Should(Say("org-users - Show org users by role")) 20 Eventually(session).Should(Say("USAGE:")) 21 Eventually(session).Should(Say(regexp.QuoteMeta("cf org-users ORG"))) 22 Eventually(session).Should(Say("OPTIONS:")) 23 Eventually(session).Should(Say(`--all-users, -a \s+List all users with roles in the org or in spaces within the org`)) 24 Eventually(session).Should(Say("SEE ALSO:")) 25 Eventually(session).Should(Say("orgs, set-org-role")) 26 Eventually(session).Should(Exit(0)) 27 }) 28 }) 29 }) 30 31 When("the user is logged in", func() { 32 var ( 33 orgName string 34 adminUsername string 35 ) 36 37 BeforeEach(func() { 38 adminUsername = helpers.LoginCF() 39 orgName = helpers.NewOrgName() 40 helpers.CreateOrg(orgName) 41 }) 42 43 When("the target org has multiple users with different roles", func() { 44 var ( 45 orgManagerUser string 46 billingManagerUser string 47 orgAuditorUser string 48 ) 49 50 BeforeEach(func() { 51 orgManagerUser, _ = helpers.CreateUserInOrgRole(orgName, "OrgManager") 52 billingManagerUser, _ = helpers.CreateUserInOrgRole(orgName, "BillingManager") 53 orgAuditorUser, _ = helpers.CreateUserInOrgRole(orgName, "OrgAuditor") 54 }) 55 56 It("prints the users in the target org under their roles", func() { 57 session := helpers.CF("org-users", orgName) 58 Eventually(session).Should(Say("Getting users in org %s as %s", orgName, adminUsername)) 59 Eventually(session).Should(Say("ORG MANAGER")) 60 Eventually(session).Should(Say(`\s+%s \(uaa\)`, orgManagerUser)) 61 Eventually(session).Should(Say("BILLING MANAGER")) 62 Eventually(session).Should(Say(`\s+%s \(uaa\)`, billingManagerUser)) 63 Eventually(session).Should(Say("ORG AUDITOR")) 64 Eventually(session).Should(Say(`\s+%s \(uaa\)`, orgAuditorUser)) 65 Eventually(session).Should(Exit(0)) 66 }) 67 68 When("the --all-users flag is given", func() { 69 It("prints all users in the org, grouped under USERS", func() { 70 session := helpers.CF("org-users", orgName, "--all-users") 71 Eventually(session).Should(Say("Getting users in org %s as %s", orgName, adminUsername)) 72 Eventually(session).Should(Say("USERS")) 73 Eventually(session).Should(Exit(0)) 74 Expect(session.Out.Contents()).To(MatchRegexp(`\s+%s \(uaa\)`, orgManagerUser)) 75 Expect(session.Out.Contents()).To(MatchRegexp(`\s+%s \(uaa\)`, billingManagerUser)) 76 Expect(session.Out.Contents()).To(MatchRegexp(`\s+%s \(uaa\)`, orgAuditorUser)) 77 }) 78 }) 79 }) 80 81 When("the target org has a client-credentials user", func() { 82 var clientID string 83 84 BeforeEach(func() { 85 clientID, _ = helpers.SkipIfClientCredentialsNotSet() 86 Eventually(helpers.CF("set-org-role", clientID, orgName, "OrgManager", "--client")).Should(Exit(0)) 87 }) 88 89 It("prints the client-credentials user", func() { 90 session := helpers.CF("org-users", orgName) 91 Eventually(session).Should(Say("Getting users in org %s as %s", orgName, adminUsername)) 92 Eventually(session).Should(Say("ORG MANAGER")) 93 Eventually(session).Should(Say(`\s+%s \(client\)`, clientID)) 94 Eventually(session).Should(Say("BILLING MANAGER")) 95 Eventually(session).Should(Say(`\s+No BILLING MANAGER found`)) 96 Eventually(session).Should(Say("ORG AUDITOR")) 97 Eventually(session).Should(Say(`\s+No ORG AUDITOR found`)) 98 Eventually(session).Should(Exit(0)) 99 }) 100 }) 101 }) 102 })