Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions internal/cmd/marketplace/apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,49 @@ func TestApplyPrintApplyOutcome(t *testing.T) {
},
},
},
{
ID: "id5",
ItemID: "item-id-5",
Done: false,
Inserted: false,
Updated: false,
ValidationErrors: []marketplace.ApplyResponseItemValidationError{
{
Message: "some validation error",
},
},
Errors: []marketplace.ApplyResponseItemValidationError{
{
Message: "some validation error in errors field",
},
},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only to be extra safe, can you add another element without both ValidationErrors and Errors array in the element?

{
ID: "id6",
ItemID: "item-id-6",
Done: true,
Inserted: true,
Updated: false,
},
},
}
found := buildOutcomeSummaryAsTables(mockOutcome)
require.Contains(t, found, "3 of 4 items have been successfully applied:")
require.Contains(t, found, "4 of 6 items have been successfully applied:")
require.Contains(t, found, "id1")
require.Contains(t, found, "item-id-1")
require.Contains(t, found, "id2")
require.Contains(t, found, "item-id-2")
require.Contains(t, found, "id3")
require.Contains(t, found, "item-id-3")
require.Contains(t, found, "1 of 4 items have not been applied due to validation errors:")
require.Contains(t, found, "id6")
require.Contains(t, found, "item-id-6")
require.Contains(t, found, "2 of 6 items have not been applied due to validation errors:")
require.Contains(t, found, "id4")
require.Contains(t, found, "item-id-4")
require.Contains(t, found, "some validation error")
require.Contains(t, found, "id5")
require.Contains(t, found, "item-id-5")
require.Contains(t, found, "some validation error in errors field")
require.Contains(t, found, "OBJECT ID")
require.Contains(t, found, "ITEM ID")
})
Expand Down
7 changes: 6 additions & 1 deletion internal/cmd/marketplace/apply/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ func buildFailureTable(items []marketplace.ApplyResponseItem) string {
headers := []string{"Object ID", "Item ID", "Validation Errors"}
columnTransform := func(item marketplace.ApplyResponseItem) []string {
var validationErrorsStr string
validationErrors := item.ValidationErrors
var validationErrors []marketplace.ApplyResponseItemValidationError
if len(item.Errors) > 0 {
validationErrors = item.Errors
} else {
validationErrors = item.ValidationErrors
}
for i, valErr := range validationErrors {
validationErrorsStr += valErr.Message
if len(validationErrors)-1 > i {
Expand Down
1 change: 1 addition & 0 deletions internal/resources/marketplace/marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ApplyResponseItem struct {
Updated bool `json:"updated"`

ValidationErrors []ApplyResponseItemValidationError `json:"validationErrors"`
Errors []ApplyResponseItemValidationError `json:"errors"`
}

type ApplyResponseItemValidationError struct {
Expand Down