Skip to content

Commit

Permalink
Issue 966: Updated ingestion return and rebased on current master
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Conner <kev.conner@gmail.com>
  • Loading branch information
knrc committed Oct 16, 2023
1 parent 237cfac commit 02b320c
Show file tree
Hide file tree
Showing 13 changed files with 1,069 additions and 246 deletions.
60 changes: 44 additions & 16 deletions pkg/assembler/backends/inmem/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,24 @@ func Test_Nodes(t *testing.T) {
}},
}, {
name: "hasSBOM",
inPkg: []*model.PkgInputSpec{testdata.P1},
inPkg: []*model.PkgInputSpec{testdata.P1, testdata.P2},
inArt: []*model.ArtifactInputSpec{testdata.A1},
isDepCall: &isDepCall{
P1: testdata.P1,
P2: testdata.P2,
MF: mAll,
ID: &model.IsDependencyInputSpec{},
},
isOcurCall: &isOcurCall{
PkgSrc: model.PackageOrSourceInput{
Package: testdata.P1,
},
Artifact: testdata.A1,
Occurrence: &model.IsOccurrenceInputSpec{
Justification: "test justification",
},
},
hasSBOMCall: &hasSBOMCall{

Sub: model.PackageOrArtifactInput{
Package: testdata.P1,
},
Expand All @@ -346,10 +361,14 @@ func Test_Nodes(t *testing.T) {
},
},
want: []model.Node{&model.HasSbom{
Subject: testdata.P1out,
DownloadLocation: "location two",
Subject: testdata.P1out,
DownloadLocation: "location two",
IncludedSoftware: []model.PackageOrArtifact{model.Package{ID: "4"}, model.Package{ID: "5"}, model.Artifact{ID: "6"}},
IncludedDependencies: []*model.IsDependency{{ID: "7"}},
IncludedOccurrences: []*model.IsOccurrence{{ID: "8"}},
}},
}, {

name: "hasSLSA",
inArt: []*model.ArtifactInputSpec{testdata.A1, testdata.A2},
inBld: []*model.BuilderInputSpec{testdata.B1, testdata.B2},
Expand Down Expand Up @@ -501,9 +520,12 @@ func Test_Nodes(t *testing.T) {
t.Fatalf("Could not instantiate testing backend: %v", err)
}
var nodeID string
includes := model.HasSBOMIncludesInputSpec{}
for _, p := range tt.inPkg {
if _, err := b.IngestPackage(ctx, *p); err != nil {
if pkg, err := b.IngestPackage(ctx, *p); err != nil {
t.Fatalf("Could not ingest package: %v", err)
} else {
includes.Software = append(includes.Software, pkg.Namespaces[0].Names[0].Versions[0].ID)
}
}
for _, s := range tt.inSrc {
Expand All @@ -512,8 +534,10 @@ func Test_Nodes(t *testing.T) {
}
}
for _, a := range tt.inArt {
if _, err := b.IngestArtifact(ctx, a); err != nil {
if art, err := b.IngestArtifact(ctx, a); err != nil {
t.Fatalf("Could not ingest artifact: %v", err)
} else {
includes.Software = append(includes.Software, art.ID)
}
}
for _, bld := range tt.inBld {
Expand All @@ -538,6 +562,7 @@ func Test_Nodes(t *testing.T) {
return
}
nodeID = ingestedPkg.Namespaces[0].Names[0].Versions[0].ID
includes.Software = append(includes.Software, nodeID)
}
if tt.artifactInput != nil {
ingestedArt, err := b.IngestArtifact(ctx, tt.artifactInput)
Expand Down Expand Up @@ -658,16 +683,6 @@ func Test_Nodes(t *testing.T) {
}
nodeID = found.ID
}
if tt.hasSBOMCall != nil {
found, err := b.IngestHasSbom(ctx, tt.hasSBOMCall.Sub, *tt.hasSBOMCall.HS)
if (err != nil) != tt.wantErr {
t.Fatalf("did not get expected ingest error, want: %v, got: %v", tt.wantErr, err)
}
if err != nil {
return
}
nodeID = found.ID
}
if tt.hasSlsaCall != nil {
found, err := b.IngestSLSA(ctx, *tt.hasSlsaCall.Sub, tt.hasSlsaCall.BF, *tt.hasSlsaCall.BB, *tt.hasSlsaCall.SLSA)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -697,6 +712,7 @@ func Test_Nodes(t *testing.T) {
return
}
nodeID = found.ID
includes.Dependencies = append(includes.Dependencies, nodeID)
}
if tt.isOcurCall != nil {
found, err := b.IngestOccurrence(ctx, tt.isOcurCall.PkgSrc, *tt.isOcurCall.Artifact, *tt.isOcurCall.Occurrence)
Expand All @@ -707,6 +723,18 @@ func Test_Nodes(t *testing.T) {
return
}
nodeID = found.ID
includes.Occurrences = append(includes.Occurrences, nodeID)
}
if tt.hasSBOMCall != nil {
// After isDepCall and isOcurCall so they can set up includes.
found, err := b.IngestHasSbom(ctx, tt.hasSBOMCall.Sub, *tt.hasSBOMCall.HS, includes)
if (err != nil) != tt.wantErr {
t.Fatalf("did not get expected ingest error, want: %v, got: %v", tt.wantErr, err)
}
if err != nil {
return
}
nodeID = found.ID
}
if tt.pkgEqualCall != nil {
found, err := b.IngestPkgEqual(ctx, *tt.pkgEqualCall.P1, *tt.pkgEqualCall.P2, *tt.pkgEqualCall.HE)
Expand Down
Loading

0 comments on commit 02b320c

Please sign in to comment.