示例#1
0
func TestUpdateServiceBroker(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	broker := cf.ServiceBroker{}
	broker.Name = "my-found-broker"
	broker.Guid = "my-found-broker-guid"
	repo := &testapi.FakeServiceBrokerRepo{
		FindByNameServiceBroker: broker,
	}
	args := []string{"my-broker", "new-username", "new-password", "new-url"}

	ui := callUpdateServiceBroker(t, args, reqFactory, repo)

	assert.Equal(t, repo.FindByNameName, "my-broker")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Updating service broker", "my-found-broker", "my-user"},
		{"OK"},
	})

	expectedServiceBroker := cf.ServiceBroker{}
	expectedServiceBroker.Name = "my-found-broker"
	expectedServiceBroker.Username = "******"
	expectedServiceBroker.Password = "******"
	expectedServiceBroker.Url = "new-url"
	expectedServiceBroker.Guid = "my-found-broker-guid"

	assert.Equal(t, repo.UpdatedServiceBroker, expectedServiceBroker)
}
示例#2
0
func TestFindServiceBrokerByName(t *testing.T) {
	responseBody := `{
  "resources": [
  	{
  	  "metadata": {
  	    "guid":"found-guid"
  	  },
  	  "entity": {
  	    "name": "found-name",
  	    "broker_url": "http://found.example.com",
  	    "auth_username": "******",
  	    "auth_password": "******"
  	  }
  	}
  ]
}`

	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/service_brokers?q=name%3Amy-broker",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: responseBody},
	})

	ts, handler, repo := createServiceBrokerRepo(t, req)
	defer ts.Close()

	foundBroker, apiResponse := repo.FindByName("my-broker")
	expectedBroker := cf.ServiceBroker{}
	expectedBroker.Name = "found-name"
	expectedBroker.Url = "http://found.example.com"
	expectedBroker.Username = "******"
	expectedBroker.Password = "******"
	expectedBroker.Guid = "found-guid"

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
	assert.Equal(t, foundBroker, expectedBroker)
}
示例#3
0
func TestUpdateServiceBroker(t *testing.T) {
	expectedReqBody := `{"broker_url":"http://update.example.com","auth_username":"******","auth_password":"******"}`

	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "PUT",
		Path:     "/v2/service_brokers/my-guid",
		Matcher:  testnet.RequestBodyMatcher(expectedReqBody),
		Response: testnet.TestResponse{Status: http.StatusOK},
	})

	ts, handler, repo := createServiceBrokerRepo(t, req)
	defer ts.Close()
	serviceBroker := cf.ServiceBroker{}
	serviceBroker.Guid = "my-guid"
	serviceBroker.Name = "foobroker"
	serviceBroker.Url = "http://update.example.com"
	serviceBroker.Username = "******"
	serviceBroker.Password = "******"

	apiResponse := repo.Update(serviceBroker)

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
}