github.com/quay/claircore@v1.5.28/libvuln/libvuln_test.go (about)

     1  package libvuln
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"testing"
     7  
     8  	"github.com/rs/zerolog"
     9  
    10  	"github.com/quay/claircore"
    11  	"github.com/quay/claircore/libvuln/driver"
    12  )
    13  
    14  func TestMatcherLog(t *testing.T) {
    15  	const want = `{"matchers":[{"name":"test-matcher","docs":"https://pkg.go.dev/github.com/quay/claircore/libvuln"}]}` + "\n"
    16  	var buf bytes.Buffer
    17  	log := zerolog.New(&buf)
    18  	log.Log().Array("matchers", matcherLog([]driver.Matcher{&TestMatcher{}})).Send()
    19  
    20  	got := buf.String()
    21  	t.Logf("got: %+#q", got)
    22  	if got != want {
    23  		t.Errorf("want: %+#q", want)
    24  	}
    25  }
    26  
    27  // Helper for above test
    28  type TestMatcher struct{}
    29  
    30  var _ driver.Matcher = (*TestMatcher)(nil)
    31  
    32  func (*TestMatcher) Name() string {
    33  	return "test-matcher"
    34  }
    35  
    36  func (*TestMatcher) Filter(*claircore.IndexRecord) bool {
    37  	return false
    38  }
    39  
    40  func (*TestMatcher) Query() []driver.MatchConstraint {
    41  	return nil
    42  }
    43  
    44  func (*TestMatcher) Vulnerable(context.Context, *claircore.IndexRecord, *claircore.Vulnerability) (bool, error) {
    45  	return false, nil
    46  }