github.com/quay/claircore@v1.5.28/pkg/ovalutil/arch_test.go (about)

     1  package ovalutil
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/quay/goval-parser/oval"
     7  )
     8  
     9  // TestArchMatch tests oval architecture match
    10  func TestArchMatch(t *testing.T) {
    11  	t.Parallel()
    12  
    13  	type testcase struct {
    14  		Name         string
    15  		PkgArch      string
    16  		RequiredArch string
    17  		Operation    oval.Operation
    18  		Want         bool
    19  	}
    20  	testcases := []testcase{
    21  		{
    22  			Name:         "equal-match",
    23  			PkgArch:      "x86_64",
    24  			RequiredArch: "x86_64",
    25  			Operation:    oval.OpEquals,
    26  			Want:         true,
    27  		},
    28  		{
    29  			Name:         "equal-not-match",
    30  			PkgArch:      "x86_64",
    31  			RequiredArch: "ppc64le",
    32  			Operation:    oval.OpEquals,
    33  			Want:         false,
    34  		},
    35  		{
    36  			Name:         "pattern-match",
    37  			PkgArch:      "x86_64",
    38  			RequiredArch: "x86_64|ppc64le",
    39  			Operation:    oval.OpPatternMatch,
    40  			Want:         true,
    41  		},
    42  		{
    43  			Name:         "pattern-not-match",
    44  			PkgArch:      "x86_64",
    45  			RequiredArch: "s390x|ppc64le",
    46  			Operation:    oval.OpPatternMatch,
    47  			Want:         false,
    48  		},
    49  		{
    50  			Name:         "no-vuln-arch",
    51  			PkgArch:      "noarch",
    52  			RequiredArch: "",
    53  			Operation:    oval.OpEquals,
    54  			Want:         true,
    55  		},
    56  		{
    57  			Name:         "no-pkg-arch",
    58  			PkgArch:      "",
    59  			RequiredArch: "x86_64",
    60  			Operation:    oval.OpEquals,
    61  			Want:         false,
    62  		},
    63  	}
    64  
    65  	for _, testCase := range testcases {
    66  		t.Run(
    67  			testCase.Name,
    68  			func(t *testing.T) {
    69  				got := ArchMatch(
    70  					testCase.PkgArch,
    71  					testCase.RequiredArch,
    72  					testCase.Operation,
    73  				)
    74  				if got != testCase.Want {
    75  					t.Errorf("got: %v, want: %v", got, testCase.Want)
    76  				}
    77  			},
    78  		)
    79  	}
    80  
    81  }