From ca5a1d419d01b7fea71279c6a0232d15d40e048a Mon Sep 17 00:00:00 2001 From: Sashwat K Date: Tue, 14 May 2024 19:34:18 +0530 Subject: [PATCH] chore: update schema verification function --- common/general/general.go | 18 ++++++++++++++---- common/general/general_test.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/common/general/general.go b/common/general/general.go index be39339..2ff9ccb 100644 --- a/common/general/general.go +++ b/common/general/general.go @@ -357,9 +357,19 @@ func VerifyContractWithSchema(contract string) (bool, error) { return false, fmt.Errorf("failed to validate contract - %v", err) } - for _, err := range report.Errors() { - fmt.Printf("- %s\n", err) - } + result := report.Valid() + + if result { + return true, nil + } else { + var consolidatedErrors strings.Builder + for i, err := range report.Errors() { + if i > 0 { + consolidatedErrors.WriteString(", ") + } + consolidatedErrors.WriteString(err.String()) + } - return report.Valid(), nil + return report.Valid(), fmt.Errorf("validation failed - %s", consolidatedErrors.String()) + } } diff --git a/common/general/general_test.go b/common/general/general_test.go index 9a8664f..73d6315 100644 --- a/common/general/general_test.go +++ b/common/general/general_test.go @@ -269,5 +269,5 @@ func TestVerifyContractWithSchema(t *testing.T) { t.Errorf("schema verification failed - %v", err) } - fmt.Println(result) + assert.True(t, result) }