Skip to content

Commit af79603

Browse files
committed
addressing failed UT and lint issues
1 parent 4ac25eb commit af79603

4 files changed

Lines changed: 47 additions & 38 deletions

File tree

cmd/os-image-composer/compare_cmd_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ func TestCompareCommand_JSONModes_PrettyAndCompact(t *testing.T) {
121121

122122
// Validate it looks like ImageCompareResult (at least top-level fields).
123123
var got struct {
124-
Equal bool `json:"equal"`
125-
From any `json:"from"`
126-
To any `json:"to"`
127-
Diff any `json:"diff"`
124+
SchemaVersion string `json:"schemaVersion"`
125+
Equal bool `json:"equal"`
126+
From json.RawMessage `json:"from"`
127+
To json.RawMessage `json:"to"`
128+
Summary json.RawMessage `json:"summary"`
129+
Diff json.RawMessage `json:"diff"`
128130
}
129131
decodeJSON(t, s, &got)
132+
if got.SchemaVersion == "" {
133+
t.Fatalf("expected schemaVersion to be set")
134+
}
130135
})
131136

132137
t.Run("diff compact", func(t *testing.T) {

cmd/os-image-composer/inspect_cmd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ func writeInspectionResult(cmd *cobra.Command, summary *imageinspect.ImageSummar
8383

8484
switch format {
8585
case "text":
86-
imageinspect.RenderSummaryText(out, summary, imageinspect.TextOptions{})
86+
if err := imageinspect.RenderSummaryText(out, summary, imageinspect.TextOptions{}); err != nil {
87+
return fmt.Errorf("render text: %w", err)
88+
}
8789
return nil
8890

8991
case "json":

internal/image/imageinspect/compare_normalize.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ func normalizeCompareResult(r *ImageCompareResult) {
88
ptType := r.To.PartitionTable.Type
99

1010
sort.Slice(r.Diff.Partitions.Added, func(i, j int) bool {
11-
return partitionKey(ptType, r.Diff.Partitions.Added[i]) < partitionKey(ptType, r.Diff.Partitions.Added[j])})
11+
return partitionKey(ptType, r.Diff.Partitions.Added[i]) < partitionKey(ptType, r.Diff.Partitions.Added[j])
12+
})
1213

1314
sort.Slice(r.Diff.Partitions.Removed, func(i, j int) bool {
14-
return partitionKey(ptType, r.Diff.Partitions.Removed[i]) < partitionKey(ptType, r.Diff.Partitions.Removed[j])})
15-
15+
return partitionKey(ptType, r.Diff.Partitions.Removed[i]) < partitionKey(ptType, r.Diff.Partitions.Removed[j])
16+
})
17+
1618
sort.Slice(r.Diff.Partitions.Modified, func(i, j int) bool {
1719
return r.Diff.Partitions.Modified[i].Key < r.Diff.Partitions.Modified[j].Key
1820
})

internal/image/imageinspect/compare_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func TestCompareImages_Equal_NoChanges(t *testing.T) {
1515
ProtectiveMBR: true,
1616
Partitions: []PartitionSummary{
1717
{
18-
Index: 1,
19-
Name: "ESP",
20-
Type: "efi",
18+
Index: 1,
19+
Name: "ESP",
20+
Type: "efi",
2121
StartLBA: 2048,
2222
EndLBA: 4095,
2323
SizeBytes: 1024,
@@ -34,8 +34,8 @@ func TestCompareImages_Equal_NoChanges(t *testing.T) {
3434

3535
// Deep copy-ish by constructing again (enough for this test)
3636
b := &ImageSummary{
37-
File: "a.raw",
38-
SizeBytes: 100,
37+
File: "a.raw",
38+
SizeBytes: 100,
3939
PartitionTable: a.PartitionTable,
4040
}
4141

@@ -111,9 +111,9 @@ func TestCompareImages_PartitionsAddedRemovedModified_ByFSUUIDKey(t *testing.T)
111111
LogicalSectorSize: 512,
112112
Partitions: []PartitionSummary{
113113
{
114-
Index: 1,
115-
Name: "ESP",
116-
Type: "efi",
114+
Index: 1,
115+
Name: "ESP",
116+
Type: "efi",
117117
StartLBA: 2048,
118118
EndLBA: 4095,
119119
SizeBytes: 1024,
@@ -124,9 +124,9 @@ func TestCompareImages_PartitionsAddedRemovedModified_ByFSUUIDKey(t *testing.T)
124124
},
125125
},
126126
{
127-
Index: 2,
128-
Name: "root",
129-
Type: "linux",
127+
Index: 2,
128+
Name: "root",
129+
Type: "linux",
130130
StartLBA: 4096,
131131
EndLBA: 8191,
132132
SizeBytes: 2048,
@@ -149,9 +149,9 @@ func TestCompareImages_PartitionsAddedRemovedModified_ByFSUUIDKey(t *testing.T)
149149
LogicalSectorSize: 512,
150150
Partitions: []PartitionSummary{
151151
{
152-
Index: 1,
153-
Name: "ESP",
154-
Type: "efi",
152+
Index: 1,
153+
Name: "ESP",
154+
Type: "efi",
155155
StartLBA: 2048,
156156
EndLBA: 4095,
157157
SizeBytes: 1024,
@@ -162,9 +162,9 @@ func TestCompareImages_PartitionsAddedRemovedModified_ByFSUUIDKey(t *testing.T)
162162
},
163163
},
164164
{
165-
Index: 3,
166-
Name: "data",
167-
Type: "linux",
165+
Index: 3,
166+
Name: "data",
167+
Type: "linux",
168168
StartLBA: 9000,
169169
EndLBA: 9999,
170170
SizeBytes: 4096,
@@ -213,9 +213,9 @@ func TestCompareImages_EFIBinaries_ModifiedAndUKIDiff(t *testing.T) {
213213
LogicalSectorSize: 512,
214214
Partitions: []PartitionSummary{
215215
{
216-
Index: 1,
217-
Name: "ESP",
218-
Type: "efi",
216+
Index: 1,
217+
Name: "ESP",
218+
Type: "efi",
219219
StartLBA: 2048,
220220
EndLBA: 4095,
221221
SizeBytes: 1024,
@@ -253,11 +253,11 @@ func TestCompareImages_EFIBinaries_ModifiedAndUKIDiff(t *testing.T) {
253253
File: "b.raw",
254254
SizeBytes: a.SizeBytes,
255255
PartitionTable: PartitionTableSummary{
256-
Type: a.PartitionTable.Type,
257-
LogicalSectorSize: a.PartitionTable.LogicalSectorSize,
256+
Type: a.PartitionTable.Type,
257+
LogicalSectorSize: a.PartitionTable.LogicalSectorSize,
258258
PhysicalSectorSize: a.PartitionTable.PhysicalSectorSize,
259-
ProtectiveMBR: a.PartitionTable.ProtectiveMBR,
260-
Partitions: make([]PartitionSummary, len(a.PartitionTable.Partitions)),
259+
ProtectiveMBR: a.PartitionTable.ProtectiveMBR,
260+
Partitions: make([]PartitionSummary, len(a.PartitionTable.Partitions)),
261261
},
262262
}
263263

@@ -326,9 +326,9 @@ func TestCompareImages_EFIBinaries_AddedRemoved(t *testing.T) {
326326
LogicalSectorSize: 512,
327327
Partitions: []PartitionSummary{
328328
{
329-
Index: 1,
330-
Name: "ESP",
331-
Type: "efi",
329+
Index: 1,
330+
Name: "ESP",
331+
Type: "efi",
332332
Filesystem: &FilesystemSummary{
333333
Type: "vfat",
334334
UUID: "UUID-ESP",
@@ -348,9 +348,9 @@ func TestCompareImages_EFIBinaries_AddedRemoved(t *testing.T) {
348348
LogicalSectorSize: 512,
349349
Partitions: []PartitionSummary{
350350
{
351-
Index: 1,
352-
Name: "ESP",
353-
Type: "efi",
351+
Index: 1,
352+
Name: "ESP",
353+
Type: "efi",
354354
Filesystem: &FilesystemSummary{
355355
Type: "vfat",
356356
UUID: "UUID-ESP",

0 commit comments

Comments
 (0)