Skip to content

Commit

Permalink
change hasSBOMList to add filter based on client usage (#2205)
Browse files Browse the repository at this point in the history
* change hasSBOMList to filter out deps.dev, add filter based on client usage

Signed-off-by: pxp928 <parth.psu@gmail.com>

* udpate backend tests with graphql preloads

Signed-off-by: pxp928 <parth.psu@gmail.com>

* remove filtering on deps.dev sboms

Signed-off-by: pxp928 <parth.psu@gmail.com>

* add unit test for preloads helper

Signed-off-by: pxp928 <parth.psu@gmail.com>

---------

Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 authored Oct 22, 2024
1 parent 7bebe65 commit 8e84bbe
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 202 deletions.
81 changes: 78 additions & 3 deletions internal/testing/backend/hasSBOM_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"context"
"testing"

"github.com/99designs/gqlgen/graphql"
"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/internal/testing/testdata"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/v2/ast"
)

type testDependency struct {
Expand Down Expand Up @@ -287,8 +289,81 @@ var includedTestExpectedSBOM = &model.HasSbom{

// End of Test resources

func getGraphQLPreloadCtx() context.Context {
ctx := graphql.WithOperationContext(context.Background(), &graphql.OperationContext{})
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
Field: graphql.CollectedField{
Selections: ast.SelectionSet{
&ast.Field{
Alias: "totalCount",
Name: "totalCount",
},
&ast.Field{
Alias: "edges",
Name: "edges",
SelectionSet: ast.SelectionSet{
&ast.Field{
Alias: "cursor",
Name: "cursor",
},
&ast.Field{
Alias: "node",
Name: "node",
SelectionSet: ast.SelectionSet{
&ast.Field{
Alias: "includedSoftware",
Name: "includedSoftware",
},
},
},
&ast.Field{
Alias: "node",
Name: "node",
SelectionSet: ast.SelectionSet{
&ast.Field{
Alias: "includedDependencies",
Name: "includedDependencies",
},
},
},
&ast.Field{
Alias: "node",
Name: "node",
SelectionSet: ast.SelectionSet{
&ast.Field{
Alias: "includedOccurrences",
Name: "includedOccurrences",
},
},
},
},
},
&ast.Field{
Alias: "pageInfo",
Name: "pageInfo",
SelectionSet: ast.SelectionSet{
&ast.Field{
Alias: "startCursor",
Name: "startCursor",
},
&ast.Field{
Alias: "endCursor",
Name: "endCursor",
},
&ast.Field{
Alias: "hasNextPage",
Name: "hasNextPage",
},
},
},
},
},
})
return ctx
}

func TestHasSBOM(t *testing.T) {
ctx := context.Background()
ctx := getGraphQLPreloadCtx()
b := setupTest(t)
type call struct {
Sub model.PackageOrArtifactInput
Expand Down Expand Up @@ -2780,7 +2855,7 @@ func TestHasSBOM(t *testing.T) {
}

func TestIngestHasSBOMs(t *testing.T) {
ctx := context.Background()
ctx := getGraphQLPreloadCtx()
b := setupTest(t)
type call struct {
Sub model.PackageOrArtifactInputs
Expand Down Expand Up @@ -3127,7 +3202,7 @@ func TestIngestHasSBOMs(t *testing.T) {
}

func TestDeleteHasSBOM(t *testing.T) {
ctx := context.Background()
ctx := getGraphQLPreloadCtx()
b := setupTest(t)
type call struct {
Sub model.PackageOrArtifactInputs
Expand Down
Loading

0 comments on commit 8e84bbe

Please sign in to comment.