diff --git a/pkg/types/rekord/v0.0.1/entry.go b/pkg/types/rekord/v0.0.1/entry.go index 5412d709593fda5759f16f7da66b58215971e8ef..e3f634ef63a53705ff7b8c8212fa8842ca04a53c 100644 --- a/pkg/types/rekord/v0.0.1/entry.go +++ b/pkg/types/rekord/v0.0.1/entry.go @@ -104,7 +104,7 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error { } -func (v V001Entry) HasExternalEntities() bool { +func (v *V001Entry) hasExternalEntities() bool { if v.RekordObj.Data != nil && v.RekordObj.Data.URL.String() != "" { return true } @@ -117,11 +117,7 @@ func (v V001Entry) HasExternalEntities() bool { return false } -func (v *V001Entry) FetchExternalEntities(ctx context.Context) error { - if err := v.validate(); err != nil { - return types.ValidationError(err) - } - +func (v *V001Entry) fetchExternalEntities(ctx context.Context) error { g, ctx := errgroup.WithContext(ctx) hashR, hashW := io.Pipe() @@ -267,7 +263,7 @@ func (v *V001Entry) FetchExternalEntities(ctx context.Context) error { } func (v *V001Entry) Canonicalize(ctx context.Context) ([]byte, error) { - if err := v.FetchExternalEntities(ctx); err != nil { + if err := v.fetchExternalEntities(ctx); err != nil { return nil, err } @@ -431,8 +427,8 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types return nil, err } - if re.HasExternalEntities() { - if err := re.FetchExternalEntities(ctx); err != nil { + if re.hasExternalEntities() { + if err := re.fetchExternalEntities(ctx); err != nil { return nil, fmt.Errorf("error retrieving external entities: %v", err) } } diff --git a/pkg/types/rekord/v0.0.1/entry_test.go b/pkg/types/rekord/v0.0.1/entry_test.go index 67258640f22103e714a52f6fd50fbf364b0e0f54..45a64999bab2c191de794cb3ef245e59cd2362fd 100644 --- a/pkg/types/rekord/v0.0.1/entry_test.go +++ b/pkg/types/rekord/v0.0.1/entry_test.go @@ -501,31 +501,21 @@ func TestCrossFieldValidation(t *testing.T) { } for _, tc := range testCases { - if err := tc.entry.validate(); (err == nil) != tc.expectUnmarshalSuccess { - t.Errorf("unexpected result in '%v': %v", tc.caseDesc, err) - } - v := &V001Entry{} r := models.Rekord{ APIVersion: swag.String(tc.entry.APIVersion()), Spec: tc.entry.RekordObj, } - unmarshalAndValidate := func() error { - if err := v.Unmarshal(&r); err != nil { - return err - } - if err := v.validate(); err != nil { - return err - } - return nil + if err := v.Unmarshal(&r); (err == nil) != tc.expectUnmarshalSuccess { + t.Fatalf("unexpected result in '%v': %v", tc.caseDesc, err) } - - if err := unmarshalAndValidate(); (err == nil) != tc.expectUnmarshalSuccess { - t.Errorf("unexpected result in '%v': %v", tc.caseDesc, err) + // No need to continue here if we didn't unmarshal + if !tc.expectUnmarshalSuccess { + continue } - if tc.entry.HasExternalEntities() != tc.hasExtEntities { + if tc.entry.hasExternalEntities() != tc.hasExtEntities { t.Errorf("unexpected result from HasExternalEntities for '%v'", tc.caseDesc) }