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, "") }
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") }
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") }
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"}, }) }
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") }
func (repo CloudControllerDomainRepository) findAllWithPath(path string) (domains []cf.Domain, apiResponse net.ApiResponse) { domainResources := new(PaginatedDomainResources) apiResponse = repo.gateway.GetResource(path, repo.config.AccessToken, domainResources) if apiResponse.IsNotSuccessful() { return } for _, r := range domainResources.Resources { domain := cf.Domain{ Name: r.Entity.Name, Guid: r.Metadata.Guid, } domain.Shared = r.Entity.OwningOrganizationGuid == "" for _, space := range r.Entity.Spaces { domain.Spaces = append(domain.Spaces, cf.Space{ Name: space.Entity.Name, Guid: space.Metadata.Guid, }) } domains = append(domains, domain) } return }
func TestListDomains(t *testing.T) { orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" orgFields.Guid = "my-org-guid" reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, OrganizationFields: orgFields} domain1 := cf.Domain{} domain1.Shared = true domain1.Name = "Domain1" domain2 := cf.Domain{} domain2.Shared = false domain2.Name = "Domain2" domain3 := cf.Domain{} domain3.Shared = false domain3.Name = "Domain3" domainRepo := &testapi.FakeDomainRepository{ ListSharedDomainsDomains: []cf.Domain{domain1}, ListDomainsForOrgDomains: []cf.Domain{domain2, domain3}, } ui := callListDomains(t, []string{}, reqFactory, domainRepo) assert.Equal(t, domainRepo.ListDomainsForOrgDomainsGuid, "my-org-guid") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting domains in org", "my-org", "my-user"}, {"name", "status"}, {"Domain1", "shared"}, {"Domain2", "owned"}, {"Domain3", "owned"}, }) }
func TestDomainReqExecute(t *testing.T) { domain := cf.Domain{} domain.Name = "example.com" domain.Guid = "domain-guid" domainRepo := &testapi.FakeDomainRepository{FindByNameDomain: domain} ui := new(testterm.FakeUI) domainReq := newDomainRequirement("example.com", ui, domainRepo) success := domainReq.Execute() assert.True(t, success) assert.Equal(t, domainRepo.FindByNameInCurrentSpaceName, "example.com") assert.Equal(t, domainReq.GetDomain(), domain) }
func TestPushingAppWithNoRoute(t *testing.T) { deps := getPushDependencies() domain := cf.Domain{} domain.Name = "bar.cf-app.com" domain.Guid = "bar-domain-guid" deps.domainRepo.FindByNameDomain = domain deps.routeRepo.FindByHostErr = true deps.appRepo.ReadNotFound = true callPush(t, []string{ "--no-route", "my-new-app", }, deps) assert.Equal(t, deps.appRepo.CreatedAppParams().Get("name").(string), "my-new-app") assert.Equal(t, deps.routeRepo.CreatedHost, "") assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "") }
func TestPushingAppWhenItDoesNotExist(t *testing.T) { deps := getPushDependencies() domain := cf.Domain{} domain.Guid = "not-the-right-guid" domain.Name = "not shared domain" domain.OwningOrganizationGuid = "my-org-guid" sharedDomain := cf.Domain{} sharedDomain.Name = "foo.cf-app.com" sharedDomain.Shared = true sharedDomain.Guid = "foo-domain-guid" appRepo := deps.appRepo domainRepo := deps.domainRepo routeRepo := deps.routeRepo appBitsRepo := deps.appBitsRepo stopper := deps.stopper starter := deps.starter domainRepo.ListDomainsForOrgDomains = []cf.Domain{domain, sharedDomain} routeRepo.FindByHostAndDomainErr = true appRepo.ReadNotFound = true ui := callPush(t, []string{"-t", "111", "my-new-app"}, deps) assert.Equal(t, appRepo.CreatedAppParams().Get("name").(string), "my-new-app") assert.Equal(t, appRepo.CreatedAppParams().Get("space_guid").(string), "my-space-guid") assert.Equal(t, routeRepo.FindByHostAndDomainHost, "my-new-app") assert.Equal(t, routeRepo.CreatedHost, "my-new-app") assert.Equal(t, routeRepo.CreatedDomainGuid, "foo-domain-guid") assert.Equal(t, routeRepo.BoundAppGuid, "my-new-app-guid") assert.Equal(t, routeRepo.BoundRouteGuid, "my-new-app-route-guid") assert.Equal(t, appBitsRepo.UploadedAppGuid, "my-new-app-guid") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Creating app", "my-new-app", "my-org", "my-space"}, {"OK"}, {"Creating", "my-new-app.foo.cf-app.com"}, {"OK"}, {"Binding", "my-new-app.foo.cf-app.com"}, {"OK"}, {"Uploading my-new-app"}, {"OK"}, }) assert.Equal(t, stopper.AppToStop.Guid, "") assert.Equal(t, starter.AppToStart.Guid, "my-new-app-guid") assert.Equal(t, starter.AppToStart.Name, "my-new-app") assert.Equal(t, starter.Timeout, 111) }
func TestFindByHostAndDomainWhenRouteIsNotFound(t *testing.T) { request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/routes?q=host%3Amy-cool-app%3Bdomain_guid%3Amy-domain-guid", Response: testnet.TestResponse{Status: http.StatusOK, Body: `{ "resources": [ ] }`}, }) ts, handler, repo, domainRepo := createRoutesRepo(t, request) defer ts.Close() domain := cf.Domain{} domain.Guid = "my-domain-guid" domainRepo.FindByNameDomain = domain _, apiResponse := repo.FindByHostAndDomain("my-cool-app", "my-domain.com") assert.True(t, handler.AllRequestsCalled()) assert.False(t, apiResponse.IsError()) assert.True(t, apiResponse.IsNotFound()) }
func TestDeleteDomainForceFlagSkipsConfirmation(t *testing.T) { reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true} domain := cf.Domain{} domain.Name = "foo.com" domain.Guid = "foo-guid" domain.Shared = true domainRepo := &testapi.FakeDomainRepository{ FindByNameInOrgDomain: domain, } ui := callDeleteDomain(t, []string{"-f", "foo.com"}, []string{}, reqFactory, domainRepo) assert.Equal(t, domainRepo.DeleteDomainGuid, "foo-guid") assert.Equal(t, len(ui.Prompts), 0) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Deleting domain", "foo.com"}, {"OK"}, }) }
func TestDeleteDomainDeleteError(t *testing.T) { domain := cf.Domain{} domain.Name = "foo.com" domain.Guid = "foo-guid" domainRepo := &testapi.FakeDomainRepository{ FindByNameInOrgDomain: domain, DeleteApiResponse: net.NewApiResponseWithMessage("failed badly"), } reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true} ui := callDeleteDomain(t, []string{"foo.com"}, []string{"y"}, reqFactory, domainRepo) assert.Equal(t, domainRepo.DeleteDomainGuid, "foo-guid") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Deleting domain", "foo.com"}, {"FAILED"}, {"foo.com"}, {"failed badly"}, }) }
func TestPushingAppWithSingleAppManifest(t *testing.T) { deps := getPushDependencies() domain := cf.Domain{} domain.Name = "manifest-example.com" domain.Guid = "bar-domain-guid" deps.domainRepo.FindByNameDomain = domain deps.routeRepo.FindByHostAndDomainErr = true deps.appRepo.ReadNotFound = true deps.manifestRepo.ReadManifestManifest = singleAppManifest() ui := callPush(t, []string{}, deps) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Creating route", "manifest-host.manifest-example.com"}, {"OK"}, {"Binding", "manifest-host.manifest-example.com"}, {"manifest-app-name"}, }) cwd, err := os.Getwd() assert.NoError(t, err) assert.Equal(t, deps.appRepo.CreatedAppParams().Get("name").(string), "manifest-app-name") assert.Equal(t, deps.appRepo.CreatedAppParams().Get("memory").(uint64), uint64(128)) assert.Equal(t, deps.appRepo.CreatedAppParams().Get("instances").(int), 1) assert.Equal(t, deps.appRepo.CreatedAppParams().Get("stack").(string), "custom-stack") assert.Equal(t, deps.appRepo.CreatedAppParams().Get("buildpack").(string), "some-buildpack") assert.Equal(t, deps.appRepo.CreatedAppParams().Get("command").(string), "JAVA_HOME=$PWD/.openjdk JAVA_OPTS=\"-Xss995K\" ./bin/start.sh run") assert.Equal(t, deps.appRepo.CreatedAppParams().Get("path").(string), filepath.Join(cwd, "../../fixtures/example-app")) assert.True(t, deps.appRepo.CreatedAppParams().Has("env")) envVars := deps.appRepo.CreatedAppParams().Get("env").(generic.Map) assert.Equal(t, 2, envVars.Count()) assert.True(t, envVars.Has("PATH")) assert.True(t, envVars.Has("FOO")) assert.Equal(t, envVars.Get("PATH").(string), "/u/apps/my-app/bin") assert.Equal(t, envVars.Get("FOO").(string), "baz") }
func TestDeleteDomainNoConfirmation(t *testing.T) { domain := cf.Domain{} domain.Name = "foo.com" domain.Guid = "foo-guid" domainRepo := &testapi.FakeDomainRepository{ FindByNameInOrgDomain: domain, } reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true} ui := callDeleteDomain(t, []string{"foo.com"}, []string{"no"}, reqFactory, domainRepo) assert.Equal(t, domainRepo.DeleteDomainGuid, "") testassert.SliceContains(t, ui.Prompts, testassert.Lines{ {"delete", "foo.com"}, }) assert.Equal(t, len(ui.Outputs), 1) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Deleting domain", "foo.com"}, }) }
func TestPushingAppWhenItAlreadyExistsAndDomainSpecifiedIsNotBound(t *testing.T) { deps := getPushDependencies() domain := cf.DomainFields{} domain.Name = "example.com" 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} foundDomain := cf.Domain{} foundDomain.Guid = "domain-guid" foundDomain.Name = "newdomain.com" deps.appRepo.ReadApp = existingApp deps.appRepo.UpdateAppResult = existingApp deps.routeRepo.FindByHostAndDomainNotFound = true deps.domainRepo.FindByNameDomain = foundDomain ui := callPush(t, []string{"-d", "newdomain.com", "existing-app"}, deps) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Creating route", "existing-app.newdomain.com"}, {"OK"}, {"Binding", "existing-app.newdomain.com"}, }) assert.Equal(t, deps.appBitsRepo.UploadedAppGuid, "existing-app-guid") assert.Equal(t, deps.domainRepo.FindByNameInCurrentSpaceName, "newdomain.com") assert.Equal(t, deps.routeRepo.FindByHostAndDomainDomain, "newdomain.com") assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "existing-app") assert.Equal(t, deps.routeRepo.CreatedHost, "existing-app") assert.Equal(t, deps.routeRepo.CreatedDomainGuid, "domain-guid") }
func TestFindByHostAndDomain(t *testing.T) { request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/routes?q=host%3Amy-cool-app%3Bdomain_guid%3Amy-domain-guid", Response: findRouteByHostResponse, }) ts, handler, repo, domainRepo := createRoutesRepo(t, request) defer ts.Close() domain := cf.Domain{} domain.Guid = "my-domain-guid" domainRepo.FindByNameDomain = domain route, apiResponse := repo.FindByHostAndDomain("my-cool-app", "my-domain.com") assert.False(t, apiResponse.IsNotSuccessful()) assert.True(t, handler.AllRequestsCalled()) assert.Equal(t, domainRepo.FindByNameName, "my-domain.com") assert.Equal(t, route.Host, "my-cool-app") assert.Equal(t, route.Guid, "my-route-guid") assert.Equal(t, route.Domain.Guid, domain.Guid) }
func getDomainMapperDeps() (reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) { domain := cf.Domain{} domain.Name = "foo.com" domain.Guid = "foo-guid" domainRepo = &testapi.FakeDomainRepository{ FindByNameInOrgDomain: domain, } org := cf.Organization{} org.Name = "my-org" org.Guid = "my-org-guid" space := cf.Space{} space.Name = "my-space" space.Guid = "my-space-guid" reqFactory = &testreq.FakeReqFactory{ LoginSuccess: true, TargetedOrgSuccess: true, Organization: org, Space: space, } return }
func TestPushingAppWithACrazyName(t *testing.T) { deps := getPushDependencies() sharedDomain := cf.Domain{} sharedDomain.Name = "foo.cf-app.com" sharedDomain.Shared = true sharedDomain.Guid = "foo-domain-guid" deps.domainRepo.ListSharedDomainsDomains = []cf.Domain{sharedDomain} deps.routeRepo.FindByHostAndDomainErr = true deps.appRepo.ReadNotFound = true ui := callPush(t, []string{"-t", "111", "Tim's 1st-Crazy__app!"}, deps) assert.Equal(t, deps.appRepo.CreatedAppParams().Get("name"), "Tim's 1st-Crazy__app!") assert.Equal(t, deps.routeRepo.FindByHostAndDomainHost, "tims-1st-crazy-app") assert.Equal(t, deps.routeRepo.CreatedHost, "tims-1st-crazy-app") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Creating", "tims-1st-crazy-app.foo.cf-app.com"}, {"Binding", "tims-1st-crazy-app.foo.cf-app.com"}, }) }