github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+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 testapi "github.com/cloudfoundry/cli/cf/api/fakes" 9 "github.com/cloudfoundry/cli/cf/net" 10 testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" 11 testnet "github.com/cloudfoundry/cli/testhelpers/net" 12 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 13 14 . "github.com/cloudfoundry/cli/cf/api/password" 15 . "github.com/cloudfoundry/cli/testhelpers/matchers" 16 . "github.com/onsi/ginkgo" 17 . "github.com/onsi/gomega" 18 ) 19 20 var _ = Describe("CloudControllerPasswordRepository", func() { 21 It("updates your password", func() { 22 req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ 23 Method: "PUT", 24 Path: "/Users/my-user-guid/password", 25 Matcher: testnet.RequestBodyMatcher(`{"password":"new-password","oldPassword":"old-password"}`), 26 Response: testnet.TestResponse{Status: http.StatusOK}, 27 }) 28 29 passwordUpdateServer, handler, repo := createPasswordRepo(req) 30 defer passwordUpdateServer.Close() 31 32 apiErr := repo.UpdatePassword("old-password", "new-password") 33 Expect(handler).To(HaveAllRequestsCalled()) 34 Expect(apiErr).NotTo(HaveOccurred()) 35 }) 36 }) 37 38 func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo PasswordRepository) { 39 passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req}) 40 41 configRepo := testconfig.NewRepositoryWithDefaults() 42 configRepo.SetUaaEndpoint(passwordServer.URL) 43 gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) 44 repo = NewCloudControllerPasswordRepository(configRepo, gateway) 45 return 46 }