示例#1
0
func TestCreateRoute(t *testing.T) {
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	space.Name = "my-space"
	domain := cf.DomainFields{}
	domain.Guid = "domain-guid"
	domain.Name = "example.com"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:       true,
		TargetedOrgSuccess: true,
		Domain:             cf.Domain{DomainFields: domain},
		Space:              cf.Space{SpaceFields: space},
	}
	routeRepo := &testapi.FakeRouteRepository{}

	ui := callCreateRoute(t, []string{"-n", "host", "my-space", "example.com"}, reqFactory, routeRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route", "host.example.com", "my-org", "my-space", "my-user"},
		{"OK"},
	})

	assert.Equal(t, routeRepo.CreateInSpaceHost, "host")
	assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid")
	assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid")

}
示例#2
0
func TestUpdateEndpointWhenUrlIsValidHttpsInfoEndpoint(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint)
	defer ts.Close()
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"

	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"

	config, _ := configRepo.Get()
	config.OrganizationFields = org
	config.SpaceFields = space

	repo.UpdateEndpoint(ts.URL)

	savedConfig := testconfig.SavedConfiguration

	assert.Equal(t, savedConfig.AccessToken, "")
	assert.Equal(t, savedConfig.AuthorizationEndpoint, "https://login.example.com")
	assert.Equal(t, savedConfig.Target, ts.URL)
	assert.Equal(t, savedConfig.ApiVersion, "42.0.0")
	assert.False(t, savedConfig.HasOrganization())
	assert.False(t, savedConfig.HasSpace())
}
示例#3
0
func TestUpdateEndpointWhenUrlIsAlreadyTargeted(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint)
	defer ts.Close()

	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"

	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"

	config, _ := configRepo.Get()
	config.Target = ts.URL
	config.AccessToken = "some access token"
	config.RefreshToken = "some refresh token"
	config.OrganizationFields = org
	config.SpaceFields = space

	repo.UpdateEndpoint(ts.URL)

	assert.Equal(t, config.OrganizationFields, org)
	assert.Equal(t, config.SpaceFields, space)
	assert.Equal(t, config.AccessToken, "some access token")
	assert.Equal(t, config.RefreshToken, "some refresh token")
}
示例#4
0
文件: services_test.go 项目: nsnt/cli
func createServiceRepo(t *testing.T, reqs []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ServiceRepository) {
	space2 := cf.SpaceFields{}
	space2.Guid = "my-space-guid"
	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		SpaceFields: space2,
	}
	return createServiceRepoWithConfig(t, reqs, config)
}
示例#5
0
func createServiceSummaryRepo(t *testing.T, req testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ServiceSummaryRepository) {
	ts, handler = testnet.NewTLSServer(t, []testnet.TestRequest{req})
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
		SpaceFields: space,
	}
	gateway := net.NewCloudControllerGateway()
	repo = NewCloudControllerServiceSummaryRepository(config, gateway)
	return
}
示例#6
0
文件: services_test.go 项目: nsnt/cli
func TestGetServiceOfferingsWhenTargetingASpace(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/spaces/my-space-guid/services?inline-relations-depth=1",
		Response: multipleOfferingsResponse,
	})
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		SpaceFields: space,
	}
	testGetServiceOfferings(t, req, config)
}
示例#7
0
func TestMarketplaceServices(t *testing.T) {
	plan := cf.ServicePlanFields{}
	plan.Name = "service-plan-a"
	plan2 := cf.ServicePlanFields{}
	plan2.Name = "service-plan-b"
	plan3 := cf.ServicePlanFields{}
	plan3.Name = "service-plan-c"
	plan4 := cf.ServicePlanFields{}
	plan4.Name = "service-plan-d"

	offering := cf.ServiceOffering{}
	offering.Label = "zzz-my-service-offering"
	offering.Description = "service offering 1 description"
	offering.Plans = []cf.ServicePlanFields{plan, plan2}

	offering2 := cf.ServiceOffering{}
	offering2.Label = "aaa-my-service-offering"
	offering2.Description = "service offering 2 description"
	offering2.Plans = []cf.ServicePlanFields{plan3, plan4}

	serviceOfferings := []cf.ServiceOffering{offering, offering2}
	serviceRepo := &testapi.FakeServiceRepo{ServiceOfferings: serviceOfferings}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"
	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"
	config := &configuration.Configuration{
		SpaceFields:        space,
		OrganizationFields: org,
		AccessToken:        token,
	}

	ui := callMarketplaceServices(t, config, serviceRepo)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting services from marketplace in org", "my-org", "my-space", "my-user"},
		{"OK"},
		{"service", "plans", "description"},
		{"aaa-my-service-offering", "service offering 2 description", "service-plan-c", "service-plan-d"},
		{"zzz-my-service-offering", "service offering 1 description", "service-plan-a", "service-plan-b"},
	})
}
示例#8
0
文件: routes_test.go 项目: nsnt/cli
func createRoutesRepo(t *testing.T, requests ...testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo CloudControllerRouteRepository, domainRepo *testapi.FakeDomainRepository) {
	ts, handler = testnet.NewTLSServer(t, requests)
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	config := &configuration.Configuration{
		AccessToken: "BEARER my_access_token",
		Target:      ts.URL,
		SpaceFields: space,
	}

	gateway := net.NewCloudControllerGateway()
	domainRepo = &testapi.FakeDomainRepository{}

	repo = NewCloudControllerRouteRepository(config, gateway, domainRepo)
	return
}
示例#9
0
func TestSetSpace(t *testing.T) {
	repo := NewConfigurationDiskRepository()
	repo.loadDefaultConfig(t)
	defer repo.restoreConfig(t)
	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"
	err := repo.SetSpace(space)
	assert.NoError(t, err)

	repo.Save()

	savedConfig, err := repo.Get()
	assert.NoError(t, err)
	assert.Equal(t, savedConfig.SpaceFields, space)
}
示例#10
0
func createDomainRepo(t *testing.T, reqs []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo DomainRepository) {
	ts, handler = testnet.NewTLSServer(t, reqs)
	org := cf.OrganizationFields{}
	org.Guid = "my-org-guid"
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"

	config := &configuration.Configuration{
		AccessToken:        "BEARER my_access_token",
		Target:             ts.URL,
		SpaceFields:        space,
		OrganizationFields: org,
	}
	gateway := net.NewCloudControllerGateway()
	repo = NewCloudControllerDomainRepository(config, gateway)
	return
}
示例#11
0
func TestSetSpace(t *testing.T) {
	withFakeHome(t, func() {
		repo := NewConfigurationDiskRepository()
		repo.Get()
		space := cf.SpaceFields{}
		space.Name = "my-space"
		space.Guid = "my-space-guid"

		err := repo.SetSpace(space)
		assert.NoError(t, err)

		repo.Save()

		savedConfig, err := repo.Get()
		assert.NoError(t, err)
		assert.Equal(t, savedConfig.SpaceFields, space)
	})
}
示例#12
0
func TestRouteCreator(t *testing.T) {
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	space.Name = "my-space"
	domain := cf.DomainFields{}
	domain.Guid = "domain-guid"
	domain.Name = "example.com"

	createdRoute := cf.Route{}
	createdRoute.Host = "my-host"
	createdRoute.Guid = "my-route-guid"
	routeRepo := &testapi.FakeRouteRepository{
		CreateInSpaceCreatedRoute: createdRoute,
	}

	ui := new(testterm.FakeUI)
	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	config := &configuration.Configuration{
		OrganizationFields: org,
		AccessToken:        token,
	}

	cmd := NewCreateRoute(ui, config, routeRepo)
	route, apiResponse := cmd.CreateRoute("my-host", domain, space)

	assert.Equal(t, route.Guid, createdRoute.Guid)

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

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route", "my-host.example.com", "my-org", "my-space", "my-user"},
		{"OK"},
	})

	assert.Equal(t, routeRepo.CreateInSpaceHost, "my-host")
	assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid")
	assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid")
}
示例#13
0
func TestDeleteSpaceWhenSpaceNotTargeted(t *testing.T) {
	reqFactory := defaultDeleteSpaceReqFactory()
	spaceRepo := &testapi.FakeSpaceRepository{}
	configRepo := &testconfig.FakeConfigRepository{}

	config, _ := configRepo.Get()
	otherSpace := cf.SpaceFields{}
	otherSpace.Name = "do-not-delete"
	otherSpace.Guid = "do-not-delete-guid"
	config.SpaceFields = otherSpace
	configRepo.Save()

	ui := &testterm.FakeUI{}
	ctxt := testcmd.NewContext("delete", []string{"-f", "space-to-delete"})

	cmd := NewDeleteSpace(ui, config, spaceRepo, configRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)

	config, _ = configRepo.Get()
	assert.Equal(t, config.HasSpace(), true)
}
示例#14
0
文件: push_test.go 项目: nsnt/cli
func callPush(t *testing.T, args []string, deps pushDependencies) (ui *testterm.FakeUI) {

	ui = new(testterm.FakeUI)
	ctxt := testcmd.NewContext("push", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"
	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"

	config := &configuration.Configuration{
		SpaceFields:        space,
		OrganizationFields: org,
		AccessToken:        token,
	}

	manifestRepo := deps.manifestRepo
	starter := deps.starter
	stopper := deps.stopper
	binder := deps.binder
	appRepo := deps.appRepo
	domainRepo := deps.domainRepo
	routeRepo := deps.routeRepo
	stackRepo := deps.stackRepo
	appBitsRepo := deps.appBitsRepo
	serviceRepo := deps.serviceRepo

	cmd := NewPush(ui, config, manifestRepo, starter, stopper, binder, appRepo, domainRepo, routeRepo, stackRepo, serviceRepo, appBitsRepo)
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true}
	testcmd.RunCommand(cmd, ctxt, reqFactory)

	return
}
示例#15
0
func TestSpaceRequirement(t *testing.T) {
	ui := new(testterm.FakeUI)
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"
	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"
	config := &configuration.Configuration{
		OrganizationFields: org,

		SpaceFields: space,
	}

	req := newTargetedSpaceRequirement(ui, config)
	success := req.Execute()
	assert.True(t, success)

	config.SpaceFields = cf.SpaceFields{}

	req = newTargetedSpaceRequirement(ui, config)
	success = req.Execute()
	assert.False(t, success)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"No space targeted"},
	})

	ui.ClearOutputs()
	config.OrganizationFields = cf.OrganizationFields{}

	req = newTargetedSpaceRequirement(ui, config)
	success = req.Execute()
	assert.False(t, success)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"No org and space targeted"},
	})
}
示例#16
0
文件: login_test.go 项目: nsnt/cli
func TestSuccessfullyLoggingInWithOrgAndSpaceSetInConfig(t *testing.T) {
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"

	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	space.Name = "my-space"

	existingConfig := configuration.Configuration{
		OrganizationFields: org,
		SpaceFields:        space,
	}

	c := LoginTestContext{
		Inputs: []string{"http://api.example.com", "*****@*****.**", "password"},
		Config: existingConfig,
	}

	callLogin(t, &c, func(c *LoginTestContext) {
		c.orgRepo.FindByNameOrganization = cf.Organization{}
		c.spaceRepo.FindByNameInOrgSpace = cf.Space{}
	})

	savedConfig := testconfig.SavedConfiguration

	assert.Equal(t, savedConfig.Target, "http://api.example.com")
	assert.Equal(t, savedConfig.OrganizationFields.Guid, "my-org-guid")
	assert.Equal(t, savedConfig.SpaceFields.Guid, "my-space-guid")
	assert.Equal(t, savedConfig.AccessToken, "my_access_token")
	assert.Equal(t, savedConfig.RefreshToken, "my_refresh_token")

	assert.Equal(t, c.endpointRepo.UpdateEndpointReceived, "http://api.example.com")
	assert.Equal(t, c.authRepo.Email, "*****@*****.**")
	assert.Equal(t, c.authRepo.Password, "password")

	assert.True(t, c.ui.ShowConfigurationCalled)
}
示例#17
0
func TestCreateRouteIsIdempotent(t *testing.T) {
	space := cf.SpaceFields{}
	space.Guid = "my-space-guid"
	space.Name = "my-space"
	domain := cf.DomainFields{}
	domain.Guid = "domain-guid"
	domain.Name = "example.com"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:       true,
		TargetedOrgSuccess: true,
		Domain:             cf.Domain{DomainFields: domain},
		Space:              cf.Space{SpaceFields: space},
	}

	route := cf.Route{}
	route.Guid = "my-route-guid"
	route.Host = "host"
	route.Domain = domain
	route.Space = space
	routeRepo := &testapi.FakeRouteRepository{
		CreateInSpaceErr:         true,
		FindByHostAndDomainRoute: route,
	}

	ui := callCreateRoute(t, []string{"-n", "host", "my-space", "example.com"}, reqFactory, routeRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route"},
		{"OK"},
		{"host.example.com", "already exists"},
	})

	assert.Equal(t, routeRepo.CreateInSpaceHost, "host")
	assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid")
	assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid")
}