The dashboard's Run read the watchdog's phase-2 report off local disk and put it on the activity stream. That is a host-local file read in the process that is moving off the host: the watchdog restarts archied and leaves its verdict beside archied, so archied is what can read it. The daemon now polls and relays it, publishing the same event through the same bus, so it persists with every other event and reaches whichever dashboard is watching. The event builder moves to releaseupdate, which owns Report and its verification; the dashboard keeps only what it needs to tell an installer where to write. The startup poll stays: the watchdog writes its result only once the process answers /healthz, so a single read at boot can always miss the report describing that very boot. persistAndBroadcastEvents takes the daemon context and detaches it for the insert, which is what it always did with context.Background() -- the last events of a run are the ones an operator reads afterwards.
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package releaseupdate
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/events"
|
|
)
|
|
|
|
// TestReportEventDistinguishesDriftFromConfirmed is the false-success
|
|
// regression the whole verification mechanism exists to catch: a passed
|
|
// health probe alone must never be worded as a confirmed version.
|
|
func TestReportEventDistinguishesDriftFromConfirmed(t *testing.T) {
|
|
report := Report{
|
|
HealthCheck: "passed",
|
|
Previous: map[string]string{ComponentDaemon: "1.0.0"},
|
|
Installed: map[string]string{ComponentDaemon: "1.1.0"},
|
|
}
|
|
|
|
drifted := ReportEvent(report, map[string]string{ComponentDaemon: "1.0.0"})
|
|
if drifted.Kind != events.KindUpdateReport {
|
|
t.Fatalf("kind = %q, want %q", drifted.Kind, events.KindUpdateReport)
|
|
}
|
|
if !strings.Contains(drifted.Detail, "did NOT take effect") {
|
|
t.Errorf("summary = %q, want it to flag drift rather than claim success", drifted.Detail)
|
|
}
|
|
if strings.Contains(drifted.Detail, "confirmed running") {
|
|
t.Errorf("summary = %q, must not claim confirmed running when drift was detected", drifted.Detail)
|
|
}
|
|
|
|
confirmed := ReportEvent(report, map[string]string{ComponentDaemon: "1.1.0"})
|
|
if !strings.Contains(confirmed.Detail, "confirmed running") {
|
|
t.Errorf("summary = %q, want it to confirm the running version", confirmed.Detail)
|
|
}
|
|
ids, _ := confirmed.Data["confirmed"].([]string)
|
|
if len(ids) != 1 || ids[0] != ComponentDaemon {
|
|
t.Errorf("confirmed = %#v, want [%q]", confirmed.Data["confirmed"], ComponentDaemon)
|
|
}
|
|
}
|
|
|
|
// TestReportEventRolledBackIsNeverWordedAsSuccess.
|
|
func TestReportEventRolledBackIsNeverWordedAsSuccess(t *testing.T) {
|
|
report := Report{
|
|
HealthCheck: "failed",
|
|
RolledBack: true,
|
|
Previous: map[string]string{ComponentDaemon: "1.0.0"},
|
|
Installed: map[string]string{ComponentDaemon: "1.1.0"},
|
|
}
|
|
|
|
e := ReportEvent(report, map[string]string{ComponentDaemon: "1.0.0"})
|
|
if !strings.Contains(e.Detail, "rolled back") {
|
|
t.Errorf("summary = %q, want it to report the rollback", e.Detail)
|
|
}
|
|
if e.Data["rolled_back"] != true {
|
|
t.Errorf("rolled_back = %v, want true", e.Data["rolled_back"])
|
|
}
|
|
}
|