예제 #1
0
파일: users_test.go 프로젝트: jalateras/cli
func testSetOrUnsetSpaceRoleWithValidRole(t *testing.T,
	setOrUnset func(UserRepository, cf.User, cf.Space) net.ApiResponse,
	verb string,
	path string) {

	reqs := []testnet.TestRequest{}

	if verb == "PUT" {
		addToOrgReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:   "PUT",
			Path:     "/v2/organizations/my-space-org-guid/users/my-user-guid",
			Response: testnet.TestResponse{Status: http.StatusOK},
		})
		reqs = append(reqs, addToOrgReq)
	}

	setOrUnsetReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   verb,
		Path:     path,
		Response: testnet.TestResponse{Status: http.StatusOK},
	})
	reqs = append(reqs, setOrUnsetReq)

	cc, handler, repo := createUsersRepoWithoutUAAEndpoints(t, reqs)
	defer cc.Close()

	user := cf.User{Guid: "my-user-guid"}
	space := cf.Space{Guid: "my-space-guid", Organization: cf.Organization{Guid: "my-space-org-guid"}}
	apiResponse := setOrUnset(repo, user, space)

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
}
예제 #2
0
파일: users_test.go 프로젝트: nsnt/cli
func TestCreateUser(t *testing.T) {
	ccReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "POST",
		Path:     "/v2/users",
		Matcher:  testnet.RequestBodyMatcher(`{"guid":"my-user-guid"}`),
		Response: testnet.TestResponse{Status: http.StatusCreated},
	})

	uaaReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "POST",
		Path:   "/Users",
		Matcher: testnet.RequestBodyMatcher(`{
				"userName":"******",
				"emails":[{"value":"my-user"}],
				"password":"******",
				"name":{
					"givenName":"my-user",
					"familyName":"my-user"}
				}`),
		Response: testnet.TestResponse{
			Status: http.StatusCreated,
			Body:   `{"id":"my-user-guid"}`,
		},
	})

	cc, ccHandler, uaa, uaaHandler, repo := createUsersRepo(t, []testnet.TestRequest{ccReq}, []testnet.TestRequest{uaaReq})
	defer cc.Close()
	defer uaa.Close()

	apiResponse := repo.Create("my-user", "my-password")
	assert.True(t, ccHandler.AllRequestsCalled())
	assert.True(t, uaaHandler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
}
예제 #3
0
파일: domains_test.go 프로젝트: pmuellr/cli
func TestDomainFindByNameInCurrentSpaceWhenFoundInDomainsButNotShared(t *testing.T) {
	spaceDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/spaces/my-space-guid/domains?q=name%3Adomain2.cf-app.com",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": []}`},
	})

	sharedDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/domains?q=name%3Adomain2.cf-app.com",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
			{
			  "metadata": { "guid": "some-domain-guid" },
			  "entity": {
			    "name": "some.cf-app.com",
				"owning_organization_guid": "some-org-guid"
			  }
			}
		]}`},
	})

	ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{spaceDomainsReq, sharedDomainsReq})
	defer ts.Close()

	_, apiResponse := repo.FindByNameInCurrentSpace("domain2.cf-app.com")
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsError())
	assert.True(t, apiResponse.IsNotFound())
}
예제 #4
0
파일: domains_test.go 프로젝트: pmuellr/cli
func TestDomainFindByNameInOrgWhenFoundInDomainsButNotShared(t *testing.T) {
	orgDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/organizations/my-org-guid/domains?inline-relations-depth=1&q=name%3Adomain2.cf-app.com",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": []}`},
	})

	sharedDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/domains?inline-relations-depth=1&q=name%3Adomain2.cf-app.com",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
			{
			  "metadata": { "guid": "shared-domain-guid" },
			  "entity": {
				"name": "shared-example.com",
				"owning_organization_guid": "some-other-org-guid",
				"wildcard": true,
				"spaces": []
			  }
			}
		]}`},
	})

	ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{orgDomainsReq, sharedDomainsReq})
	defer ts.Close()

	_, apiResponse := repo.FindByNameInOrg("domain2.cf-app.com", "my-org-guid")
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsError())
	assert.True(t, apiResponse.IsNotFound())
}
예제 #5
0
파일: routes_test.go 프로젝트: nsnt/cli
func TestRoutesListRoutes(t *testing.T) {
	firstRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/routes?inline-relations-depth=1",
		Response: firstPageRoutesResponse,
	})

	secondRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/routes?inline-relations-depth=1&page=2",
		Response: secondPageRoutesResponse,
	})

	ts, handler, repo, _ := createRoutesRepo(t, firstRequest, secondRequest)
	defer ts.Close()

	stopChan := make(chan bool)
	defer close(stopChan)
	routesChan, statusChan := repo.ListRoutes(stopChan)

	routes := []cf.Route{}
	for chunk := range routesChan {
		routes = append(routes, chunk...)
	}
	apiResponse := <-statusChan

	assert.Equal(t, len(routes), 2)
	assert.Equal(t, routes[0].Guid, "route-1-guid")
	assert.Equal(t, routes[1].Guid, "route-2-guid")
	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
}
예제 #6
0
파일: spaces_test.go 프로젝트: nsnt/cli
func TestSpacesListSpaces(t *testing.T) {
	firstPageSpacesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations/some-org-guid/spaces",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{
			"next_url": "/v2/organizations/some-org-guid/spaces?page=2",
			"resources": [
				{
			  		"metadata": {
				  		"guid": "acceptance-space-guid"
			  		},
			  		"entity": {
				  		"name": "acceptance"
			  		}
			  	}
			]
		}`}})

	secondPageSpacesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations/some-org-guid/spaces?page=2",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{
			"resources": [
			  	{
			  		"metadata": {
				      	"guid": "staging-space-guid"
				  	},
			    	"entity": {
						"name": "staging"
				    }
				}
			]
		}`}})

	ts, handler, repo := createSpacesRepo(t, firstPageSpacesRequest, secondPageSpacesRequest)
	defer ts.Close()

	stopChan := make(chan bool)
	defer close(stopChan)
	spacesChan, statusChan := repo.ListSpaces(stopChan)

	spaces := []cf.Space{}
	for chunk := range spacesChan {
		spaces = append(spaces, chunk...)
	}
	apiResponse := <-statusChan

	assert.Equal(t, spaces[0].Guid, "acceptance-space-guid")
	assert.Equal(t, spaces[1].Guid, "staging-space-guid")
	assert.True(t, apiResponse.IsSuccessful())
	assert.True(t, handler.AllRequestsCalled())
}
예제 #7
0
func TestOrganizationPaginator(t *testing.T) {
	firstReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{
		"total_pages": 2,
		"next_url": "/v2/organizations?page=2",
		"resources": [
			{
			  "metadata": { "guid": "org1-guid" },
			  "entity": { "name": "Org1" }
			}
		]}`},
	})

	secondReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations?page=2",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{
		"total_pages": 2,
		"next_url": "",
		"resources": [
			{
			  "metadata": { "guid": "org2-guid" },
			  "entity": { "name": "Org2" }
			}
		]}`},
	})

	ts, handler, p := createOrgPaginator(t, firstReq, secondReq)
	defer ts.Close()

	assert.True(t, p.HasNext())

	firstChunk, apiResponse := p.Next()

	assert.True(t, apiResponse.IsSuccessful())
	assert.Equal(t, len(firstChunk), 1)

	firstOutput := firstChunk[0]
	assert.Contains(t, firstOutput, "Org1")
	assert.True(t, p.HasNext())

	secondChunk, apiResponse := p.Next()

	assert.True(t, apiResponse.IsSuccessful())
	assert.Equal(t, len(secondChunk), 1)

	secondOutput := secondChunk[0]
	assert.Contains(t, secondOutput, "Org2")

	assert.False(t, p.HasNext())

	assert.True(t, handler.AllRequestsCalled())
}
예제 #8
0
파일: users_test.go 프로젝트: nsnt/cli
func createUsersByRoleEndpoints(rolePath string) (ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) {
	nextUrl := rolePath + "?page=2"

	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   rolePath,
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: fmt.Sprintf(`{
				"next_url": "%s",
				"resources": [ {"metadata": {"guid": "user-1-guid"}, "entity": {}} ]
			}`, nextUrl)},
	})

	secondReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   nextUrl,
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{
				"resources": [ {"metadata": {"guid": "user-2-guid"}, "entity": {}}, {"metadata": {"guid": "user-3-guid"}, "entity": {}} ]
			}`},
	})

	ccReqs = append(ccReqs, req, secondReq)

	uaaRoleResponses := []string{
		`{ "resources": [ { "id": "user-1-guid", "userName": "******" }]}`,
		`{ "resources": [
			{ "id": "user-2-guid", "userName": "******" },
  			{ "id": "user-3-guid", "userName": "******" }
		]}`,
	}

	filters := []string{
		`Id eq "user-1-guid"`,
		`Id eq "user-2-guid" or Id eq "user-3-guid"`,
	}

	for index, resp := range uaaRoleResponses {
		path := fmt.Sprintf(
			"/Users?attributes=id,userName&filter=%s",
			url.QueryEscape(filters[index]),
		)
		req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:   "GET",
			Path:     path,
			Response: testnet.TestResponse{Status: http.StatusOK, Body: resp},
		})
		uaaReqs = append(uaaReqs, req)
	}

	return
}
예제 #9
0
파일: users_test.go 프로젝트: nota-ja/cli
func createUsersByRoleEndpoints(rolePath string) (ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) {
	nextUrl := rolePath + "?page=2"

	ccReqs = []testnet.TestRequest{
		testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method: "GET",
			Path:   rolePath,
			Response: testnet.TestResponse{
				Status: http.StatusOK,
				Body: fmt.Sprintf(`
				{
					"next_url": "%s",
					"resources": [
						{"metadata": {"guid": "user-1-guid"}, "entity": {}}
					]
				}`, nextUrl)}}),

		testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method: "GET",
			Path:   nextUrl,
			Response: testnet.TestResponse{
				Status: http.StatusOK,
				Body: `
				{
					"resources": [
					 	{"metadata": {"guid": "user-2-guid"}, "entity": {}},
					 	{"metadata": {"guid": "user-3-guid"}, "entity": {}}
					]
				}`}}),
	}

	uaaReqs = []testnet.TestRequest{
		testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method: "GET",
			Path: fmt.Sprintf(
				"/Users?attributes=id,userName&filter=%s",
				url.QueryEscape(`Id eq "user-1-guid" or Id eq "user-2-guid" or Id eq "user-3-guid"`)),
			Response: testnet.TestResponse{
				Status: http.StatusOK,
				Body: `
				{
					"resources": [
						{ "id": "user-1-guid", "userName": "******" },
						{ "id": "user-2-guid", "userName": "******" },
  						{ "id": "user-3-guid", "userName": "******" }
					]
				}`}})}

	return
}
예제 #10
0
func TestOrganizationsListOrgs(t *testing.T) {
	firstPageOrgsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{
		"next_url": "/v2/organizations?page=2",
		"resources": [
			{
			  "metadata": { "guid": "org1-guid" },
			  "entity": { "name": "Org1" }
			},
			{
			  "metadata": { "guid": "org2-guid" },
			  "entity": { "name": "Org2" }
			}
		]}`},
	})

	secondPageOrgsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations?page=2",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
			{
			  "metadata": { "guid": "org3-guid" },
			  "entity": { "name": "Org3" }
			}
		]}`},
	})

	ts, handler, repo := createOrganizationRepo(t, firstPageOrgsRequest, secondPageOrgsRequest)
	defer ts.Close()

	stopChan := make(chan bool)
	defer close(stopChan)
	orgsChan, statusChan := repo.ListOrgs(stopChan)

	orgs := []cf.Organization{}
	for chunk := range orgsChan {
		orgs = append(orgs, chunk...)
	}
	apiResponse := <-statusChan

	assert.Equal(t, len(orgs), 3)
	assert.Equal(t, orgs[0].Guid, "org1-guid")
	assert.Equal(t, orgs[1].Guid, "org2-guid")
	assert.Equal(t, orgs[2].Guid, "org3-guid")
	assert.True(t, apiResponse.IsSuccessful())
	assert.True(t, handler.AllRequestsCalled())

}
예제 #11
0
func TestStopApplication(t *testing.T) {
	stopApplicationRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "PUT",
		Path:    "/v2/apps/my-cool-app-guid?inline-relations-depth=2",
		Matcher: testnet.RequestBodyMatcher(`{"console":true,"state":"STOPPED"}`),
		Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
  "metadata": {
    "guid": "my-updated-app-guid"
  },
  "entity": {
    "name": "cli1",
    "state": "STOPPED"
  }
}`},
	})

	ts, handler, repo := createAppRepo(t, []testnet.TestRequest{stopApplicationRequest})
	defer ts.Close()

	app := cf.Application{Name: "my-cool-app", Guid: "my-cool-app-guid"}
	updatedApp, apiResponse := repo.Stop(app)

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.Equal(t, "cli1", updatedApp.Name)
	assert.Equal(t, "stopped", updatedApp.State)
	assert.Equal(t, "my-updated-app-guid", updatedApp.Guid)
}
예제 #12
0
func TestGetInstances(t *testing.T) {
	getInstancesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/apps/my-cool-app-guid/instances",
		Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
  "1": {
    "state": "STARTING"
  },
  "0": {
    "state": "RUNNING"
  }
}`},
	})

	ts, handler, repo := createAppRepo(t, []testnet.TestRequest{getInstancesRequest})
	defer ts.Close()

	app := cf.Application{Name: "my-cool-app", Guid: "my-cool-app-guid"}
	instances, apiResponse := repo.GetInstances(app)

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.Equal(t, len(instances), 2)
	assert.Equal(t, instances[0].State, "running")
	assert.Equal(t, instances[1].State, "starting")
}
예제 #13
0
func TestCreateBuildpackEnabled(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "POST",
		Path:    "/v2/buildpacks",
		Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":999, "enabled":true}`),
		Response: testnet.TestResponse{
			Status: http.StatusCreated,
			Body: `{
				"metadata": {
					"guid": "my-cool-buildpack-guid"
				},
				"entity": {
					"name": "my-cool-buildpack",
					"position":999,
					"enabled":true
				}
			}`},
	})

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

	position := 999
	enabled := true
	created, apiResponse := repo.Create("my-cool-buildpack", &position, &enabled)

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

	assert.NotNil(t, created.Guid)
	assert.Equal(t, "my-cool-buildpack", created.Name)
	assert.Equal(t, 999, *created.Position)
}
예제 #14
0
func deleteSharedDomainReq(statusCode int) testnet.TestRequest {
	return testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "DELETE",
		Path:     "/v2/shared_domains/my-domain-guid?recursive=true",
		Response: testnet.TestResponse{Status: statusCode},
	})
}
예제 #15
0
파일: domains_test.go 프로젝트: pmuellr/cli
func unmapDomainReq(statusCode int) testnet.TestRequest {
	return testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "DELETE",
		Path:     "/v2/spaces/my-space-guid/domains/my-domain-guid",
		Response: testnet.TestResponse{Status: statusCode},
	})
}
예제 #16
0
파일: quotas_test.go 프로젝트: pmuellr/cli
func TestFindQuotaByName(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/quota_definitions?q=name%3Amy-quota",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{"resources": [
				{
				  "metadata": { "guid": "my-quota-guid" },
				  "entity": { "name": "my-remote-quota", "memory_limit": 1024 }
				}
			]}`},
	})

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

	quota, apiResponse := repo.FindByName("my-quota")
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	expectedQuota := cf.QuotaFields{}
	expectedQuota.Guid = "my-quota-guid"
	expectedQuota.Name = "my-remote-quota"
	expectedQuota.MemoryLimit = 1024
	assert.Equal(t, quota, expectedQuota)
}
예제 #17
0
파일: domains_test.go 프로젝트: pmuellr/cli
func TestDomainFindByNameInOrg(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations/my-org-guid/domains?inline-relations-depth=1&q=name%3Adomain2.cf-app.com",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
			{
			  "metadata": { "guid": "my-domain-guid" },
			  "entity": {
				"name": "my-example.com",
				"owning_organization_guid": "my-org-guid",
				"wildcard": true,
				"spaces": [
				  {
					"metadata": { "guid": "my-space-guid" },
					"entity": { "name": "my-space" }
				  }
				]
			  }
			}
		]}`},
	})

	ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{req})
	defer ts.Close()

	domain, apiResponse := repo.FindByNameInOrg("domain2.cf-app.com", "my-org-guid")
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())

	assert.Equal(t, domain.Name, "my-example.com")
	assert.Equal(t, domain.Guid, "my-domain-guid")
	assert.False(t, domain.Shared)
	assert.Equal(t, domain.Spaces[0].Name, "my-space")
}
예제 #18
0
func TestOrganizationsFindAll(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/organizations",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
			{
			  "metadata": { "guid": "org1-guid" },
			  "entity": { "name": "Org1" }
			},
			{
			  "metadata": { "guid": "org2-guid" },
			  "entity": { "name": "Org2" }
			}
		]}`},
	})

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

	organizations, apiResponse := repo.FindAll()
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.Equal(t, 2, len(organizations))

	firstOrg := organizations[0]
	assert.Equal(t, firstOrg.Name, "Org1")
	assert.Equal(t, firstOrg.Guid, "org1-guid")

	secondOrg := organizations[1]
	assert.Equal(t, secondOrg.Name, "Org2")
	assert.Equal(t, secondOrg.Guid, "org2-guid")
}
예제 #19
0
func TestRoutesFindAll(t *testing.T) {
	request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/routes?inline-relations-depth=1",
		Response: findAllRoutesResponse,
	})

	ts, handler, repo, _ := createRoutesRepo(t, request)
	defer ts.Close()

	routes, apiResponse := repo.FindAll()

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.Equal(t, len(routes), 2)

	route := routes[0]
	assert.Equal(t, route.Host, "route-1-host")
	assert.Equal(t, route.Guid, "route-1-guid")
	assert.Equal(t, route.Domain.Name, "cfapps.io")
	assert.Equal(t, route.Domain.Guid, "domain-1-guid")
	assert.Equal(t, route.Space.Name, "space-1")
	assert.Equal(t, route.Space.Guid, "space-1-guid")
	assert.Equal(t, route.AppNames, []string{"app-1"})

	route = routes[1]
	assert.Equal(t, route.Guid, "route-2-guid")
	assert.Equal(t, route.AppNames, []string{"app-2", "app-3"})
}
func TestUpdateUserProvidedServiceInstance(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "PUT",
		Path:     "/v2/user_provided_service_instances/my-instance-guid",
		Matcher:  testnet.RequestBodyMatcher(`{"credentials":{"host":"example.com","password":"******","user":"******"},"syslog_drain_url":"syslog://example.com"}`),
		Response: testnet.TestResponse{Status: http.StatusCreated},
	})

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

	params := map[string]string{
		"host":     "example.com",
		"user":     "******",
		"password": "******",
	}
	serviceInstance := cf.ServiceInstanceFields{}
	serviceInstance.Guid = "my-instance-guid"
	serviceInstance.Params = params
	serviceInstance.SysLogDrainUrl = "syslog://example.com"

	apiResponse := repo.Update(serviceInstance)
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
}
예제 #21
0
파일: curl_test.go 프로젝트: nsnt/cli
func TestCurlWithCustomHeaders(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "POST",
		Path:   "/v2/endpoint",
		Matcher: func(t *testing.T, req *http.Request) {
			assert.Equal(t, req.Header.Get("content-type"), "ascii/cats")
			assert.Equal(t, req.Header.Get("x-something-else"), "5")
		},
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body:   jsonResponse},
	})
	ts, handler := testnet.NewTLSServer(t, []testnet.TestRequest{req})
	defer ts.Close()

	deps := newCurlDependencies()
	deps.config.Target = ts.URL

	headers := "content-type: ascii/cats\nx-something-else:5"
	repo := NewCloudControllerCurlRepository(deps.config, deps.gateway)
	_, _, apiResponse := repo.Request("POST", "/v2/endpoint", headers, "")
	println(apiResponse.Message)
	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
}
예제 #22
0
func TestCreateBuildpackWithPosition(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "POST",
		Path:    "/v2/buildpacks",
		Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":999}`),
		Response: testnet.TestResponse{
			Status: http.StatusCreated,
			Body: `{
				"metadata": {
					"guid": "my-cool-buildpack-guid"
				},
				"entity": {
					"name": "my-cool-buildpack",
					"position":999
				}
			}`},
	})

	ts, handler, repo := createBuildpackRepo(t, []testnet.TestRequest{req})
	defer ts.Close()

	position := 999
	buildpack := cf.Buildpack{Name: "my-cool-buildpack", Position: &position}
	created, apiResponse := repo.Create(buildpack)

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

	assert.NotNil(t, created.Guid)
	assert.Equal(t, buildpack.Name, created.Name)
	assert.Equal(t, *buildpack.Position, 999)
}
예제 #23
0
func TestUpdateBuildpack(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "PUT",
		Path:    "/v2/buildpacks/my-cool-buildpack-guid",
		Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":555}`),
		Response: testnet.TestResponse{
			Status: http.StatusCreated,
			Body: `{
				
				    "metadata": {
				        "guid": "my-cool-buildpack-guid"
				    },
				    "entity": {
				        "name": "my-cool-buildpack",
						"position":555
				    }
				}`},
	})

	ts, handler, repo := createBuildpackRepo(t, []testnet.TestRequest{req})
	defer ts.Close()

	position := 555
	buildpack := cf.Buildpack{Name: "my-cool-buildpack", Guid: "my-cool-buildpack-guid", Position: &position}
	updated, apiResponse := repo.Update(buildpack)

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())

	assert.Equal(t, buildpack, updated)
}
예제 #24
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{
		Guid:     "my-guid",
		Name:     "foobroker",
		Url:      "http://update.example.com",
		Username: "******",
		Password: "******",
	}
	apiResponse := repo.Update(serviceBroker)

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
}
예제 #25
0
func TestDomainFindDefault(t *testing.T) {
	sharedDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/domains",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
			{
			  "metadata": { "guid": "shared-domain-guid" },
			  "entity": {
			    "name": "shared-domain.cf-app.com",
				"owning_organization_guid": null
			  }
			}
		]}`},
	})

	ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{sharedDomainsReq})
	defer ts.Close()

	domain, apiResponse := repo.FindDefaultAppDomain()
	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())

	assert.Equal(t, domain.Name, "shared-domain.cf-app.com")
	assert.Equal(t, domain.Guid, "shared-domain-guid")
}
예제 #26
0
func TestServiceAuthFindByLabelAndProvider(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/service_auth_tokens?q=label:a-label;provider:a-provider",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body: `{"resources": [{
			"metadata": { "guid": "mysql-core-guid" },
			"entity": {
				"label": "mysql",
				"provider": "mysql-core"
			}
		}]}`},
	})

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

	serviceAuthToken, apiResponse := repo.FindByLabelAndProvider("a-label", "a-provider")

	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())
	authToken2 := cf.ServiceAuthTokenFields{}
	authToken2.Guid = "mysql-core-guid"
	authToken2.Label = "mysql"
	authToken2.Provider = "mysql-core"
	assert.Equal(t, serviceAuthToken, authToken2)
}
예제 #27
0
파일: domains_test.go 프로젝트: pmuellr/cli
func TestDomainListDomainsForOrgWithNoDomains(t *testing.T) {
	emptyDomainsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/domains?inline-relations-depth=1",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [] }`},
	})

	ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{emptyDomainsRequest})
	defer ts.Close()

	stopChan := make(chan bool)
	defer close(stopChan)
	domainsChan, statusChan := repo.ListDomainsForOrg("my-org-guid", stopChan)

	domains := []cf.Domain{}
	for chunk := range domainsChan {
		domains = append(domains, chunk...)
	}

	_, ok := <-domainsChan
	apiResponse := <-statusChan

	assert.False(t, ok)
	assert.True(t, apiResponse.IsSuccessful())
	assert.True(t, handler.AllRequestsCalled())
}
예제 #28
0
func TestServiceSummaryGetSummariesInCurrentSpace(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/spaces/my-space-guid/summary",
		Response: serviceInstanceSummariesResponse,
	})

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

	serviceInstances, apiResponse := repo.GetSummariesInCurrentSpace()
	assert.True(t, handler.AllRequestsCalled())

	assert.True(t, apiResponse.IsSuccessful())
	assert.Equal(t, 1, len(serviceInstances))

	instance1 := serviceInstances[0]
	assert.Equal(t, instance1.Name, "my-service-instance")
	assert.Equal(t, instance1.ServicePlan.Name, "spark")
	assert.Equal(t, instance1.ServiceOffering.Label, "cleardb")
	assert.Equal(t, instance1.ServiceOffering.Label, "cleardb")
	assert.Equal(t, instance1.ServiceOffering.Provider, "cleardb-provider")
	assert.Equal(t, instance1.ServiceOffering.Version, "n/a")
	assert.Equal(t, len(instance1.ApplicationNames), 2)
	assert.Equal(t, instance1.ApplicationNames[0], "app1")
	assert.Equal(t, instance1.ApplicationNames[1], "app2")
}
예제 #29
0
func TestCreateInSpace(t *testing.T) {
	request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "POST",
		Path:    "/v2/routes",
		Matcher: testnet.RequestBodyMatcher(`{"host":"my-cool-app","domain_guid":"my-domain-guid","space_guid":"my-space-guid"}`),
		Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
  "metadata": { "guid": "my-route-guid" },
  "entity": { "host": "my-cool-app" }
}`},
	})

	ts, handler, repo, _ := createRoutesRepo(t, request)
	defer ts.Close()

	domain := cf.Domain{Guid: "my-domain-guid"}
	newRoute := cf.Route{Host: "my-cool-app"}
	space := cf.Space{Guid: "my-space-guid"}

	createdRoute, apiResponse := repo.CreateInSpace(newRoute, domain, space)
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())

	assert.Equal(t, createdRoute, cf.Route{Host: "my-cool-app", Guid: "my-route-guid", Domain: domain})
}
예제 #30
0
func TestServiceBrokersFindAll(t *testing.T) {
	responseBody := `{
  "resources": [
  	{
  	  "metadata": {
  	    "guid":"found-guid-1"
  	  },
  	  "entity": {
  	    "name": "found-name-1",
  	    "broker_url": "http://found.example.com-1",
  	    "auth_username": "******",
  	    "auth_password": "******"
  	  }
  	},
  	{
  	  "metadata": {
  	    "guid":"found-guid-2"
  	  },
  	  "entity": {
  	    "name": "found-name-2",
  	    "broker_url": "http://found.example.com-2",
  	    "auth_username": "******",
  	    "auth_password": "******"
  	  }
  	}
  ]
}`

	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/service_brokers",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: responseBody},
	})

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

	serviceBrokers, apiResponse := repo.FindAll()

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.Equal(t, len(serviceBrokers), 2)

	assert.Equal(t, serviceBrokers[0].Name, "found-name-1")
	assert.Equal(t, serviceBrokers[0].Guid, "found-guid-1")
	assert.Equal(t, serviceBrokers[0].Url, "http://found.example.com-1")
	assert.Equal(t, serviceBrokers[0].Username, "found-username-1")
	assert.Equal(t, serviceBrokers[0].Password, "found-password-1")

	assert.Equal(t, serviceBrokers[1].Name, "found-name-2")
	assert.Equal(t, serviceBrokers[1].Guid, "found-guid-2")
	assert.Equal(t, serviceBrokers[1].Url, "http://found.example.com-2")
	assert.Equal(t, serviceBrokers[1].Username, "found-username-2")
	assert.Equal(t, serviceBrokers[1].Password, "found-password-2")
}