github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/cf/api/password/password_test.go (about) 1 package password_test 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "time" 7 8 "code.cloudfoundry.org/cli/cf/api/apifakes" 9 "code.cloudfoundry.org/cli/cf/net" 10 "code.cloudfoundry.org/cli/cf/terminal/terminalfakes" 11 testconfig "code.cloudfoundry.org/cli/util/testhelpers/configuration" 12 testnet "code.cloudfoundry.org/cli/util/testhelpers/net" 13 14 . "code.cloudfoundry.org/cli/cf/api/password" 15 "code.cloudfoundry.org/cli/cf/trace/tracefakes" 16 . "code.cloudfoundry.org/cli/util/testhelpers/matchers" 17 . "github.com/onsi/ginkgo" 18 . "github.com/onsi/gomega" 19 ) 20 21 var _ = Describe("CloudControllerPasswordRepository", func() { 22 It("updates your password", func() { 23 req := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{ 24 Method: "PUT", 25 Path: "/Users/my-user-guid/password", 26 Matcher: testnet.RequestBodyMatcher(`{"password":"new-password","oldPassword":"old-password"}`), 27 Response: testnet.TestResponse{Status: http.StatusOK}, 28 }) 29 30 passwordUpdateServer, handler, repo := createPasswordRepo(req) 31 defer passwordUpdateServer.Close() 32 33 apiErr := repo.UpdatePassword("old-password", "new-password") 34 Expect(handler).To(HaveAllRequestsCalled()) 35 Expect(apiErr).NotTo(HaveOccurred()) 36 }) 37 }) 38 39 func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo Repository) { 40 passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req}) 41 42 configRepo := testconfig.NewRepositoryWithDefaults() 43 configRepo.SetUaaEndpoint(passwordServer.URL) 44 gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") 45 repo = NewCloudControllerRepository(configRepo, gateway) 46 return 47 }