github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/vulnsrc/wolfi/wolfi_test.go (about) 1 package wolfi_test 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/khulnasoft-lab/tunnel-db/pkg/types" 8 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrc/vulnerability" 9 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrc/wolfi" 10 "github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrctest" 11 ) 12 13 func TestVulnSrc_Update(t *testing.T) { 14 tests := []struct { 15 name string 16 dir string 17 wantValues []vulnsrctest.WantValues 18 wantErr string 19 }{ 20 { 21 name: "happy path", 22 dir: filepath.Join("testdata", "happy"), 23 wantValues: []vulnsrctest.WantValues{ 24 { 25 Key: []string{"data-source", "wolfi"}, 26 Value: types.DataSource{ 27 ID: vulnerability.Wolfi, 28 Name: "Wolfi Secdb", 29 URL: "https://packages.wolfi.dev/os/security.json", 30 }, 31 }, 32 { 33 Key: []string{"advisory-detail", "CVE-2022-38126", "wolfi", "binutils"}, 34 Value: types.Advisory{ 35 FixedVersion: "2.39-r1", 36 }, 37 }, 38 { 39 Key: []string{"advisory-detail", "CVE-2022-38533", "wolfi", "binutils"}, 40 Value: types.Advisory{ 41 FixedVersion: "2.39-r2", 42 }, 43 }, 44 }, 45 }, 46 { 47 name: "sad path", 48 dir: filepath.Join("testdata", "sad"), 49 wantErr: "failed to decode Wolfi advisory", 50 }, 51 } 52 for _, tt := range tests { 53 t.Run(tt.name, func(t *testing.T) { 54 vs := wolfi.NewVulnSrc() 55 vulnsrctest.TestUpdate(t, vs, vulnsrctest.TestUpdateArgs{ 56 Dir: tt.dir, 57 WantValues: tt.wantValues, 58 WantErr: tt.wantErr, 59 }) 60 }) 61 } 62 }