github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/delete_user_command_test.go (about) 1 package isolated 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("delete-user command", func() { 15 Context("when the logged in user is authorized to delete-users", func() { 16 BeforeEach(func() { 17 helpers.LoginCF() 18 }) 19 20 Context("when deleting a user that exists in multiple origins", func() { 21 var newUser string 22 23 BeforeEach(func() { 24 newUser = helpers.RandomUsername() 25 Eventually(helpers.CF("create-user", newUser, "--origin", "ldap")).Should(Exit(0)) 26 Eventually(helpers.CF("create-user", newUser, helpers.RandomPassword())).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 session := helpers.CF("curl", "/v2/users") 33 Eventually(session).Should(Exit(0)) 34 35 var usersResponse struct { 36 Resources []struct { 37 Metadata struct { 38 GUID string `json:"guid"` 39 } `json:"metadata"` 40 Entity struct { 41 UserName string `json:"username"` 42 } `json:"entity"` 43 } `json:"resources"` 44 } 45 46 err := json.Unmarshal(session.Out.Contents(), &usersResponse) 47 Expect(err).NotTo(HaveOccurred()) 48 49 for _, user := range usersResponse.Resources { 50 if user.Entity.UserName == newUser { 51 Eventually(helpers.CF("curl", "-X", "DELETE", fmt.Sprintf("/v2/users/%s", user.Metadata.GUID))).Should(Exit(0)) 52 } 53 } 54 }) 55 56 It("errors with DuplicateUsernameError", func() { 57 session := helpers.CF("delete-user", "-f", newUser) 58 Eventually(session.Out).Should(Say("FAILED")) 59 Eventually(session.Out).Should(Say("Error deleting user %s", newUser)) 60 Eventually(session.Out).Should(Say("Multiple users with that username found. Please use 'cf curl' to delete the user by guid instead.")) 61 Eventually(session).Should(Exit(1)) 62 }) 63 }) 64 }) 65 })