Skip to content

Commit de955f3

Browse files
LiliumCandidumPaola Nicosia
andauthored
feat: read from errors field in apply items response body to display errors (#241)
Co-authored-by: Paola Nicosia <[email protected]>
1 parent ea1f0ce commit de955f3

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

internal/cmd/marketplace/apply/apply_test.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,20 +334,49 @@ func TestApplyPrintApplyOutcome(t *testing.T) {
334334
},
335335
},
336336
},
337+
{
338+
ID: "id5",
339+
ItemID: "item-id-5",
340+
Done: false,
341+
Inserted: false,
342+
Updated: false,
343+
ValidationErrors: []marketplace.ApplyResponseItemValidationError{
344+
{
345+
Message: "some validation error",
346+
},
347+
},
348+
Errors: []marketplace.ApplyResponseItemValidationError{
349+
{
350+
Message: "some validation error in errors field",
351+
},
352+
},
353+
},
354+
{
355+
ID: "id6",
356+
ItemID: "item-id-6",
357+
Done: true,
358+
Inserted: true,
359+
Updated: false,
360+
},
337361
},
338362
}
339363
found := buildOutcomeSummaryAsTables(mockOutcome)
340-
require.Contains(t, found, "3 of 4 items have been successfully applied:")
364+
require.Contains(t, found, "4 of 6 items have been successfully applied:")
341365
require.Contains(t, found, "id1")
342366
require.Contains(t, found, "item-id-1")
343367
require.Contains(t, found, "id2")
344368
require.Contains(t, found, "item-id-2")
345369
require.Contains(t, found, "id3")
346370
require.Contains(t, found, "item-id-3")
347-
require.Contains(t, found, "1 of 4 items have not been applied due to validation errors:")
371+
require.Contains(t, found, "id6")
372+
require.Contains(t, found, "item-id-6")
373+
require.Contains(t, found, "2 of 6 items have not been applied due to validation errors:")
348374
require.Contains(t, found, "id4")
349375
require.Contains(t, found, "item-id-4")
350376
require.Contains(t, found, "some validation error")
377+
require.Contains(t, found, "id5")
378+
require.Contains(t, found, "item-id-5")
379+
require.Contains(t, found, "some validation error in errors field")
351380
require.Contains(t, found, "OBJECT ID")
352381
require.Contains(t, found, "ITEM ID")
353382
})

internal/cmd/marketplace/apply/table.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ func buildFailureTable(items []marketplace.ApplyResponseItem) string {
6060
headers := []string{"Object ID", "Item ID", "Validation Errors"}
6161
columnTransform := func(item marketplace.ApplyResponseItem) []string {
6262
var validationErrorsStr string
63-
validationErrors := item.ValidationErrors
63+
var validationErrors []marketplace.ApplyResponseItemValidationError
64+
if len(item.Errors) > 0 {
65+
validationErrors = item.Errors
66+
} else {
67+
validationErrors = item.ValidationErrors
68+
}
6469
for i, valErr := range validationErrors {
6570
validationErrorsStr += valErr.Message
6671
if len(validationErrors)-1 > i {

internal/resources/marketplace/marketplace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type ApplyResponseItem struct {
4646
Updated bool `json:"updated"`
4747

4848
ValidationErrors []ApplyResponseItemValidationError `json:"validationErrors"`
49+
Errors []ApplyResponseItemValidationError `json:"errors"`
4950
}
5051

5152
type ApplyResponseItemValidationError struct {

0 commit comments

Comments
 (0)