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

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     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("delete-user command", func() {
    14  	When("the logged in user is authorized to delete-users", func() {
    15  		BeforeEach(func() {
    16  			helpers.LoginCF()
    17  		})
    18  
    19  		When("deleting a user that exists in multiple origins", func() {
    20  			var newUser string
    21  
    22  			BeforeEach(func() {
    23  				newUser = helpers.NewUsername()
    24  
    25  				Eventually(helpers.CF("create-user", newUser, "--origin", "ldap")).Should(Exit(0))
    26  				Eventually(helpers.CF("create-user", newUser, helpers.NewPassword())).Should(Exit(0))
    27  			})
    28  
    29  			AfterEach(func() {
    30  				// Doing the cleanup here because it can't easily be done in
    31  				// bin/cleanup-integration.
    32  				users := helpers.GetUsers()
    33  
    34  				var usersDeleted int
    35  				for _, user := range users {
    36  					if user.Username == newUser {
    37  						Eventually(helpers.CF("curl", "-X", "DELETE", fmt.Sprintf("/v2/users/%s", user.GUID))).Should(Exit(0))
    38  						usersDeleted++
    39  					}
    40  				}
    41  
    42  				Expect(usersDeleted).To(Equal(2), "some users were not deleted")
    43  			})
    44  
    45  			It("errors with DuplicateUsernameError", func() {
    46  				session := helpers.CF("delete-user", "-f", newUser)
    47  				Eventually(session).Should(Say("FAILED"))
    48  				Eventually(session).Should(Say("Error deleting user %s", newUser))
    49  				Eventually(session).Should(Say("The user exists in multiple origins."))
    50  				Eventually(session).Should(Exit(1))
    51  			})
    52  		})
    53  	})
    54  })