Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rekor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SafSec
rekor
Commits
98632922
Unverified
Commit
98632922
authored
3 years ago
by
dlorenc
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Some more cleanups in the rekord type and tests. (#557)
Signed-off-by:
Dan Lorenc
<
lorenc.d@gmail.com
>
parent
5c809080
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/types/rekord/v0.0.1/entry.go
+5
-9
5 additions, 9 deletions
pkg/types/rekord/v0.0.1/entry.go
pkg/types/rekord/v0.0.1/entry_test.go
+6
-16
6 additions, 16 deletions
pkg/types/rekord/v0.0.1/entry_test.go
with
11 additions
and
25 deletions
pkg/types/rekord/v0.0.1/entry.go
+
5
−
9
View file @
98632922
...
...
@@ -104,7 +104,7 @@ func (v *V001Entry) Unmarshal(pe models.ProposedEntry) error {
}
func
(
v
V001Entry
)
H
asExternalEntities
()
bool
{
func
(
v
*
V001Entry
)
h
asExternalEntities
()
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
.
F
etchExternalEntities
(
ctx
);
err
!=
nil
{
if
err
:=
v
.
f
etchExternalEntities
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -431,8 +427,8 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
return
nil
,
err
}
if
re
.
H
asExternalEntities
()
{
if
err
:=
re
.
F
etchExternalEntities
(
ctx
);
err
!=
nil
{
if
re
.
h
asExternalEntities
()
{
if
err
:=
re
.
f
etchExternalEntities
(
ctx
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error retrieving external entities: %v"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/types/rekord/v0.0.1/entry_test.go
+
6
−
16
View file @
98632922
...
...
@@ -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
.
H
asExternalEntities
()
!=
tc
.
hasExtEntities
{
if
tc
.
entry
.
h
asExternalEntities
()
!=
tc
.
hasExtEntities
{
t
.
Errorf
(
"unexpected result from HasExternalEntities for '%v'"
,
tc
.
caseDesc
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment