Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: nathannaveen <42319948+nathannaveen@users.noreply.github.com>
  • Loading branch information
nathannaveen committed May 9, 2024
1 parent 66d27bb commit 54c8ca6
Show file tree
Hide file tree
Showing 25 changed files with 353 additions and 174 deletions.
5 changes: 5 additions & 0 deletions internal/testing/backend/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var commonOpts = cmp.Options{
cmpopts.SortSlices(lessHM),
cmpopts.SortSlices(lessPackageOrArtifact),
cmpopts.SortSlices(lessSLSAPred),
cmpopts.SortSlices(hasSlsaLess),
cmpopts.SortSlices(lessHSA),
cmpopts.SortSlices(lessIsDep),
cmpopts.SortSlices(lessIsOcc),
Expand Down Expand Up @@ -586,6 +587,10 @@ func lessSLSAPred(a, b *model.SLSAPredicate) bool {
return false
}

func hasSlsaLess(a, b *model.HasSlsa) bool {
return cmpArt(a.Subject, b.Subject) < 0
}

func lessPackageOrArtifact(a, b model.PackageOrArtifact) bool {
return cmpPackageOrArtifact(a, b) < 0
}
Expand Down
82 changes: 41 additions & 41 deletions internal/testing/backend/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,40 @@ const (

var skipMatrix = map[string]map[string]bool{
// pagination not implemented
"TestArtifacts": {arango: true, memmap: true, redis: true, tikv: true},
"TestBuilder": {arango: true, memmap: true, redis: true, tikv: true},
"TestBuilders": {arango: true, memmap: true, redis: true, tikv: true},
"TestCertifyBad": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestCertifyBads": {arango: true, memmap: true, redis: true, tikv: true},
"TestCertifyGood": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestCertifyGoods": {arango: true, memmap: true, redis: true, tikv: true},
"TestLegal": {arango: true, memmap: true, redis: true, tikv: true},
"TestLegals": {arango: true, memmap: true, redis: true, tikv: true},
"TestCertifyScorecard": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestScorecards": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestCertifyVulnerability": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestCertifyVulns": {arango: true, memmap: true, redis: true, tikv: true},
"TestHasMetadata": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestBulkHasMetadata": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestHasSBOMs": {arango: true, memmap: true, redis: true, tikv: true},
"TestHasSLSA": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestHasSLSAs": {arango: true, memmap: true, redis: true, tikv: true},
"TestHasSourceAt": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestHasSourceAts": {arango: true, memmap: true, redis: true, tikv: true},
"TestHashEqual": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestHashEquals": {arango: true, memmap: true, redis: true, tikv: true},
"TestIsDependencies": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestOccurrences": {arango: true, memmap: true, redis: true, tikv: true},
"TestLicenses": {arango: true, memmap: true, redis: true, tikv: true},
"TestLicensesBulk": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestPkgEquals": {arango: true, memmap: true, redis: true, tikv: true},
"TestPackages": {arango: true, memmap: true, redis: true, tikv: true},
"TestPointOfContact": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestPointOfContacts": {arango: true, memmap: true, redis: true, tikv: true},
"TestSources": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestVulnEquals": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestVulnMetadata": {arango: true, memmap: true, redis: true, tikv: true},
"TestIngestVulnMetadatas": {arango: true, memmap: true, redis: true, tikv: true},
"TestArtifacts": {arango: true, redis: true, tikv: true},
"TestBuilder": {arango: true, redis: true, tikv: true},
"TestBuilders": {arango: true, redis: true, tikv: true},
"TestCertifyBad": {arango: true, redis: true, tikv: true},
"TestIngestCertifyBads": {arango: true, redis: true, tikv: true},
"TestCertifyGood": {arango: true, redis: true, tikv: true},
"TestIngestCertifyGoods": {arango: true, redis: true, tikv: true},
"TestLegal": {arango: true, redis: true, tikv: true},
"TestLegals": {arango: true, redis: true, tikv: true},
"TestCertifyScorecard": {arango: true, redis: true, tikv: true},
"TestIngestScorecards": {arango: true, redis: true, tikv: true},
"TestIngestCertifyVulnerability": {arango: true, redis: true, tikv: true},
"TestIngestCertifyVulns": {arango: true, redis: true, tikv: true},
"TestHasMetadata": {arango: true, redis: true, tikv: true},
"TestIngestBulkHasMetadata": {arango: true, redis: true, tikv: true},
"TestIngestHasSBOMs": {arango: true, redis: true, tikv: true},
"TestHasSLSA": {arango: true, redis: true, tikv: true},
"TestIngestHasSLSAs": {arango: true, redis: true, tikv: true},
"TestHasSourceAt": {arango: true, redis: true, tikv: true},
"TestIngestHasSourceAts": {arango: true, redis: true, tikv: true},
"TestHashEqual": {arango: true, redis: true, tikv: true},
"TestIngestHashEquals": {arango: true, redis: true, tikv: true},
"TestIsDependencies": {arango: true, redis: true, tikv: true},
"TestIngestOccurrences": {arango: true, redis: true, tikv: true},
"TestLicenses": {arango: true, redis: true, tikv: true},
"TestLicensesBulk": {arango: true, redis: true, tikv: true},
"TestIngestPkgEquals": {arango: true, redis: true, tikv: true},
"TestPackages": {arango: true, redis: true, tikv: true},
"TestPointOfContact": {arango: true, redis: true, tikv: true},
"TestIngestPointOfContacts": {arango: true, redis: true, tikv: true},
"TestSources": {arango: true, redis: true, tikv: true},
"TestIngestVulnEquals": {arango: true, redis: true, tikv: true},
"TestIngestVulnMetadata": {arango: true, redis: true, tikv: true},
"TestIngestVulnMetadatas": {arango: true, redis: true, tikv: true},

// arango fails IncludedOccurrences_-_Valid_Included_ID and IncludedDependencies_-_Valid_Included_ID
"TestHasSBOM": {arango: true},
Expand All @@ -87,11 +87,11 @@ var skipMatrix = map[string]map[string]bool{
"TestPkgEqual": {arango: true, memmap: true, redis: true, tikv: true},
// keyvalue: Query_on_OSV_and_novuln_(return_nothing_as_not_valid) fails
// arango: errors when ID is not found
"TestVulnEqual": {memmap: true, redis: true, tikv: true, arango: true},
"TestVulnEqual": {redis: true, memmap: true, tikv: true, arango: true},
// arango: errors when ID is not found
"TestVulnerability": {arango: true},
"TestVulnerability": {arango: true, redis: true, tikv: true},
// redis order issues
"TestVEX": {arango: true, redis: true},
"TestVEX": {arango: true, redis: true, tikv: true},
// redis order issues
"TestVEXBulkIngest": {arango: true, redis: true},
"TestFindSoftware": {redis: true, arango: true},
Expand All @@ -105,11 +105,11 @@ type backend interface {
}

var testBackends = map[string]backend{
// memmap: newMemMap(),
memmap: newMemMap(),
arango: newArango(),
// redis: newRedis(),
ent: newEnt(),
// tikv: newTikv(),
redis: newRedis(),
ent: newEnt(),
tikv: newTikv(),
}

var currentBackend string
Expand Down
26 changes: 15 additions & 11 deletions pkg/assembler/backends/keyvalue/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,28 @@ func (c *demoClient) ArtifactsList(ctx context.Context, artifactSpec model.Artif
continue
}

if convArt == nil {
continue
}

artEdge := createArtifactEdges(algorithm, a, digest, convArt)

if artEdge == nil {
continue
}

if first != nil {
if currentPage && count < *first {
artEdge := createArtifactEdges(algorithm, a, digest, convArt)
if artEdge != nil {
edges = append(edges, artEdge)
count++
}
edges = append(edges, artEdge)
count++
}
// If there are any elements left after the current page we indicate that in the response
if count == *first && i < len(artKeys) {
hasNextPage = true
}
} else {
artEdge := createArtifactEdges(algorithm, a, digest, convArt)
if artEdge != nil {
edges = append(edges, artEdge)
count++
}
edges = append(edges, artEdge)
count++
}
}
}
Expand All @@ -319,7 +323,7 @@ func (c *demoClient) ArtifactsList(ctx context.Context, artifactSpec model.Artif
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[count-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(count-1, 0)].Node.ID),
},
Edges: edges}, nil
} else {
Expand Down
7 changes: 6 additions & 1 deletion pkg/assembler/backends/keyvalue/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ func (c *demoClient) BuildersList(ctx context.Context, builderSpec model.Builder
return nil, err
}
convBuild := c.convBuilder(b)

if convBuild == nil {
continue
}

if after != nil && !currentPage {
if convBuild.ID == *after {
currentPage = true
Expand Down Expand Up @@ -201,7 +206,7 @@ func (c *demoClient) BuildersList(ctx context.Context, builderSpec model.Builder
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[count-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(0, count-1)].Node.ID),
},
Edges: edges}, nil
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/assembler/backends/keyvalue/certifyBad.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ func (c *demoClient) CertifyBadList(ctx context.Context, certifyBadSpec model.Ce
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}

if cbOut == nil {
continue
}

if after != nil && !currentPage {
if cbOut.ID == *after {
totalCount = len(cbKeys) - (i + 1)
Expand All @@ -312,7 +316,7 @@ func (c *demoClient) CertifyBadList(ctx context.Context, certifyBadSpec model.Ce
}

if first != nil {
if numNodes < *first {
if numNodes < *first && currentPage {
edges = append(edges, &model.CertifyBadEdge{
Cursor: cbOut.ID,
Node: cbOut,
Expand All @@ -337,7 +341,7 @@ func (c *demoClient) CertifyBadList(ctx context.Context, certifyBadSpec model.Ce
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(0, numNodes-1)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/assembler/backends/keyvalue/certifyGood.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ func (c *demoClient) CertifyGoodList(ctx context.Context, certifyGoodSpec model.
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}

if cgOut == nil {
continue
}

if after != nil && !currentPage {
if cgOut.ID == *after {
totalCount = len(cgKeys) - (i + 1)
Expand Down Expand Up @@ -337,7 +341,7 @@ func (c *demoClient) CertifyGoodList(ctx context.Context, certifyGoodSpec model.
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(0, numNodes-1)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/assembler/backends/keyvalue/certifyLegal.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ func (c *demoClient) CertifyLegalList(ctx context.Context, certifyLegalSpec mode
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}

if legal == nil {
continue
}

if after != nil && !currentPage {
if legal.ID == *after {
totalCount = len(clKeys) - (i + 1)
Expand Down Expand Up @@ -422,7 +426,7 @@ func (c *demoClient) CertifyLegalList(ctx context.Context, certifyLegalSpec mode
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(numNodes-1, 0)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/assembler/backends/keyvalue/certifyScorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (c *demoClient) ScorecardsList(ctx context.Context, scorecardSpec model.Cer
}

if scorecardOut == nil {
return nil, fmt.Errorf("the scorecard link doesn't match the specification")
continue
}

if after != nil && !currentPage {
Expand Down Expand Up @@ -289,7 +289,7 @@ func (c *demoClient) ScorecardsList(ctx context.Context, scorecardSpec model.Cer
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(numNodes-1, 0)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
9 changes: 8 additions & 1 deletion pkg/assembler/backends/keyvalue/certifyVEXStatement.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ func (c *demoClient) CertifyVEXStatementList(ctx context.Context, certifyVEXStat
if err != nil {
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}
if vex == nil {
continue
}

edges = append(edges, &model.VEXEdge{
Cursor: vex.ID,
Expand Down Expand Up @@ -314,6 +317,10 @@ func (c *demoClient) CertifyVEXStatementList(ctx context.Context, certifyVEXStat
return nil, gqlerror.Errorf("%vex :: %vex", funcName, err)
}

if vex == nil {
continue
}

if after != nil && !currentPage {
if vex.ID == *after {
totalCount = len(keys) - (i + 1)
Expand Down Expand Up @@ -348,7 +355,7 @@ func (c *demoClient) CertifyVEXStatementList(ctx context.Context, certifyVEXStat
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(numNodes-1, 0)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/assembler/backends/keyvalue/certifyVuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func (c *demoClient) CertifyVulnList(ctx context.Context, certifyVulnSpec model.
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}

if cv == nil {
continue
}

if after != nil && !currentPage {
if cv.ID == *after {
totalCount = len(keys) - (i + 1)
Expand Down Expand Up @@ -317,7 +321,7 @@ func (c *demoClient) CertifyVulnList(ctx context.Context, certifyVulnSpec model.
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(numNodes-1, 0)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/assembler/backends/keyvalue/hasMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ func (c *demoClient) HasMetadataList(ctx context.Context, hasMetadataSpec model.
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}

if hm == nil {
continue
}

if after != nil && !currentPage {
if hm.ID == *after {
totalCount = len(hmKeys) - (i + 1)
Expand Down Expand Up @@ -344,7 +348,7 @@ func (c *demoClient) HasMetadataList(ctx context.Context, hasMetadataSpec model.
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(numNodes-1, 0)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/assembler/backends/keyvalue/hasSBOM.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ func (c *demoClient) HasSBOMList(ctx context.Context, hasSBOMSpec model.HasSBOMS
return nil, gqlerror.Errorf("%v :: %v", funcName, err)
}

if hs == nil {
continue
}

if after != nil && !currentPage {
if hs.ID == *after {
totalCount = len(hsKeys) - (i + 1)
Expand Down Expand Up @@ -464,7 +468,7 @@ func (c *demoClient) HasSBOMList(ctx context.Context, hasSBOMSpec model.HasSBOMS
PageInfo: &model.PageInfo{
HasNextPage: hasNextPage,
StartCursor: ptrfrom.String(edges[0].Node.ID),
EndCursor: ptrfrom.String(edges[numNodes-1].Node.ID),
EndCursor: ptrfrom.String(edges[max(numNodes-1, 0)].Node.ID),
},
Edges: edges,
}, nil
Expand Down
Loading

0 comments on commit 54c8ca6

Please sign in to comment.