|
1 | 1 | package operators |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "reflect" |
5 | 6 | "testing" |
6 | 7 | "time" |
@@ -52,6 +53,50 @@ func Test_parseBootInstances(t *testing.T) { |
52 | 53 | } |
53 | 54 | } |
54 | 55 |
|
| 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 | + |
55 | 100 | func Test_parseRebootInstances(t *testing.T) { |
56 | 101 | type args struct { |
57 | 102 | rebootsOutput string |
|
0 commit comments