github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/space_users_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 11 "code.cloudfoundry.org/cli/integration/helpers" 12 ) 13 14 var _ = Describe("space-users command", func() { 15 Describe("help", func() { 16 When("--help flag is set", func() { 17 It("displays command usage to output", func() { 18 session := helpers.CF("space-users", "--help") 19 Eventually(session).Should(Say("NAME:")) 20 Eventually(session).Should(Say("space-users - Show space users by role")) 21 Eventually(session).Should(Say("USAGE:")) 22 Eventually(session).Should(Say(regexp.QuoteMeta("cf space-users ORG SPACE"))) 23 Eventually(session).Should(Say("SEE ALSO:")) 24 Eventually(session).Should(Say("org-users, orgs, set-space-role, spaces, unset-space-role")) 25 Eventually(session).Should(Exit(0)) 26 }) 27 }) 28 }) 29 30 When("the user is logged in", func() { 31 var ( 32 orgName string 33 spaceName string 34 adminUsername string 35 ) 36 37 BeforeEach(func() { 38 adminUsername = helpers.LoginCF() 39 orgName = helpers.NewOrgName() 40 spaceName = helpers.NewSpaceName() 41 helpers.CreateOrgAndSpace(orgName, spaceName) 42 }) 43 44 When("the target space has multiple users with different roles", func() { 45 var ( 46 spaceManagerUser string 47 spaceDeveloperUser string 48 spaceAuditorUser1 string 49 ) 50 51 BeforeEach(func() { 52 spaceManagerUser, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceManager") 53 spaceDeveloperUser, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceDeveloper") 54 spaceAuditorUser1, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceAuditor") 55 }) 56 57 It("prints the users in the target space under their roles", func() { 58 session := helpers.CF("space-users", orgName, spaceName) 59 Eventually(session).Should(Say("Getting users in org %s / space %s as %s", orgName, spaceName, adminUsername)) 60 Eventually(session).Should(Say("SPACE MANAGER")) 61 Eventually(session).Should(Say(`\s+%s \(uaa\)`, spaceManagerUser)) 62 Eventually(session).Should(Say("SPACE DEVELOPER")) 63 Eventually(session).Should(Say(`\s+%s \(uaa\)`, spaceDeveloperUser)) 64 Eventually(session).Should(Say("SPACE AUDITOR")) 65 Eventually(session).Should(Say(`\s+%s \(uaa\)`, spaceAuditorUser1)) 66 Eventually(session).Should(Exit(0)) 67 }) 68 }) 69 70 When("the target space has a client-credentials user", func() { 71 var ( 72 clientID string 73 spaceManagerUser string 74 ) 75 76 BeforeEach(func() { 77 spaceManagerUser, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceManager") 78 clientID, _ = helpers.SkipIfClientCredentialsNotSet() 79 Eventually(helpers.CF("set-space-role", clientID, orgName, spaceName, "SpaceDeveloper", "--client")).Should(Exit(0)) 80 }) 81 82 It("prints the client-credentials user", func() { 83 session := helpers.CF("space-users", orgName, spaceName) 84 Eventually(session).Should(Say("Getting users in org %s / space %s as %s", orgName, spaceName, adminUsername)) 85 Eventually(session).Should(Say("SPACE MANAGER")) 86 Eventually(session).Should(Say(`\s+%s`, spaceManagerUser)) 87 Eventually(session).Should(Say("SPACE DEVELOPER")) 88 Eventually(session).Should(Say(`\s+%s \(client\)`, clientID)) 89 Eventually(session).Should(Say("SPACE AUDITOR")) 90 Eventually(session).Should(Say(`\s+No SPACE AUDITOR found`)) 91 Eventually(session).Should(Exit(0)) 92 }) 93 }) 94 }) 95 })