Skip to content

Commit 6580e94

Browse files
committed
Fix timestamps in unexpected node reboot test
1 parent c429b6e commit 6580e94

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

test/extended/machines/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ func (a byTime) Less(i, j int) bool {
244244
return a[i].time.Before(a[j].time)
245245
}
246246

247-
func (e *bootTimelineEntry) String() string {
248-
return fmt.Sprintf("%v - %v", e.time.String(), e.action)
247+
func (e bootTimelineEntry) String() string {
248+
return fmt.Sprintf("%v - %v", e.time.Format(time.RFC3339), e.action)
249249
}
250250

251251
func parseBootInstances(listBootsOutput string) ([]bootTimelineEntry, error) {

test/extended/machines/cluster_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package operators
22

33
import (
4+
"fmt"
45
"reflect"
56
"testing"
67
"time"
@@ -52,6 +53,50 @@ func Test_parseBootInstances(t *testing.T) {
5253
}
5354
}
5455

56+
func Test_bootTimelineEntryString(t *testing.T) {
57+
tests := []struct {
58+
name string
59+
entry bootTimelineEntry
60+
expected string
61+
}{
62+
{
63+
name: "boot entry formats time as RFC3339",
64+
entry: bootTimelineEntry{action: "Boot", time: mustTime("2026-01-20T22:20:50Z")},
65+
expected: "2026-01-20T22:20:50Z - Boot",
66+
},
67+
{
68+
name: "reboot request entry formats time as RFC3339",
69+
entry: bootTimelineEntry{action: "RebootRequest", time: mustTime("2024-03-13T10:20:01-04:00")},
70+
expected: "2024-03-13T10:20:01-04:00 - RebootRequest",
71+
},
72+
}
73+
for _, tt := range tests {
74+
t.Run(tt.name, func(t *testing.T) {
75+
result := tt.entry.String()
76+
if result != tt.expected {
77+
t.Errorf("String() = %q, want %q", result, tt.expected)
78+
}
79+
})
80+
}
81+
}
82+
83+
func Test_bootTimelineSliceFormat(t *testing.T) {
84+
// Verify that formatting a []bootTimelineEntry with %v calls String() on each element,
85+
// producing human-readable timestamps instead of raw struct output.
86+
entries := []bootTimelineEntry{
87+
{action: "Boot", time: mustTime("2026-01-20T22:20:50Z")},
88+
{action: "RebootRequest", time: mustTime("2026-01-20T22:01:27Z")},
89+
}
90+
formatted := fmt.Sprintf("%v", entries)
91+
if formatted == fmt.Sprintf("%v", []struct{ action string; time time.Time }{{action: "Boot"}, {action: "RebootRequest"}}) {
92+
t.Error("slice formatting is not using String() method")
93+
}
94+
expected := "[2026-01-20T22:20:50Z - Boot 2026-01-20T22:01:27Z - RebootRequest]"
95+
if formatted != expected {
96+
t.Errorf("formatted slice = %q, want %q", formatted, expected)
97+
}
98+
}
99+
55100
func Test_parseRebootInstances(t *testing.T) {
56101
type args struct {
57102
rebootsOutput string

0 commit comments

Comments
 (0)