2026-04-01 02:07:09 -03:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestBuildStageHeartbeatProgresses(t *testing.T) {
|
|
|
|
|
p1, m1 := buildStageHeartbeat("titan-13", "titan-04", 10*time.Second)
|
|
|
|
|
p2, m2 := buildStageHeartbeat("titan-13", "titan-04", 3*time.Minute)
|
|
|
|
|
p3, m3 := buildStageHeartbeat("titan-13", "titan-04", 11*time.Minute)
|
|
|
|
|
|
|
|
|
|
if !(p1 > 8 && p1 < p2 && p2 < p3 && p3 <= 76) {
|
|
|
|
|
t.Fatalf("unexpected build progress values: %v %v %v", p1, p2, p3)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(m1, "Scheduling") {
|
|
|
|
|
t.Fatalf("expected scheduling message, got %q", m1)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(m2, "replacement image filesystem") {
|
|
|
|
|
t.Fatalf("expected filesystem message, got %q", m2)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(m3, "Harbor") {
|
|
|
|
|
t.Fatalf("expected Harbor message, got %q", m3)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFlashStageHeartbeatProgresses(t *testing.T) {
|
|
|
|
|
p1, m1 := flashStageHeartbeat("titan-22", "registry.bstein.dev/metis/titan-13:latest", 5*time.Second)
|
|
|
|
|
p2, m2 := flashStageHeartbeat("titan-22", "registry.bstein.dev/metis/titan-13:latest", 20*time.Second)
|
|
|
|
|
p3, m3 := flashStageHeartbeat("titan-22", "registry.bstein.dev/metis/titan-13:latest", 90*time.Second)
|
|
|
|
|
|
|
|
|
|
if !(p1 > 84 && p1 < p2 && p2 < p3 && p3 <= 98) {
|
|
|
|
|
t.Fatalf("unexpected flash progress values: %v %v %v", p1, p2, p3)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(m1, "Pulling") {
|
|
|
|
|
t.Fatalf("expected pulling message, got %q", m1)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(m2, "Writing") {
|
|
|
|
|
t.Fatalf("expected writing message, got %q", m2)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(m3, "Flushing") {
|
|
|
|
|
t.Fatalf("expected flushing message, got %q", m3)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 22:29:19 -03:00
|
|
|
|
|
|
|
|
func TestParseRemoteProgressLogsFindsLatestMarker(t *testing.T) {
|
|
|
|
|
logs := strings.Join([]string{
|
|
|
|
|
"plain log line",
|
|
|
|
|
ProgressLogLine(RemoteProgressUpdate{Stage: "build", ProgressPct: 40, Message: "phase one"}),
|
|
|
|
|
ProgressLogLine(RemoteProgressUpdate{Stage: "build", ProgressPct: 72, Message: "phase two"}),
|
|
|
|
|
`{"local_path":"/tmp/out.img.xz"}`,
|
|
|
|
|
}, "\n")
|
|
|
|
|
update, ok := parseRemoteProgressLogs(logs)
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("expected progress marker")
|
|
|
|
|
}
|
|
|
|
|
if update.ProgressPct != 72 || update.Message != "phase two" {
|
|
|
|
|
t.Fatalf("unexpected update: %#v", update)
|
|
|
|
|
}
|
|
|
|
|
}
|