github.com/quay/claircore@v1.5.28/aws/matcher_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/quay/claircore"
     9  )
    10  
    11  func TestVulnerable(t *testing.T) {
    12  	m := &Matcher{}
    13  	type testcase struct {
    14  		name   string
    15  		record *claircore.IndexRecord
    16  		vuln   *claircore.Vulnerability
    17  		want   bool
    18  	}
    19  	inner := func(testcase *testcase) func(*testing.T) {
    20  		return func(t *testing.T) {
    21  			got, err := m.Vulnerable(context.Background(), testcase.record, testcase.vuln)
    22  			if err != nil {
    23  				t.Fatal(err)
    24  			}
    25  			if !cmp.Equal(got, testcase.want) {
    26  				t.Error(cmp.Diff(got, testcase.want))
    27  			}
    28  		}
    29  	}
    30  
    31  	t.Run("Unfixed", func(t *testing.T) {
    32  		testcases := []testcase{
    33  			{
    34  				name: "SameArch",
    35  				record: &claircore.IndexRecord{
    36  					Package: &claircore.Package{
    37  						Version: "10:3.1.0-8.amzn2.0.8",
    38  						Arch:    "noarch",
    39  					},
    40  				},
    41  				vuln: &claircore.Vulnerability{
    42  					Package: &claircore.Package{
    43  						Arch: "noarch",
    44  					},
    45  					FixedInVersion: "",
    46  					ArchOperation:  claircore.OpEquals,
    47  				},
    48  				want: true,
    49  			},
    50  			{
    51  				name: "DifferentArch",
    52  				record: &claircore.IndexRecord{
    53  					Package: &claircore.Package{
    54  						Version: "10:3.1.0-8.amzn2.0.8",
    55  						Arch:    "x86_64",
    56  					},
    57  				},
    58  				vuln: &claircore.Vulnerability{
    59  					Package: &claircore.Package{
    60  						Arch: "noarch",
    61  					},
    62  					FixedInVersion: "",
    63  					ArchOperation:  claircore.OpEquals,
    64  				},
    65  				want: false,
    66  			},
    67  		}
    68  		for _, testcase := range testcases {
    69  			t.Run(testcase.name, inner(&testcase))
    70  		}
    71  	})
    72  	t.Run("Fixed", func(t *testing.T) {
    73  
    74  		testcases := []testcase{
    75  			{
    76  				name: "SameArch",
    77  				record: &claircore.IndexRecord{
    78  					Package: &claircore.Package{
    79  						Version: "10:3.1.0-8.amzn2.0.8",
    80  						Arch:    "x86_64",
    81  					},
    82  				},
    83  				vuln: &claircore.Vulnerability{
    84  					Package: &claircore.Package{
    85  						Arch: "x86_64",
    86  					},
    87  					FixedInVersion: "10:3.1.0-9.amzn2.0.8",
    88  					ArchOperation:  claircore.OpEquals,
    89  				},
    90  				want: true,
    91  			},
    92  			{
    93  				name: "UnaffectedArch",
    94  				record: &claircore.IndexRecord{
    95  					Package: &claircore.Package{
    96  						Version: "10:3.1.0-8.amzn2.0.8",
    97  						Arch:    "x86_64",
    98  					},
    99  				},
   100  				vuln: &claircore.Vulnerability{
   101  					Package: &claircore.Package{
   102  						Arch: "noarch",
   103  					},
   104  					FixedInVersion: "10:3.1.0-9.amzn2.0.8",
   105  					ArchOperation:  claircore.OpEquals,
   106  				},
   107  				want: false,
   108  			},
   109  			{
   110  				name: "UnaffectedVersion",
   111  				record: &claircore.IndexRecord{
   112  					Package: &claircore.Package{
   113  						Version: "10:3.1.0-9.amzn2.0.8",
   114  						Arch:    "x86_64",
   115  					},
   116  				},
   117  				vuln: &claircore.Vulnerability{
   118  					Package: &claircore.Package{
   119  						Arch: "x86_64",
   120  					},
   121  					FixedInVersion: "9:3.1.0-9.amzn2.0.8",
   122  					ArchOperation:  claircore.OpEquals,
   123  				},
   124  				want: false,
   125  			},
   126  		}
   127  		for _, testcase := range testcases {
   128  			t.Run(testcase.name, inner(&testcase))
   129  		}
   130  	})
   131  }