Luigit
repositories / bugabinga.net

bugabinga.net

personal infrastructure for bugabinga!

owned by admin

services/luci/internal/web/steps_test.go

Raw
package web

import (
	"strings"
	"testing"
)

func TestParseStepsPairsStartAndEnd(t *testing.T) {
	log := "[luci] step 1/3: rustup target add wasm32-wasip2\n" +
		"downloading\n" +
		"[luci] step 1/3 done in 17s\n" +
		"[luci] step 2/3: cargo test\n" +
		"[luci] step 2/3 failed after 728s\n" +
		"[luci] step 3/3: never reached\n"
	steps := ParseSteps(log)
	if len(steps) != 3 {
		t.Fatalf("steps=%#v", steps)
	}
	if steps[0].Command != "rustup target add wasm32-wasip2" || steps[0].Seconds != 17 || !steps[0].Done || steps[0].Failed {
		t.Fatalf("first=%#v", steps[0])
	}
	if !steps[1].Done || !steps[1].Failed || steps[1].Seconds != 728 {
		t.Fatalf("second=%#v", steps[1])
	}
	if steps[2].Done {
		t.Fatalf("third=%#v", steps[2])
	}
}

func TestHighlightLogMarksStructureAndEscapes(t *testing.T) {
	out := string(HighlightLog("[luci] step 1/2 done in 3s\n   Compiling foo\nerror: <bad>&stuff\nnormal line\n"))
	for _, want := range []string{
		`<span class="log-mark">[luci] step 1/2 done in 3s</span>`,
		`<span class="log-dim">   Compiling foo</span>`,
		`<span class="log-fail">error: &lt;bad&gt;&amp;stuff</span>`,
		"normal line",
	} {
		if !strings.Contains(out, want) {
			t.Fatalf("missing %q in %s", want, out)
		}
	}
}

func TestParseStepsToleratesMarkerLookalikes(t *testing.T) {
	log := "[luci] step 1/2: echo \"step 9/9 done in 5s\"\n" +
		"[luci] step 1/2 done in 1s\n"
	steps := ParseSteps(log)
	if len(steps) != 1 {
		t.Fatalf("steps=%#v", steps)
	}
	if steps[0].Command != `echo "step 9/9 done in 5s"` || !steps[0].Done || steps[0].Seconds != 1 {
		t.Fatalf("step=%#v", steps[0])
	}
}