Skip to content

Commit

Permalink
hud: if showing logs inline, try crashLogs first [ch1090] (#821)
Browse files Browse the repository at this point in the history
* hud: if showing logs inline, try crashLogs first [ch1090]

* unit tests
  • Loading branch information
maiamcc authored Dec 10, 2018
1 parent 5872909 commit 2d7c8ab
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
79 changes: 79 additions & 0 deletions internal/hud/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/hud/resourceview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 2d7c8ab

Please sign in to comment.