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

     1  package ovalutil
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/quay/goval-parser/oval"
     7  )
     8  
     9  // TestLookup is a general test lookup function.
    10  //
    11  // The passed function can be used as an allowlist for test kinds. All known
    12  // kinds will be returned if not provided.
    13  func TestLookup(root *oval.Root, ref string, f func(kind string) bool) (oval.Test, error) {
    14  	kind, i, err := root.Tests.Lookup(ref)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  	if f != nil && !f(kind) {
    19  		return nil, fmt.Errorf("disallowed kind %q: %w", kind, errTestSkip)
    20  	}
    21  	switch kind {
    22  	case "dpkginfo_test":
    23  		return &root.Tests.DpkgInfoTests[i], nil
    24  	case "line_test":
    25  		return &root.Tests.LineTests[i], nil
    26  	case "rpminfo_test":
    27  		return &root.Tests.RPMInfoTests[i], nil
    28  	case "rpmverifyfile_test":
    29  		return &root.Tests.RPMVerifyFileTests[i], nil
    30  	case "textfilecontent54_test":
    31  		return &root.Tests.TextfileContent54Tests[i], nil
    32  	case "uname_test":
    33  		return &root.Tests.UnameTests[i], nil
    34  	case "version55_test":
    35  		return &root.Tests.Version55Tests[i], nil
    36  	}
    37  	return nil, fmt.Errorf("unknown kind: %q", kind)
    38  }