Skip to content
Snippets Groups Projects
Unverified Commit 98632922 authored by dlorenc's avatar dlorenc Committed by GitHub
Browse files

Some more cleanups in the rekord type and tests. (#557)


Signed-off-by: default avatarDan Lorenc <lorenc.d@gmail.com>
parent 5c809080
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
}
......
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment