Beispiel #1
0
func TestEmptyServicesList(t *testing.T) {
	serviceInstances := []cf.ServiceInstance{}
	serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{
		GetSummariesInCurrentSpaceInstances: serviceInstances,
	}
	ui := &testterm.FakeUI{}

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

	cmd := NewListServices(ui, config, serviceSummaryRepo)
	cmd.Run(testcmd.NewContext("services", []string{}))

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting services in org", "my-org", "my-space", "my-user"},
		{"OK"},
		{"No services found"},
	})
	testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{
		{"name", "service", "plan", "bound apps"},
	})
}
Beispiel #2
0
func TestListingSpaces(t *testing.T) {
	spaceRepo := &testapi.FakeSpaceRepository{
		Spaces: []cf.Space{
			cf.Space{Name: "space1"}, cf.Space{Name: "space2"},
		},
	}
	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})

	assert.NoError(t, err)
	config := &configuration.Configuration{
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}
	ui := callSpaces([]string{}, reqFactory, config, spaceRepo)
	assert.Contains(t, ui.Outputs[0], "Getting spaces in org")
	assert.Contains(t, ui.Outputs[0], "my-org")
	assert.Contains(t, ui.Outputs[0], "my-user")
	assert.Contains(t, ui.Outputs[1], "OK")
	assert.Contains(t, ui.Outputs[3], "space1")
	assert.Contains(t, ui.Outputs[4], "space2")
}
func deleteServiceBroker(t *testing.T, confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, repo *testapi.FakeServiceBrokerRepo) {
	serviceBroker := cf.ServiceBroker{
		Name: "service-broker-to-delete",
		Guid: "service-broker-to-delete-guid",
	}

	reqFactory = &testreq.FakeReqFactory{LoginSuccess: true}
	repo = &testapi.FakeServiceBrokerRepo{FindByNameServiceBroker: serviceBroker}
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	ctxt := testcmd.NewContext("delete-service-broker", args)
	cmd := NewDeleteServiceBroker(ui, config, repo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #4
0
func callListQuotas(t *testing.T, reqFactory *testreq.FakeReqFactory, quotaRepo *testapi.FakeQuotaRepository) (fakeUI *testterm.FakeUI) {
	fakeUI = &testterm.FakeUI{}
	ctxt := testcmd.NewContext("quotas", []string{})

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

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

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

	config := &configuration.Configuration{
		SpaceFields:        spaceFields,
		OrganizationFields: orgFields,
		AccessToken:        token,
	}

	cmd := organization.NewListQuotas(fakeUI, config, quotaRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #5
0
func TestListAllPagesOfOrgs(t *testing.T) {
	org1 := cf.Organization{}
	org1.Name = "Organization-1"

	org2 := cf.Organization{}
	org2.Name = "Organization-2"

	org3 := cf.Organization{}
	org3.Name = "Organization-3"

	orgRepo := &testapi.FakeOrgRepository{
		Organizations: []cf.Organization{org1, org2, org3},
	}

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	tokenInfo := configuration.TokenInfo{Username: "******"}
	accessToken, err := testconfig.CreateAccessTokenWithTokenInfo(tokenInfo)
	assert.NoError(t, err)
	config := &configuration.Configuration{AccessToken: accessToken}

	ui := callListOrgs(config, reqFactory, orgRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting orgs as my-user"},
		{"Organization-1"},
		{"Organization-2"},
		{"Organization-3"},
	})
}
Beispiel #6
0
func callListRoutes(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, routeRepo *testapi.FakeRouteRepository) (ui *testterm.FakeUI) {

	ui = &testterm.FakeUI{}

	ctxt := testcmd.NewContext("routes", args)

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

	cmd := NewListRoutes(ui, config, routeRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)

	return
}
Beispiel #7
0
func deleteSpace(t *testing.T, confirmation string, args []string) (ui *testterm.FakeUI, spaceRepo *testapi.FakeSpaceRepository) {
	space := cf.Space{Name: "space-to-delete", Guid: "space-to-delete-guid"}
	reqFactory := &testreq.FakeReqFactory{}
	spaceRepo = &testapi.FakeSpaceRepository{FindByNameSpace: space}
	configRepo := &testconfig.FakeConfigRepository{}

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

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	cmd := NewDeleteSpace(ui, config, spaceRepo, configRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #8
0
func deleteWithConfirmation(t *testing.T, confirmation string) (ui *testterm.FakeUI, userRepo *testapi.FakeUserRepository) {
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}

	userRepo = &testapi.FakeUserRepository{
		FindByUsernameUser: cf.User{Username: "******", Guid: "my-found-user-guid"},
	}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	cmd := NewDeleteUser(ui, config, userRepo)

	ctxt := testcmd.NewContext("delete-user", []string{"my-user"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #9
0
func deleteApp(t *testing.T, confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, appRepo *testapi.FakeApplicationRepository) {

	app := cf.Application{}
	app.Name = "app-to-delete"
	app.Guid = "app-to-delete-guid"

	reqFactory = &testreq.FakeReqFactory{}
	appRepo = &testapi.FakeApplicationRepository{ReadApp: app}
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	org := cf.OrganizationFields{}
	org.Name = "my-org"
	space := cf.SpaceFields{}
	space.Name = "my-space"
	config := &configuration.Configuration{
		SpaceFields:        space,
		OrganizationFields: org,
		AccessToken:        token,
	}

	ctxt := testcmd.NewContext("delete", args)
	cmd := NewDeleteApp(ui, config, appRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
func callDeleteServiceAuthToken(t *testing.T, args []string, inputs []string, reqFactory *testreq.FakeReqFactory, authTokenRepo *testapi.FakeAuthTokenRepo) (ui *testterm.FakeUI) {
	ui = &testterm.FakeUI{
		Inputs: inputs,
	}

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

	cmd := NewDeleteServiceAuthToken(ui, config, authTokenRepo)
	ctxt := testcmd.NewContext("delete-service-auth-token", args)

	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #11
0
func callStacks(t *testing.T, stackRepo *testapi.FakeStackRepository) (ui *testterm.FakeUI) {
	ui = &testterm.FakeUI{}

	ctxt := testcmd.NewContext("stacks", []string{})

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

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

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

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

	cmd := NewStacks(ui, config, stackRepo)
	testcmd.RunCommand(cmd, ctxt, nil)

	return
}
Beispiel #12
0
func callDeleteDomain(t *testing.T, args []string, inputs []string, reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (ui *testterm.FakeUI) {
	ctxt := testcmd.NewContext("delete-domain", args)
	ui = &testterm.FakeUI{
		Inputs: inputs,
	}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

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

	orgFields := cf.OrganizationFields{}
	orgFields.Name = "my-org"
	config := &configuration.Configuration{
		SpaceFields:        spaceFields,
		OrganizationFields: orgFields,
		AccessToken:        token,
	}

	cmd := domain.NewDeleteDomain(ui, config, domainRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #13
0
func deleteOrg(t *testing.T, confirmation string, args []string, orgRepo *testapi.FakeOrgRepository) (ui *testterm.FakeUI) {
	reqFactory := &testreq.FakeReqFactory{}
	configRepo := &testconfig.FakeConfigRepository{}

	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}
	ctxt := testcmd.NewContext("delete-org", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

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

	orgFields := cf.OrganizationFields{}
	orgFields.Name = "my-org"
	config := &configuration.Configuration{
		SpaceFields:        spaceFields,
		OrganizationFields: orgFields,
		AccessToken:        token,
	}

	cmd := NewDeleteOrg(ui, config, orgRepo, configRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #14
0
func callRenameOrg(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, orgRepo *testapi.FakeOrgRepository) (ui *testterm.FakeUI) {
	ui = new(testterm.FakeUI)
	ctxt := testcmd.NewContext("rename-org", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

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

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

	config := &configuration.Configuration{
		SpaceFields:        spaceFields,
		OrganizationFields: orgFields,
		AccessToken:        token,
	}

	cmd := organization.NewRenameOrg(ui, config, orgRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #15
0
func callDomainMapper(t *testing.T, shouldMap bool, args []string, reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (ui *testterm.FakeUI) {
	cmdName := "map-domain"
	if !shouldMap {
		cmdName = "unmap-domain"
	}

	ctxt := testcmd.NewContext(cmdName, args)
	ui = &testterm.FakeUI{}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

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

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

	config := &configuration.Configuration{
		SpaceFields:        spaceFields,
		OrganizationFields: orgFields,
		AccessToken:        token,
	}

	cmd := domain.NewDomainMapper(ui, config, domainRepo, shouldMap)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #16
0
func TestListingSpaces(t *testing.T) {
	space := cf.Space{}
	space.Name = "space1"
	space2 := cf.Space{}
	space2.Name = "space2"
	space3 := cf.Space{}
	space3.Name = "space3"
	spaceRepo := &testapi.FakeSpaceRepository{
		Spaces: []cf.Space{space, space2, space3},
	}
	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,
	}

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}
	ui := callSpaces([]string{}, reqFactory, config, spaceRepo)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting spaces in org", "my-org", "my-user"},
		{"space1"},
		{"space2"},
		{"space3"},
	})
}
Beispiel #17
0
func callPush(t *testing.T,
	args []string,
	starter ApplicationStarter,
	stopper ApplicationStopper,
	appRepo api.ApplicationRepository,
	domainRepo api.DomainRepository,
	routeRepo api.RouteRepository,
	stackRepo api.StackRepository,
	appBitsRepo *testapi.FakeApplicationBitsRepository) (fakeUI *testterm.FakeUI) {

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

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

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

	return
}
Beispiel #18
0
func TestListAllPagesOfOrgs(t *testing.T) {
	orgs := []cf.Organization{
		cf.Organization{Name: "Organization-1"},
		cf.Organization{Name: "Organization-2"},
		cf.Organization{Name: "Organization-3"},
	}
	orgRepo := &testapi.FakeOrgRepository{
		Organizations: orgs,
	}

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	tokenInfo := configuration.TokenInfo{Username: "******"}
	accessToken, err := testconfig.CreateAccessTokenWithTokenInfo(tokenInfo)
	assert.NoError(t, err)
	config := &configuration.Configuration{AccessToken: accessToken}

	ui := callListOrgs(config, reqFactory, orgRepo)

	testassert.SliceContains(t, ui.Outputs, []string{
		"Getting orgs as my-user",
		"Organization-1",
		"Organization-2",
		"Organization-3",
	})
}
Beispiel #19
0
func callRenameService(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory) (ui *testterm.FakeUI, serviceRepo *testapi.FakeServiceRepo) {
	ui = &testterm.FakeUI{}
	serviceRepo = &testapi.FakeServiceRepo{}

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

	cmd := NewRenameService(ui, config, serviceRepo)
	ctxt := testcmd.NewContext("rename-service", args)

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	return
}
Beispiel #20
0
func TestServices(t *testing.T) {
	plan := cf.ServicePlanFields{}
	plan.Guid = "spark-guid"
	plan.Name = "spark"

	offering := cf.ServiceOfferingFields{}
	offering.Label = "cleardb"

	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service-1"
	serviceInstance.ServicePlan = plan
	serviceInstance.ApplicationNames = []string{"cli1", "cli2"}
	serviceInstance.ServiceOffering = offering

	plan2 := cf.ServicePlanFields{}
	plan2.Guid = "spark-guid-2"
	plan2.Name = "spark-2"

	serviceInstance2 := cf.ServiceInstance{}
	serviceInstance2.Name = "my-service-2"
	serviceInstance2.ServicePlan = plan2
	serviceInstance2.ApplicationNames = []string{"cli1"}
	serviceInstance2.ServiceOffering = offering

	serviceInstance3 := cf.ServiceInstance{}
	serviceInstance3.Name = "my-service-provided-by-user"

	serviceInstances := []cf.ServiceInstance{serviceInstance, serviceInstance2, serviceInstance3}
	serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{
		GetSummariesInCurrentSpaceInstances: serviceInstances,
	}
	ui := &testterm.FakeUI{}

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

	cmd := NewListServices(ui, config, serviceSummaryRepo)
	cmd.Run(testcmd.NewContext("services", []string{}))

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting services in org", "my-org", "my-space", "my-user"},
		{"OK"},
		{"my-service-1", "cleardb", "spark", "cli1, cli2"},
		{"my-service-2", "cleardb", "spark-2", "cli1"},
		{"my-service-provided-by-user", "user-provided"},
	})
}
Beispiel #21
0
func startAppWithInstancesAndErrors(t *testing.T, app cf.Application, instances [][]cf.ApplicationInstance, errorCodes []string) (ui *testterm.FakeUI, appRepo *testapi.FakeApplicationRepository, reqFactory *testreq.FakeReqFactory) {
	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:                   cf.Space{Name: "my-space"},
		Organization:            cf.Organization{Name: "my-org"},
		AccessToken:             token,
		ApplicationStartTimeout: 2,
	}

	appRepo = &testapi.FakeApplicationRepository{
		FindByNameApp:          app,
		GetInstancesResponses:  instances,
		GetInstancesErrorCodes: errorCodes,
	}

	currentTime := time.Now()
	messageType := logmessage.LogMessage_ERR
	sourceType := logmessage.LogMessage_DEA
	logMessage1 := logmessage.LogMessage{
		Message:     []byte("Log Line 1"),
		AppId:       proto.String(app.Guid),
		MessageType: &messageType,
		SourceType:  &sourceType,
		Timestamp:   proto.Int64(currentTime.UnixNano()),
	}

	logMessage2 := logmessage.LogMessage{
		Message:     []byte("Log Line 2"),
		AppId:       proto.String(app.Guid),
		MessageType: &messageType,
		SourceType:  &sourceType,
		Timestamp:   proto.Int64(currentTime.UnixNano()),
	}

	logRepo := &testapi.FakeLogsRepository{
		TailLogMessages: []logmessage.LogMessage{
			logMessage1,
			logMessage2,
		},
	}

	args := []string{"my-app"}
	reqFactory = &testreq.FakeReqFactory{Application: app}
	ui = callStart(args, config, reqFactory, appRepo, logRepo)
	return
}
Beispiel #22
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"},
	})
}
func TestMarketplaceServices(t *testing.T) {
	serviceOfferings := []cf.ServiceOffering{
		cf.ServiceOffering{
			Label:       "my-service-offering-1",
			Description: "service offering 1 description",
			Plans: []cf.ServicePlan{
				cf.ServicePlan{Name: "service-plan-a"},
				cf.ServicePlan{Name: "service-plan-b"},
			},
		},
		cf.ServiceOffering{
			Label:       "my-service-offering-2",
			Description: "service offering 2 description",
			Plans: []cf.ServicePlan{
				cf.ServicePlan{Name: "service-plan-c"},
				cf.ServicePlan{Name: "service-plan-d"},
			},
		},
	}
	serviceRepo := &testapi.FakeServiceRepo{ServiceOfferings: serviceOfferings}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space", Guid: "my-space-guid"},
		Organization: cf.Organization{Name: "my-org", Guid: "my-org-guid"},
		AccessToken:  token,
	}

	ui := callMarketplaceServices(t, config, serviceRepo)

	assert.Contains(t, ui.Outputs[0], "Getting services from marketplace in org")
	assert.Contains(t, ui.Outputs[0], "my-org")
	assert.Contains(t, ui.Outputs[0], "my-space")
	assert.Contains(t, ui.Outputs[0], "my-user")
	assert.Contains(t, ui.Outputs[1], "OK")

	assert.Contains(t, ui.Outputs[4], "my-service-offering-1")
	assert.Contains(t, ui.Outputs[4], "service offering 1 description")
	assert.Contains(t, ui.Outputs[4], "service-plan-a, service-plan-b")

	assert.Contains(t, ui.Outputs[5], "my-service-offering-2")
	assert.Contains(t, ui.Outputs[5], "service offering 2 description")
	assert.Contains(t, ui.Outputs[5], "service-plan-c, service-plan-d")
}
Beispiel #24
0
func callShowSpace(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, config *configuration.Configuration) (ui *testterm.FakeUI) {
	ui = new(testterm.FakeUI)
	ctxt := testcmd.NewContext("space", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config.Organization = cf.Organization{Name: "my-org"}
	config.AccessToken = token

	cmd := NewShowSpace(ui, config)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #25
0
func callShareDomain(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (fakeUI *testterm.FakeUI) {
	fakeUI = new(testterm.FakeUI)
	ctxt := testcmd.NewContext("share-domain", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		AccessToken: token,
	}

	cmd := NewShareDomain(fakeUI, config, domainRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #26
0
func TestUpdatePassword(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "PUT",
		Path:     "/Users/my-user-guid/password",
		Matcher:  testnet.RequestBodyMatcher(`{"password":"******","oldPassword":"******"}`),
		Response: testnet.TestResponse{Status: http.StatusOK},
	})

	accessToken, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{UserGuid: "my-user-guid"})
	assert.NoError(t, err)

	passwordUpdateServer, handler, repo := createPasswordRepo(t, req, accessToken)
	defer passwordUpdateServer.Close()

	apiResponse := repo.UpdatePassword("old-password", "new-password")
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
}
Beispiel #27
0
func callRenameSpace(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, spaceRepo *testapi.FakeSpaceRepository) (ui *testterm.FakeUI) {
	ui = new(testterm.FakeUI)
	ctxt := testcmd.NewContext("create-space", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	cmd := NewRenameSpace(ui, config, spaceRepo, testconfig.FakeConfigRepository{})
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #28
0
func callListDomains(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (fakeUI *testterm.FakeUI) {
	fakeUI = new(testterm.FakeUI)
	ctxt := testcmd.NewContext("domains", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	cmd := NewListDomains(fakeUI, config, domainRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #29
0
func callUnsetSpaceRole(t *testing.T, args []string, spaceRepo *testapi.FakeSpaceRepository, userRepo *testapi.FakeUserRepository, reqFactory *testreq.FakeReqFactory) (ui *testterm.FakeUI) {
	ui = &testterm.FakeUI{}
	ctxt := testcmd.NewContext("unset-space-role", args)

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "my-space"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	cmd := NewUnsetSpaceRole(ui, config, spaceRepo, userRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Beispiel #30
0
func callApps(t *testing.T, appSummaryRepo *testapi.FakeAppSummaryRepo, reqFactory *testreq.FakeReqFactory) (ui *testterm.FakeUI) {
	ui = &testterm.FakeUI{}
	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)

	config := &configuration.Configuration{
		Space:        cf.Space{Name: "development"},
		Organization: cf.Organization{Name: "my-org"},
		AccessToken:  token,
	}

	ctxt := testcmd.NewContext("apps", []string{})
	cmd := NewListApps(ui, config, appSummaryRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)

	return
}