예제 #1
0
func TestPasswordCanBeChanged(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{ValidAccessTokenSuccess: true}
	pwdRepo := &testapi.FakePasswordRepo{Score: "meh"}
	configRepo := &testconfig.FakeConfigRepository{}
	ui := callPassword([]string{"old-password", "new-password", "new-password"}, reqFactory, pwdRepo, configRepo)

	testassert.SliceContains(t, ui.PasswordPrompts, testassert.Lines{
		{"Current Password"},
		{"New Password"},
		{"Verify Password"},
	})

	assert.Equal(t, pwdRepo.ScoredPassword, "new-password")
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Your password strength is: meh"},
		{"Changing password..."},
		{"OK"},
		{"Please log in again"},
	})

	assert.Equal(t, pwdRepo.UpdateNewPassword, "new-password")
	assert.Equal(t, pwdRepo.UpdateOldPassword, "old-password")

	updatedConfig, err := configRepo.Get()
	assert.NoError(t, err)
	assert.Empty(t, updatedConfig.AccessToken)
	assert.Equal(t, updatedConfig.OrganizationFields, cf.OrganizationFields{})
	assert.Equal(t, updatedConfig.SpaceFields, cf.SpaceFields{})
}
예제 #2
0
func TestCreateUserProvidedServiceWithParameterList(t *testing.T) {
	repo := &testapi.FakeUserProvidedServiceInstanceRepo{}
	ui := callCreateUserProvidedService(t,
		[]string{"-p", `"foo, bar, baz"`, "my-custom-service"},
		[]string{"foo value", "bar value", "baz value"},
		repo,
	)

	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"foo"},
		{"bar"},
		{"baz"},
	})

	assert.Equal(t, repo.CreateName, "my-custom-service")
	assert.Equal(t, repo.CreateParams, map[string]string{
		"foo": "foo value",
		"bar": "bar value",
		"baz": "baz value",
	})

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating user provided service", "my-custom-service", "my-org", "my-space", "my-user"},
		{"OK"},
	})
}
예제 #3
0
파일: password_test.go 프로젝트: nsnt/cli
func TestPasswordCanBeChanged(t *testing.T) {
	deps := getPasswordDeps()
	deps.ReqFactory.ValidAccessTokenSuccess = true
	deps.PwdRepo.UpdateUnauthorized = false
	ui := callPassword([]string{"old-password", "new-password", "new-password"}, deps)

	testassert.SliceContains(t, ui.PasswordPrompts, testassert.Lines{
		{"Current Password"},
		{"New Password"},
		{"Verify Password"},
	})

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Changing password..."},
		{"OK"},
		{"Please log in again"},
	})

	assert.Equal(t, deps.PwdRepo.UpdateNewPassword, "new-password")
	assert.Equal(t, deps.PwdRepo.UpdateOldPassword, "old-password")

	updatedConfig, err := deps.ConfigRepo.Get()
	assert.NoError(t, err)
	assert.Empty(t, updatedConfig.AccessToken)
	assert.Equal(t, updatedConfig.OrganizationFields, cf.OrganizationFields{})
	assert.Equal(t, updatedConfig.SpaceFields, cf.SpaceFields{})
}
예제 #4
0
파일: app_test.go 프로젝트: nsnt/cli
func TestPushCommandHelpOutput(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{}
	cmdRunner := commands.NewRunner(nil, reqFactory)
	app, _ := NewApp(cmdRunner)

	var updateCommand, pushCommand cli.Command
	for _, cmd := range app.Commands {
		if cmd.Name == "push" {
			pushCommand = cmd
		} else if cmd.Name == "update-buildpack" {
			updateCommand = cmd
		}
	}

	flags := []string{}
	for _, flag := range pushCommand.Flags {
		flags = append(flags, flag.String())
	}

	testassert.SliceContains(t, flags, testassert.Lines{
		{"-b \tCustom buildpack URL (e.g. https://github.com/heroku/heroku-buildpack-play.git)"},
	})

	flags = []string{}
	for _, flag := range updateCommand.Flags {
		flags = append(flags, flag.String())
	}

	testassert.SliceContains(t, flags, testassert.Lines{
		{"-i \tBuildpack position among other buildpacks"},
	})
}
예제 #5
0
func TestDeleteRouteWithConfirmation(t *testing.T) {
	domain := cf.DomainFields{}
	domain.Guid = "domain-guid"
	domain.Name = "example.com"
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	route := cf.Route{}
	route.Guid = "route-guid"
	route.Host = "my-host"
	route.Domain = domain
	routeRepo := &testapi.FakeRouteRepository{
		FindByHostAndDomainRoute: route,
	}

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

	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"Really delete", "my-host"},
	})

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting route", "my-host.example.com"},
		{"OK"},
	})
	assert.Equal(t, routeRepo.DeleteRouteGuid, "route-guid")
}
예제 #6
0
func TestDeleteBuildpackSuccess(t *testing.T) {
	ui := &testterm.FakeUI{Inputs: []string{"y"}}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameBuildpack: buildpack,
	}
	cmd := NewDeleteBuildpack(ui, buildpackRepo)

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

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.DeleteBuildpackGuid, "my-buildpack-guid")

	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"delete", "my-buildpack"},
	})
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting buildpack", "my-buildpack"},
		{"OK"},
	})
}
예제 #7
0
func TestDeleteSpaceConfirmingWithYes(t *testing.T) {
	ui, spaceRepo := deleteSpace(t, []string{"Yes"}, []string{"space-to-delete"}, defaultDeleteSpaceReqFactory())

	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"Really delete", "space-to-delete"},
	})
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting space", "space-to-delete", "my-org", "my-user"},
		{"OK"},
	})
	assert.Equal(t, spaceRepo.DeletedSpaceGuid, "space-to-delete-guid")
}
예제 #8
0
파일: delete_app_test.go 프로젝트: nsnt/cli
func TestDeleteConfirmingWithY(t *testing.T) {
	ui, _, appRepo := deleteApp(t, "y", []string{"app-to-delete"})

	assert.Equal(t, appRepo.ReadName, "app-to-delete")
	assert.Equal(t, appRepo.DeletedAppGuid, "app-to-delete-guid")
	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"Really delete"},
	})
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting", "app-to-delete", "my-org", "my-space", "my-user"},
		{"OK"},
	})
}
예제 #9
0
func TestDeleteConfirmingWithY(t *testing.T) {
	ui, _, repo := deleteServiceBroker(t, "y", []string{"service-broker-to-delete"})

	assert.Equal(t, repo.FindByNameName, "service-broker-to-delete")
	assert.Equal(t, repo.DeletedServiceBrokerGuid, "service-broker-to-delete-guid")
	assert.Equal(t, len(ui.Outputs), 2)
	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"Really delete", "service-broker-to-delete"},
	})
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting service broker", "service-broker-to-delete", "my-user"},
		{"OK"},
	})
}
예제 #10
0
func TestSetSpaceRole(t *testing.T) {
	org := cf.Organization{}
	org.Guid = "my-org-guid"
	org.Name = "my-org"

	args := []string{"some-user", "some-org", "some-space", "SpaceManager"}

	reqFactory, spaceRepo, userRepo := getSetSpaceRoleDeps()
	reqFactory.LoginSuccess = true
	reqFactory.UserFields = cf.UserFields{}
	reqFactory.UserFields.Guid = "my-user-guid"
	reqFactory.UserFields.Username = "******"
	reqFactory.Organization = org

	spaceRepo.FindByNameInOrgSpace = cf.Space{}
	spaceRepo.FindByNameInOrgSpace.Guid = "my-space-guid"
	spaceRepo.FindByNameInOrgSpace.Name = "my-space"
	spaceRepo.FindByNameInOrgSpace.Organization = org.OrganizationFields

	ui := callSetSpaceRole(t, args, reqFactory, spaceRepo, userRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Assigning role ", "SpaceManager", "my-user", "my-org", "my-space", "current-user"},
		{"OK"},
	})

	assert.Equal(t, spaceRepo.FindByNameInOrgName, "some-space")
	assert.Equal(t, spaceRepo.FindByNameInOrgOrgGuid, "my-org-guid")

	assert.Equal(t, userRepo.SetSpaceRoleUserGuid, "my-user-guid")
	assert.Equal(t, userRepo.SetSpaceRoleSpaceGuid, "my-space-guid")
	assert.Equal(t, userRepo.SetSpaceRoleRole, cf.SPACE_MANAGER)
}
예제 #11
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"},
	})
}
예제 #12
0
func TestCreateServiceWhenServiceAlreadyExists(t *testing.T) {
	offering := cf.ServiceOffering{}
	offering.Label = "cleardb"
	plan := cf.ServicePlanFields{}
	plan.Name = "spark"
	plan.Guid = "cleardb-spark-guid"
	offering.Plans = []cf.ServicePlanFields{plan}
	offering2 := cf.ServiceOffering{}
	offering2.Label = "postgres"
	serviceOfferings := []cf.ServiceOffering{offering, offering2}
	serviceRepo := &testapi.FakeServiceRepo{ServiceOfferings: serviceOfferings, CreateServiceAlreadyExists: true}
	ui := callCreateService(t,
		[]string{"cleardb", "spark", "my-cleardb-service"},
		[]string{},
		serviceRepo,
	)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating service", "my-cleardb-service"},
		{"OK"},
		{"my-cleardb-service", "already exists"},
	})
	assert.Equal(t, serviceRepo.CreateServiceInstanceName, "my-cleardb-service")
	assert.Equal(t, serviceRepo.CreateServiceInstancePlanGuid, "cleardb-spark-guid")
}
예제 #13
0
파일: manifest_test.go 프로젝트: nsnt/cli
func TestParsingManifestWithNulls(t *testing.T) {
	_, errs := manifest.NewManifest(generic.NewMap(map[string]interface{}{
		"applications": []interface{}{
			map[string]interface{}{
				"buildpack":  nil,
				"disk_quota": nil,
				"domain":     nil,
				"host":       nil,
				"name":       nil,
				"path":       nil,
				"stack":      nil,
				"memory":     nil,
				"instances":  nil,
				"timeout":    nil,
				"no-route":   nil,
				"services":   nil,
				"env":        nil,
			},
		},
	}))

	assert.Error(t, errs)
	errorSlice := strings.Split(errs.Error(), "\n")
	manifestKeys := []string{"buildpack", "disk_quota", "domain", "host", "name", "path", "stack",
		"memory", "instances", "timeout", "no-route", "services", "env"}

	for _, key := range manifestKeys {
		testassert.SliceContains(t, errorSlice, testassert.Lines{{key, "not be null"}})
	}
}
예제 #14
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"},
	})
}
예제 #15
0
파일: push_test.go 프로젝트: nsnt/cli
func TestPushingAppWhenItAlreadyExistsAndDomainIsSpecifiedIsAlreadyBound(t *testing.T) {
	deps := getPushDependencies()

	domain := cf.DomainFields{}
	domain.Name = "example.com"
	domain.Guid = "domain-guid"

	existingRoute := cf.RouteSummary{}
	existingRoute.Host = "existing-app"
	existingRoute.Domain = domain

	existingApp := cf.Application{}
	existingApp.Name = "existing-app"
	existingApp.Guid = "existing-app-guid"
	existingApp.Routes = []cf.RouteSummary{existingRoute}

	foundRoute := cf.Route{}
	foundRoute.RouteFields = existingRoute.RouteFields
	foundRoute.Domain = existingRoute.Domain

	deps.appRepo.ReadApp = existingApp
	deps.appRepo.UpdateAppResult = existingApp
	deps.routeRepo.FindByHostAndDomainRoute = foundRoute

	ui := callPush(t, []string{"-d", "example.com", "existing-app"}, deps)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Using route", "existing-app", "example.com"},
	})
	assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, "existing-app-guid")
}
예제 #16
0
func TestDeleteBuildpackThatDoesNotExist(t *testing.T) {
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameNotFound:  true,
		FindByNameBuildpack: buildpack,
	}

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

	cmd := NewDeleteBuildpack(ui, buildpackRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.FindByNameName, "my-buildpack")
	assert.True(t, buildpackRepo.FindByNameNotFound)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting", "my-buildpack"},
		{"OK"},
		{"my-buildpack", "does not exist"},
	})
}
예제 #17
0
func TestShowServiceOutput(t *testing.T) {
	offering := cf.ServiceOfferingFields{}
	offering.Label = "mysql"
	offering.DocumentationUrl = "http://documentation.url"
	offering.Description = "the-description"

	plan := cf.ServicePlanFields{}
	plan.Guid = "plan-guid"
	plan.Name = "plan-name"

	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "service1"
	serviceInstance.Guid = "service1-guid"
	serviceInstance.ServicePlan = plan
	serviceInstance.ServiceOffering = offering
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:         true,
		TargetedSpaceSuccess: true,
		ServiceInstance:      serviceInstance,
	}
	ui := callShowService([]string{"service1"}, reqFactory)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Service instance:", "service1"},
		{"Service: ", "mysql"},
		{"Plan: ", "plan-name"},
		{"Description: ", "the-description"},
		{"Documentation url: ", "http://documentation.url"},
	})
}
예제 #18
0
func TestDeleteBuildpackDeleteError(t *testing.T) {
	ui := &testterm.FakeUI{Inputs: []string{"y"}}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameBuildpack: buildpack,
		DeleteApiResponse:   net.NewApiResponseWithMessage("failed badly"),
	}

	cmd := NewDeleteBuildpack(ui, buildpackRepo)

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

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.DeleteBuildpackGuid, "my-buildpack-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting buildpack", "my-buildpack"},
		{"FAILED"},
		{"my-buildpack"},
		{"failed badly"},
	})
}
예제 #19
0
파일: push_test.go 프로젝트: nsnt/cli
func TestPushingAppWhenItDoesNotExistButRouteExists(t *testing.T) {
	deps := getPushDependencies()

	domain := cf.Domain{}
	domain.Name = "foo.cf-app.com"
	domain.Guid = "foo-domain-guid"
	domain.Shared = true

	route := cf.Route{}
	route.Guid = "my-route-guid"
	route.Host = "my-new-app"
	route.Domain = domain.DomainFields

	deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{domain}

	deps.routeRepo.FindByHostAndDomainRoute = route
	deps.appRepo.ReadNotFound = true

	ui := callPush(t, []string{"my-new-app"}, deps)

	assert.Empty(t, deps.routeRepo.CreatedHost)
	assert.Empty(t, deps.routeRepo.CreatedDomainGuid)
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "my-new-app")
	assert.Equal(t, deps.routeRepo.BoundAppGuid, "my-new-app-guid")
	assert.Equal(t, deps.routeRepo.BoundRouteGuid, "my-route-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Using", "my-new-app.foo.cf-app.com"},
		{"Binding", "my-new-app.foo.cf-app.com"},
		{"OK"},
	})
}
예제 #20
0
파일: logs_test.go 프로젝트: nsnt/cli
func TestLogsOutputsRecentLogs(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"

	currentTime := time.Now()

	recentLogs := []*logmessage.Message{
		NewLogMessage("Log Line 1", app.Guid, "DEA", currentTime),
		NewLogMessage("Log Line 2", app.Guid, "DEA", currentTime),
	}

	reqFactory, logsRepo := getLogsDependencies()
	reqFactory.Application = app
	logsRepo.RecentLogs = recentLogs

	ui := callLogs(t, []string{"--recent", "my-app"}, reqFactory, logsRepo)

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, app.Guid, logsRepo.AppLoggedGuid)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Connected, dumping recent logs for app", "my-app", "my-org", "my-space", "my-user"},
		{"Log Line 1"},
		{"Log Line 2"},
	})
}
예제 #21
0
파일: push_test.go 프로젝트: nsnt/cli
func TestPushingAppWhenItAlreadyExistsWithoutARouteCreatesADefaultDomain(t *testing.T) {
	deps := getPushDependencies()

	sharedDomain := cf.Domain{}
	sharedDomain.Name = "foo.cf-app.com"
	sharedDomain.Shared = true
	sharedDomain.Guid = "foo-domain-guid"

	deps.routeRepo.FindByHostAndDomainErr = true
	deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{sharedDomain}
	deps.appRepo.ReadApp = maker.NewApp(maker.Overrides{"name": "existing-app", "guid": "existing-app-guid"})
	deps.appRepo.UpdateAppResult = deps.appRepo.ReadApp

	ui := callPush(t, []string{"-t", "111", "existing-app"}, deps)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route", "existing-app.foo.cf-app.com"},
		{"OK"},
		{"Binding", "existing-app.foo.cf-app.com"},
		{"OK"},
		{"Uploading"},
		{"OK"},
	})

	assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "foo.cf-app.com")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "existing-app")

	assert.Equal(t, deps.routeRepo.CreatedHost, "existing-app")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "foo-domain-guid")

	assert.Equal(t, deps.routeRepo.BoundAppGuid, "existing-app-guid")
	assert.Equal(t, deps.routeRepo.BoundRouteGuid, "existing-app-route-guid")
}
예제 #22
0
파일: push_test.go 프로젝트: nsnt/cli
func TestPushingAppWhenItAlreadyExistsAndHostIsSpecified(t *testing.T) {
	deps := getPushDependencies()

	domain := cf.Domain{}
	domain.Name = "example.com"
	domain.Guid = "domain-guid"
	domain.Shared = true

	existingRoute := cf.RouteSummary{}
	existingRoute.Host = "existing-app"
	existingRoute.Domain = domain.DomainFields

	existingApp := cf.Application{}
	existingApp.Name = "existing-app"
	existingApp.Guid = "existing-app-guid"
	existingApp.Routes = []cf.RouteSummary{existingRoute}

	deps.appRepo.ReadApp = existingApp
	deps.appRepo.UpdateAppResult = existingApp
	deps.routeRepo.FindByHostAndDomainNotFound = true
	deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{domain}

	ui := callPush(t, []string{"-n", "new-host", "existing-app"}, deps)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Creating route", "new-host.example.com"},
		{"OK"},
		{"Binding", "new-host.example.com"},
	})

	assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "example.com")
	assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "new-host")
	assert.Equal(t, deps.routeRepo.CreatedHost, "new-host")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "domain-guid")
}
예제 #23
0
파일: list_orgs_test.go 프로젝트: nsnt/cli
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"},
	})
}
예제 #24
0
func TestListServiceBrokers(t *testing.T) {
	broker := cf.ServiceBroker{}
	broker.Name = "service-broker-to-list-a"
	broker.Guid = "service-broker-to-list-guid-a"
	broker.Url = "http://service-a-url.com"
	broker2 := cf.ServiceBroker{}
	broker2.Name = "service-broker-to-list-b"
	broker2.Guid = "service-broker-to-list-guid-b"
	broker2.Url = "http://service-b-url.com"
	broker3 := cf.ServiceBroker{}
	broker3.Name = "service-broker-to-list-c"
	broker3.Guid = "service-broker-to-list-guid-c"
	broker3.Url = "http://service-c-url.com"
	serviceBrokers := []cf.ServiceBroker{broker, broker2, broker3}

	repo := &testapi.FakeServiceBrokerRepo{
		ServiceBrokers: serviceBrokers,
	}

	ui := callListServiceBrokers(t, []string{}, repo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting service brokers as", "my-user"},
		{"name", "url"},
		{"service-broker-to-list-a", "http://service-a-url.com"},
		{"service-broker-to-list-b", "http://service-b-url.com"},
		{"service-broker-to-list-c", "http://service-c-url.com"},
	})
}
예제 #25
0
func TestUpdateServiceAuthToken(t *testing.T) {
	foundAuthToken := cf.ServiceAuthTokenFields{}
	foundAuthToken.Guid = "found-auth-token-guid"
	foundAuthToken.Label = "found label"
	foundAuthToken.Provider = "found provider"

	authTokenRepo := &testapi.FakeAuthTokenRepo{FindByLabelAndProviderServiceAuthTokenFields: foundAuthToken}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	args := []string{"a label", "a provider", "a value"}

	ui := callUpdateServiceAuthToken(t, args, reqFactory, authTokenRepo)
	expectedAuthToken := cf.ServiceAuthTokenFields{}
	expectedAuthToken.Guid = "found-auth-token-guid"
	expectedAuthToken.Label = "found label"
	expectedAuthToken.Provider = "found provider"
	expectedAuthToken.Token = "a value"

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Updating service auth token as", "my-user"},
		{"OK"},
	})

	assert.Equal(t, authTokenRepo.FindByLabelAndProviderLabel, "a label")
	assert.Equal(t, authTokenRepo.FindByLabelAndProviderProvider, "a provider")
	assert.Equal(t, authTokenRepo.UpdatedServiceAuthTokenFields, expectedAuthToken)
	assert.Equal(t, authTokenRepo.UpdatedServiceAuthTokenFields, expectedAuthToken)
}
예제 #26
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)
}
예제 #27
0
파일: start_test.go 프로젝트: nsnt/cli
func TestStartApplicationWhenOneInstanceFlaps(t *testing.T) {
	t.Parallel()

	displayApp := &testcmd.FakeAppDisplayer{}
	appInstance := cf.AppInstanceFields{}
	appInstance.State = cf.InstanceStarting
	appInstance2 := cf.AppInstanceFields{}
	appInstance2.State = cf.InstanceStarting
	appInstance3 := cf.AppInstanceFields{}
	appInstance3.State = cf.InstanceStarting
	appInstance4 := cf.AppInstanceFields{}
	appInstance4.State = cf.InstanceFlapping
	instances := [][]cf.AppInstanceFields{
		[]cf.AppInstanceFields{appInstance, appInstance2},
		[]cf.AppInstanceFields{appInstance3, appInstance4},
	}

	errorCodes := []string{"", ""}

	ui, _, _, _ := startAppWithInstancesAndErrors(t, displayApp, defaultAppForStart, instances, errorCodes, defaultStartTimeout)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"my-app"},
		{"OK"},
		{"0 of 2 instances running", "1 starting", "1 failing"},
		{"FAILED"},
		{"Start unsuccessful"},
	})
}
예제 #28
0
func TestDeleteUserWhenConfirmingWithYes(t *testing.T) {
	ui, userRepo := deleteWithConfirmation(t, "Yes")

	assert.Equal(t, len(ui.Outputs), 2)
	assert.Equal(t, len(ui.Prompts), 1)
	testassert.SliceContains(t, ui.Prompts, testassert.Lines{
		{"Really delete", "my-user"},
	})
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting user", "my-user", "current-user"},
		{"OK"},
	})

	assert.Equal(t, userRepo.FindByUsernameUsername, "my-user")
	assert.Equal(t, userRepo.DeleteUserGuid, "my-found-user-guid")
}
예제 #29
0
파일: map_route_test.go 프로젝트: nsnt/cli
func TestMapRouteWhenBinding(t *testing.T) {

	domain := cf.Domain{}
	domain.Guid = "my-domain-guid"
	domain.Name = "example.com"
	route := cf.Route{}
	route.Guid = "my-route-guid"
	route.Host = "foo"
	route.Domain = domain.DomainFields

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

	routeRepo := &testapi.FakeRouteRepository{}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Application: app, Domain: domain}
	routeCreator := &testcmd.FakeRouteCreator{ReservedRoute: route}

	ui := callMapRoute(t, []string{"-n", "my-host", "my-app", "my-domain.com"}, reqFactory, routeRepo, routeCreator)

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

	assert.Equal(t, routeRepo.BoundRouteGuid, "my-route-guid")
	assert.Equal(t, routeRepo.BoundAppGuid, "my-app-guid")
}
예제 #30
0
파일: push_test.go 프로젝트: nsnt/cli
func TestPushingAppWithCustomFlags(t *testing.T) {
	deps := getPushDependencies()
	domain := cf.Domain{}
	domain.Name = "bar.cf-app.com"
	domain.Guid = "bar-domain-guid"
	stack := cf.Stack{}
	stack.Name = "customLinux"
	stack.Guid = "custom-linux-guid"

	deps.domainRepo.FindByNameDomain = domain
	deps.routeRepo.FindByHostAndDomainErr = true
	deps.stackRepo.FindByNameStack = stack
	deps.appRepo.ReadNotFound = true

	ui := callPush(t, []string{
		"-c", "unicorn -c config/unicorn.rb -D",
		"-d", "bar.cf-app.com",
		"-n", "my-hostname",
		"-i", "3",
		"-m", "2G",
		"-b", "https://github.com/heroku/heroku-buildpack-play.git",
		"-s", "customLinux",
		"-t", "1",
		"--no-start",
		"my-new-app",
	}, deps)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Using", "customLinux"},
		{"OK"},
		{"Creating app", "my-new-app"},
		{"OK"},
		{"Creating Route", "my-hostname.bar.cf-app.com"},
		{"OK"},
		{"Binding", "my-hostname.bar.cf-app.com", "my-new-app"},
		{"Uploading", "my-new-app"},
		{"OK"},
	})

	assert.Equal(t, deps.stackRepo.FindByNameName, "customLinux")

	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("name").(string), "my-new-app")
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("command").(string), "unicorn -c config/unicorn.rb -D")
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("instances").(int), 3)
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("memory").(uint64), uint64(2048))
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("stack_guid"), "custom-linux-guid")
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("health_check_timeout").(int), 1)
	assert.Equal(t, deps.appRepo.CreatedAppParams().Get("buildpack"), "https://github.com/heroku/heroku-buildpack-play.git")

	assert.Equal(t, deps.domainRepo.FindByNameInCurrentSpaceName, "bar.cf-app.com")

	assert.Equal(t, deps.routeRepo.CreatedHost, "my-hostname")
	assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "bar-domain-guid")
	assert.Equal(t, deps.routeRepo.BoundAppGuid, "my-new-app-guid")
	assert.Equal(t, deps.routeRepo.BoundRouteGuid, "my-hostname-route-guid")

	assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, "my-new-app-guid")

	assert.Equal(t, deps.starter.AppToStart.Name, "")
}