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"}, }) }
func init() { defaultAppForStart.Name = "my-app" defaultAppForStart.Guid = "my-app-guid" defaultAppForStart.InstanceCount = 2 domain := cf.DomainFields{} domain.Name = "example.com" route := cf.RouteSummary{} route.Host = "my-app" route.Domain = domain defaultAppForStart.Routes = []cf.RouteSummary{route} instance1 := cf.AppInstanceFields{} instance1.State = cf.InstanceStarting instance2 := cf.AppInstanceFields{} instance2.State = cf.InstanceStarting instance3 := cf.AppInstanceFields{} instance3.State = cf.InstanceRunning instance4 := cf.AppInstanceFields{} instance4.State = cf.InstanceStarting defaultInstanceReponses = [][]cf.AppInstanceFields{ []cf.AppInstanceFields{instance1, instance2}, []cf.AppInstanceFields{instance1, instance2}, []cf.AppInstanceFields{instance3, instance4}, } }
func TestStartApplicationWhenAppHasNoURL(t *testing.T) { t.Parallel() displayApp := &testcmd.FakeAppDisplayer{} app := defaultAppForStart app.Routes = []cf.RouteSummary{} appInstance := cf.AppInstanceFields{} appInstance.State = cf.InstanceRunning instances := [][]cf.AppInstanceFields{ []cf.AppInstanceFields{appInstance}, } errorCodes := []string{""} ui, appRepo, _, reqFactory := startAppWithInstancesAndErrors(t, displayApp, app, instances, errorCodes, defaultStartTimeout) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"my-app"}, {"OK"}, {"Started"}, }) assert.Equal(t, reqFactory.ApplicationName, "my-app") assert.Equal(t, appRepo.UpdateAppGuid, "my-app-guid") }
func TestStartApplicationWhenStartTimesOut(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.InstanceDown appInstance5 := cf.AppInstanceFields{} appInstance5.State = cf.InstanceDown appInstance6 := cf.AppInstanceFields{} appInstance6.State = cf.InstanceDown instances := [][]cf.AppInstanceFields{ []cf.AppInstanceFields{appInstance, appInstance2}, []cf.AppInstanceFields{appInstance3, appInstance4}, []cf.AppInstanceFields{appInstance5, appInstance6}, } errorCodes := []string{"500", "500", "500"} ui, _, _, _ := startAppWithInstancesAndErrors(t, displayApp, defaultAppForStart, instances, errorCodes, 0) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Starting", "my-app"}, {"OK"}, {"FAILED"}, {"Start app timeout"}, }) testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{ {"instances running"}, }) }
func TestStartApplicationWhenAppIsStillStaging(t *testing.T) { t.Parallel() displayApp := &testcmd.FakeAppDisplayer{} appInstance := cf.AppInstanceFields{} appInstance.State = cf.InstanceDown appInstance2 := cf.AppInstanceFields{} appInstance2.State = cf.InstanceStarting appInstance3 := cf.AppInstanceFields{} appInstance3.State = cf.InstanceStarting appInstance4 := cf.AppInstanceFields{} appInstance4.State = cf.InstanceStarting appInstance5 := cf.AppInstanceFields{} appInstance5.State = cf.InstanceRunning appInstance6 := cf.AppInstanceFields{} appInstance6.State = cf.InstanceRunning instances := [][]cf.AppInstanceFields{ []cf.AppInstanceFields{}, []cf.AppInstanceFields{}, []cf.AppInstanceFields{appInstance, appInstance2}, []cf.AppInstanceFields{appInstance3, appInstance4}, []cf.AppInstanceFields{appInstance5, appInstance6}, } errorCodes := []string{cf.APP_NOT_STAGED, cf.APP_NOT_STAGED, "", "", ""} ui, _, appInstancesRepo, _ := startAppWithInstancesAndErrors(t, displayApp, defaultAppForStart, instances, errorCodes, defaultStartTimeout) assert.Equal(t, appInstancesRepo.GetInstancesAppGuid, "my-app-guid") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Log Line 1"}, {"Log Line 2"}, {"0 of 2 instances running", "2 starting"}, }) }
func TestDisplayingAppSummary(t *testing.T) { reqApp := cf.Application{} reqApp.Name = "my-app" reqApp.Guid = "my-app-guid" route1 := cf.RouteSummary{} route1.Host = "my-app" domain := cf.DomainFields{} domain.Name = "example.com" route1.Domain = domain route2 := cf.RouteSummary{} route2.Host = "foo" domain2 := cf.DomainFields{} domain2.Name = "example.com" route2.Domain = domain2 appSummary := cf.AppSummary{} appSummary.State = "started" appSummary.InstanceCount = 2 appSummary.RunningInstances = 2 appSummary.Memory = 256 appSummary.RouteSummaries = []cf.RouteSummary{route1, route2} time1, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2012") assert.NoError(t, err) time2, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Apr 1 15:04:05 -0700 MST 2012") assert.NoError(t, err) appInstance := cf.AppInstanceFields{} appInstance.State = cf.InstanceRunning appInstance.Since = time1 appInstance.CpuUsage = 1.0 appInstance.DiskQuota = 1 * formatters.GIGABYTE appInstance.DiskUsage = 32 * formatters.MEGABYTE appInstance.MemQuota = 64 * formatters.MEGABYTE appInstance.MemUsage = 13 * formatters.BYTE appInstance2 := cf.AppInstanceFields{} appInstance2.State = cf.InstanceDown appInstance2.Since = time2 instances := []cf.AppInstanceFields{appInstance, appInstance2} appSummaryRepo := &testapi.FakeAppSummaryRepo{GetSummarySummary: appSummary} appInstancesRepo := &testapi.FakeAppInstancesRepo{GetInstancesResponses: [][]cf.AppInstanceFields{instances}} reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: reqApp} ui := callApp(t, []string{"my-app"}, reqFactory, appSummaryRepo, appInstancesRepo) assert.Equal(t, appSummaryRepo.GetSummaryAppGuid, "my-app-guid") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Showing health and status", "my-app"}, {"state", "started"}, {"instances", "2/2"}, {"usage", "256M x 2 instances"}, {"urls", "my-app.example.com", "foo.example.com"}, {"#0", "running", "2012-01-02 03:04:05 PM", "100.0%", "13 of 64M", "32M of 1G"}, {"#1", "down", "2012-04-01 03:04:05 PM", "0%", "0 of 0", "0 of 0"}, }) }