diff --git a/internal/hud/renderer_test.go b/internal/hud/renderer_test.go index 7ab71843cc..96330dae98 100644 --- a/internal/hud/renderer_test.go +++ b/internal/hud/renderer_test.go @@ -414,6 +414,85 @@ func TestPodLogContainerUpdate(t *testing.T) { rtf.run("pod log for container update", 70, 20, v, vs) } +func TestCrashingPodInlineCrashLog(t *testing.T) { + rtf := newRendererTestFixture(t) + ts := time.Now().Add(-30 * time.Second) + + v := view.View{ + Resources: []view.Resource{ + { + Name: "vigoda", + PodName: "vigoda-pod", + PodStatus: "Error", + Endpoints: []string{"1.2.3.4:8080"}, + PodLog: "Something's maybe wrong idk", + CrashLog: "Definitely borken", + LastBuildLog: "Building (1/2)\nBuilding (2/2)\n", + PodUpdateStartTime: ts, + PodCreationTime: ts.Add(-time.Minute), + LastBuildStartTime: ts, + LastBuildFinishTime: ts, + LastDeployTime: ts, + LastBuildReason: model.BuildReasonFlagCrash, + }, + }, + } + vs := fakeViewState(1, view.CollapseAuto) + rtf.run("crashing pod displays crash log inline if present", 70, 20, v, vs) +} + +func TestCrashingPodInlinePodLogIfNoCrashLog(t *testing.T) { + rtf := newRendererTestFixture(t) + ts := time.Now().Add(-30 * time.Second) + + v := view.View{ + Resources: []view.Resource{ + { + Name: "vigoda", + PodName: "vigoda-pod", + PodStatus: "Error", + Endpoints: []string{"1.2.3.4:8080"}, + PodLog: "Something's maybe wrong idk", + LastBuildLog: "Building (1/2)\nBuilding (2/2)\n", + PodUpdateStartTime: ts, + PodCreationTime: ts.Add(-time.Minute), + LastBuildStartTime: ts, + LastBuildFinishTime: ts, + LastDeployTime: ts, + LastBuildReason: model.BuildReasonFlagCrash, + }, + }, + } + vs := fakeViewState(1, view.CollapseAuto) + rtf.run("crashing pod displays pod log inline if no crash log if present", 70, 20, v, vs) +} + +func TestNonCrashingPodNoInlineCrashLog(t *testing.T) { + rtf := newRendererTestFixture(t) + ts := time.Now().Add(-30 * time.Second) + + v := view.View{ + Resources: []view.Resource{ + { + Name: "vigoda", + PodName: "vigoda-pod", + PodStatus: "Running", + Endpoints: []string{"1.2.3.4:8080"}, + PodLog: "Something's maybe wrong idk", + CrashLog: "Definitely borken", + LastBuildLog: "Building (1/2)\nBuilding (2/2)\n", + PodUpdateStartTime: ts, + PodCreationTime: ts.Add(-time.Minute), + LastBuildStartTime: ts, + LastBuildFinishTime: ts, + LastDeployTime: ts, + }, + }, + } + vs := fakeViewState(1, view.CollapseAuto) + rtf.run("non-crashing pod displays no logs inline even if crash log if present", 70, 20, v, vs) +} + type rendererTestFixture struct { t *testing.T i rty.InteractiveTester diff --git a/internal/hud/resourceview.go b/internal/hud/resourceview.go index 1d871f1a82..952e576570 100644 --- a/internal/hud/resourceview.go +++ b/internal/hud/resourceview.go @@ -246,9 +246,9 @@ func (v *ResourceView) resourceExpandedK8sError() (rty.Component, bool) { pane := rty.NewConcatLayout(rty.DirVert) ok := false if isCrashing(v.res) { - podLog := v.res.PodLog + podLog := v.res.CrashLog if podLog == "" { - podLog = v.res.CrashLog + podLog = v.res.PodLog } abbrevLog := abbreviateLog(podLog) for _, logLine := range abbrevLog { diff --git a/internal/hud/testdata/crashing pod displays crash log inline if present.gob b/internal/hud/testdata/crashing pod displays crash log inline if present.gob new file mode 100644 index 0000000000..908b8b5052 Binary files /dev/null and b/internal/hud/testdata/crashing pod displays crash log inline if present.gob differ diff --git a/internal/hud/testdata/crashing pod displays pod log inline if no crash log if present.gob b/internal/hud/testdata/crashing pod displays pod log inline if no crash log if present.gob new file mode 100644 index 0000000000..c7d389b6a6 Binary files /dev/null and b/internal/hud/testdata/crashing pod displays pod log inline if no crash log if present.gob differ diff --git a/internal/hud/testdata/non-crashing pod displays no logs inline even if crash log if present.gob b/internal/hud/testdata/non-crashing pod displays no logs inline even if crash log if present.gob new file mode 100644 index 0000000000..503b9e977d Binary files /dev/null and b/internal/hud/testdata/non-crashing pod displays no logs inline even if crash log if present.gob differ