| index 0cd50f49c..6c6ea9edd 100644 |
| --- a/system_namedunits_test.go |
| +++ b/system_namedunits_test.go |
| @@ -43,6 +43,17 @@ func (f *fakeNamedUnitsStore) Region() string { return f.region } |
| |
| const testIID = "i-0abc1234def567890" |
| |
| +// fixNamedUnitsClock pins show's clock for the test, so the ages it |
| +// prints do not depend on how long the test takes. |
| +func fixNamedUnitsClock(t *testing.T) time.Time { |
| + t.Helper() |
| + now := time.Date(2026, 11, 19, 9, 0, 0, 0, time.UTC) |
| + prev := namedUnitsNow |
| + namedUnitsNow = func() time.Time { return now } |
| + t.Cleanup(func() { namedUnitsNow = prev }) |
| + return now |
| +} |
| + |
| // validDeclarations passes both decoders: addr and health path set. |
| const validDeclarations = `{"schema":1,"units":[{"host":"shop.example.com","app":"shop","unit":"shop.service","addr":"127.0.0.1:8080","health":{"path":"/up"}}]}` |
| |
| @@ -130,14 +141,15 @@ func TestNamedUnitsPutPrintsPathVersionAndPickup(t *testing.T) { |
| // region and the box reads its own. Both regions are printed, and the |
| // mismatch is named, because that is the whole diagnosis. |
| func TestNamedUnitsShowNamesBothRegions(t *testing.T) { |
| + now := fixNamedUnitsClock(t) |
| store := &fakeNamedUnitsStore{region: "eu-west-1", raw: []byte(validDeclarations), version: 4} |
| open := func(context.Context, string) (hostenv.NamedUnitsStore, error) { return store, nil } |
| boxes := func(context.Context, string) ([]systemBoxRow, error) { |
| return []systemBoxRow{ |
| {Label: "other", InstanceID: "i-0fff1234def567890"}, |
| - {Label: "box-1", InstanceID: testIID, HeartbeatAt: time.Now().Add(-2 * time.Minute), NamedUnits: &status.NamedUnitsStatus{ |
| + {Label: "box-1", InstanceID: testIID, HeartbeatAt: now.Add(-2 * time.Minute), NamedUnits: &status.NamedUnitsStatus{ |
| Parameter: "/carlos/host/named-units/" + testIID, InstanceID: testIID, Region: "eu-west-2", |
| - Outcome: "not-found", At: time.Now().Add(-3 * time.Minute), |
| + Outcome: "not-found", At: now.Add(-3 * time.Minute), |
| }}, |
| }, nil |
| } |
| @@ -198,11 +210,12 @@ func TestNamedUnitsShowConsoleUnavailable(t *testing.T) { |
| // version says so with its heartbeat's age, and each unit's delivery |
| // state is listed. |
| func TestNamedUnitsShowBehindAndUnits(t *testing.T) { |
| + now := fixNamedUnitsClock(t) |
| store := &fakeNamedUnitsStore{region: "eu-west-1", raw: []byte(validDeclarations), version: 5} |
| open := func(context.Context, string) (hostenv.NamedUnitsStore, error) { return store, nil } |
| boxes := func(context.Context, string) ([]systemBoxRow, error) { |
| - return []systemBoxRow{{Label: "box-1", InstanceID: testIID, HeartbeatAt: time.Now().Add(-90 * time.Second), NamedUnits: &status.NamedUnitsStatus{ |
| - Region: "eu-west-1", Version: 4, Outcome: "installed", At: time.Now().Add(-time.Hour), |
| + return []systemBoxRow{{Label: "box-1", InstanceID: testIID, HeartbeatAt: now.Add(-90 * time.Second), NamedUnits: &status.NamedUnitsStatus{ |
| + Region: "eu-west-1", Version: 4, Outcome: "installed", At: now.Add(-time.Hour), |
| Units: []status.NamedUnitDelivery{ |
| {Host: "shop.example.com", Unit: "shop.service", State: "delivered"}, |
| {Host: "blog.example.com", Unit: "blog.service", State: "refused", Reason: "unit not loaded"}, |
| @@ -214,7 +227,7 @@ func TestNamedUnitsShowBehindAndUnits(t *testing.T) { |
| t.Fatal(err) |
| } |
| s := out.String() |
| - for _, want := range []string{"has not taken version 5", "1m30s ago", "shop.service", "delivered", "blog.service", "refused: unit not loaded"} { |
| + for _, want := range []string{"has not taken version 5", "last heartbeat was 1m30s ago", "at 2026-11-19T08:00:00Z (1h00m ago)", "shop.service", "delivered", "blog.service", "refused: unit not loaded"} { |
| if !strings.Contains(s, want) { |
| t.Errorf("output lacks %q:\n%s", want, s) |
| } |