github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/isolated/space_users_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  	. "github.com/onsi/gomega/gbytes"
     7  	. "github.com/onsi/gomega/gexec"
     8  
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    10  )
    11  
    12  var _ = Describe("space-users command", func() {
    13  	When("the user is logged in", func() {
    14  		var (
    15  			orgName       string
    16  			spaceName     string
    17  			adminUsername string
    18  		)
    19  
    20  		BeforeEach(func() {
    21  			adminUsername = helpers.LoginCF()
    22  			orgName = helpers.NewOrgName()
    23  			spaceName = helpers.NewSpaceName()
    24  			helpers.CreateOrgAndSpace(orgName, spaceName)
    25  		})
    26  
    27  		When("the target space has multiple users with different roles", func() {
    28  			var (
    29  				spaceManagerUser   string
    30  				spaceDeveloperUser string
    31  				spaceAuditorUser1  string
    32  				spaceAuditorUser2  string
    33  			)
    34  
    35  			BeforeEach(func() {
    36  				spaceManagerUser, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceManager")
    37  				spaceDeveloperUser, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceDeveloper")
    38  				spaceAuditorUser1, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceAuditor")
    39  				spaceAuditorUser2, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceAuditor")
    40  			})
    41  
    42  			It("prints the users in the target space under their roles", func() {
    43  				session := helpers.CF("space-users", orgName, spaceName)
    44  				Eventually(session).Should(Say("Getting users in org %s / space %s as %s", orgName, spaceName, adminUsername))
    45  				Eventually(session).Should(Say("SPACE MANAGER"))
    46  				Eventually(session).Should(Say(`\s+%s`, spaceManagerUser))
    47  				Eventually(session).Should(Say("SPACE DEVELOPER"))
    48  				Eventually(session).Should(Say(`\s+%s`, spaceDeveloperUser))
    49  				Eventually(session).Should(Say("SPACE AUDITOR"))
    50  				Eventually(session).Should(Say(`\s+%s`, spaceAuditorUser1))
    51  				Eventually(session).Should(Say(`\s+%s`, spaceAuditorUser2))
    52  				Eventually(session).Should(Exit(0))
    53  			})
    54  		})
    55  
    56  		When("the target space has a client-credentials user", func() {
    57  			var (
    58  				clientID         string
    59  				spaceManagerUser string
    60  			)
    61  
    62  			BeforeEach(func() {
    63  				spaceManagerUser, _ = helpers.CreateUserInSpaceRole(orgName, spaceName, "SpaceManager")
    64  				clientID, _ = helpers.SkipIfClientCredentialsNotSet()
    65  				Eventually(helpers.CF("set-space-role", clientID, orgName, spaceName, "SpaceDeveloper", "--client")).Should(Exit(0))
    66  			})
    67  
    68  			It("prints the client-credentials user", func() {
    69  				session := helpers.CF("space-users", orgName, spaceName)
    70  				Eventually(session).Should(Say("Getting users in org %s / space %s as %s", orgName, spaceName, adminUsername))
    71  				Eventually(session).Should(Say("SPACE MANAGER"))
    72  				Eventually(session).Should(Say(`\s+%s`, spaceManagerUser))
    73  				Eventually(session).Should(Say("SPACE DEVELOPER"))
    74  				Eventually(session).Should(Say(`\s+%s \(client\)`, clientID))
    75  				Eventually(session).Should(Say("SPACE AUDITOR"))
    76  				Eventually(session).Should(Say(`\s+No SPACE AUDITOR found`))
    77  				Eventually(session).Should(Exit(0))
    78  			})
    79  		})
    80  	})
    81  })