■ ■ ■ ■ ■ ■
grype/presenter/models/models_helpers.go
| skipped 3 lines |
4 | 4 | | "regexp" |
5 | 5 | | "testing" |
6 | 6 | | |
7 | | - | "github.com/google/uuid" |
| 7 | + | "github.com/stretchr/testify/require" |
8 | 8 | | |
9 | 9 | | grypeDb "github.com/anchore/grype/grype/db/v5" |
10 | 10 | | "github.com/anchore/grype/grype/match" |
11 | 11 | | "github.com/anchore/grype/grype/pkg" |
12 | 12 | | "github.com/anchore/grype/grype/vulnerability" |
13 | 13 | | "github.com/anchore/stereoscope/pkg/image" |
| 14 | + | "github.com/anchore/syft/syft/artifact" |
14 | 15 | | "github.com/anchore/syft/syft/cpe" |
15 | 16 | | "github.com/anchore/syft/syft/linux" |
16 | 17 | | syftPkg "github.com/anchore/syft/syft/pkg" |
| skipped 112 lines |
129 | 130 | | func generatePackages(t *testing.T) []pkg.Package { |
130 | 131 | | t.Helper() |
131 | 132 | | epoch := 2 |
132 | | - | return []pkg.Package{ |
| 133 | + | |
| 134 | + | pkgs := []pkg.Package{ |
133 | 135 | | { |
134 | | - | ID: pkg.ID(uuid.NewString()), |
135 | 136 | | Name: "package-1", |
136 | 137 | | Version: "1.1.1", |
137 | 138 | | Type: syftPkg.RpmPkg, |
| skipped 19 lines |
157 | 158 | | }, |
158 | 159 | | }, |
159 | 160 | | { |
160 | | - | ID: pkg.ID(uuid.NewString()), |
161 | 161 | | Name: "package-2", |
162 | 162 | | Version: "2.2.2", |
163 | 163 | | Type: syftPkg.DebPkg, |
| skipped 10 lines |
174 | 174 | | Licenses: []string{"MIT", "Apache-2.0"}, |
175 | 175 | | }, |
176 | 176 | | } |
| 177 | + | |
| 178 | + | updatedPkgs := make([]pkg.Package, 0, len(pkgs)) |
| 179 | + | |
| 180 | + | for _, p := range pkgs { |
| 181 | + | id, err := artifact.IDByHash(p) |
| 182 | + | require.NoError(t, err) |
| 183 | + | |
| 184 | + | p.ID = pkg.ID(id) |
| 185 | + | updatedPkgs = append(updatedPkgs, p) |
| 186 | + | } |
| 187 | + | |
| 188 | + | return updatedPkgs |
177 | 189 | | } |
178 | 190 | | |
179 | 191 | | func generateContext(t *testing.T, scheme syftSource.Scheme) pkg.Context { |
| skipped 62 lines |