func startAppWithInstancesAndErrors(displayApp ApplicationDisplayer, app models.Application, instances [][]models.AppInstanceFields, errorCodes []string, requirementsFactory *testreq.FakeReqFactory) (ui *testterm.FakeUI, appRepo *testapi.FakeApplicationRepository, appInstancesRepo *testapi.FakeAppInstancesRepo) { configRepo := testconfig.NewRepositoryWithDefaults() appRepo = &testapi.FakeApplicationRepository{ UpdateAppResult: app, } appRepo.ReadReturns.App = app appInstancesRepo = &testapi.FakeAppInstancesRepo{ GetInstancesResponses: instances, GetInstancesErrorCodes: errorCodes, } logRepo := &testapi.FakeLogsRepository{ TailLogMessages: []*logmessage.LogMessage{ testlogs.NewLogMessage("Log Line 1", app.Guid, LogMessageTypeStaging, time.Now()), testlogs.NewLogMessage("Log Line 2", app.Guid, LogMessageTypeStaging, time.Now()), }, } args := []string{"my-app"} requirementsFactory.Application = app ui = callStart(args, configRepo, requirementsFactory, displayApp, appRepo, appInstancesRepo, logRepo) return }
requirementsFactory, logsRepo := getLogsDependencies() requirementsFactory.LoginSuccess = false callLogs([]string{"my-app"}, requirementsFactory, logsRepo) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) It("TestLogsOutputsRecentLogs", func() { app := models.Application{} app.Name = "my-app" app.Guid = "my-app-guid" currentTime := time.Now() recentLogs := []*logmessage.LogMessage{ testlogs.NewLogMessage("Log Line 1", app.Guid, "DEA", currentTime), testlogs.NewLogMessage("Log Line 2", app.Guid, "DEA", currentTime), } requirementsFactory, logsRepo := getLogsDependencies() requirementsFactory.Application = app logsRepo.RecentLogs = recentLogs ui := callLogs([]string{"--recent", "my-app"}, requirementsFactory, logsRepo) Expect(requirementsFactory.ApplicationName).To(Equal("my-app")) Expect(app.Guid).To(Equal(logsRepo.AppLoggedGuid)) testassert.SliceContains(ui.Outputs, testassert.Lines{ {"Connected, dumping recent logs for app", "my-app", "my-org", "my-space", "my-user"}, {"Log Line 1"}, {"Log Line 2"},
UpdateAppResult: defaultAppForStart, } appRepo.ReadReturns.App = defaultAppForStart appInstancesRepo := &testapi.FakeAppInstancesRepo{ GetInstancesResponses: defaultInstanceReponses, GetInstancesErrorCodes: defaultInstanceErrorCodes, } currentTime := time.Now() wrongSourceName := "DEA" correctSourceName := "STG" logRepo := &testapi.FakeLogsRepository{ TailLogMessages: []*logmessage.LogMessage{ testlogs.NewLogMessage("Log Line 1", defaultAppForStart.Guid, wrongSourceName, currentTime), testlogs.NewLogMessage("Log Line 2", defaultAppForStart.Guid, correctSourceName, currentTime), testlogs.NewLogMessage("Log Line 3", defaultAppForStart.Guid, correctSourceName, currentTime), testlogs.NewLogMessage("Log Line 4", defaultAppForStart.Guid, wrongSourceName, currentTime), }, } ui := callStart([]string{"my-app"}, testconfig.NewRepository(), requirementsFactory, displayApp, appRepo, appInstancesRepo, logRepo) testassert.SliceContains(ui.Outputs, testassert.Lines{ {"Log Line 2"}, {"Log Line 3"}, }) testassert.SliceDoesNotContain(ui.Outputs, testassert.Lines{ {"Log Line 1"}, {"Log Line 4"},