github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/vulnsrc/alpine/alpine_test.go (about)

     1  package alpine_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/alpine"
     9  	"github.com/khulnasoft-lab/tunnel-db/pkg/vulnsrc/vulnerability"
    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", "alpine 3.12"},
    26  					Value: types.DataSource{
    27  						ID:   vulnerability.Alpine,
    28  						Name: "Alpine Secdb",
    29  						URL:  "https://secdb.alpinelinux.org/",
    30  					},
    31  				},
    32  				{
    33  					Key: []string{"advisory-detail", "CVE-2019-14904", "alpine 3.12", "ansible"},
    34  					Value: types.Advisory{
    35  						FixedVersion: "2.9.3-r0",
    36  					},
    37  				},
    38  				{
    39  					Key: []string{"advisory-detail", "CVE-2019-14905", "alpine 3.12", "ansible"},
    40  					Value: types.Advisory{
    41  						FixedVersion: "2.9.3-r0",
    42  					},
    43  				},
    44  				{
    45  					Key: []string{"advisory-detail", "CVE-2020-1737", "alpine 3.12", "ansible"},
    46  					Value: types.Advisory{
    47  						FixedVersion: "2.9.6-r0",
    48  					},
    49  				},
    50  			},
    51  		},
    52  		{
    53  			name:    "sad path",
    54  			dir:     filepath.Join("testdata", "sad"),
    55  			wantErr: "failed to decode Alpine advisory",
    56  		},
    57  	}
    58  	for _, tt := range tests {
    59  		t.Run(tt.name, func(t *testing.T) {
    60  			vs := alpine.NewVulnSrc()
    61  			vulnsrctest.TestUpdate(t, vs, vulnsrctest.TestUpdateArgs{
    62  				Dir:        tt.dir,
    63  				WantValues: tt.wantValues,
    64  				WantErr:    tt.wantErr,
    65  			})
    66  		})
    67  	}
    68  }