github.com/quay/claircore@v1.5.28/test/periodic/enricher_test.go (about)

     1  package periodic
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/quay/zlog"
    10  
    11  	"github.com/quay/claircore/enricher/cvss"
    12  	"github.com/quay/claircore/libvuln/driver"
    13  )
    14  
    15  func TestCVSS(t *testing.T) {
    16  	ctx := zlog.Test(context.Background(), t)
    17  	e := &cvss.Enricher{}
    18  	err := e.Configure(ctx, func(interface{}) error { return nil }, pkgClient)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	runEnricher(ctx, t, e)
    23  }
    24  
    25  func runEnricher(ctx context.Context, t *testing.T, u driver.EnrichmentUpdater) {
    26  	var rc io.ReadCloser
    27  	var nfp driver.Fingerprint
    28  	var err error
    29  	// Debounce any network hiccups.
    30  	for i := 0; i < 5; i++ {
    31  		rc, nfp, err = u.FetchEnrichment(ctx, fp)
    32  		if err == nil {
    33  			break
    34  		}
    35  		select {
    36  		case <-ctx.Done():
    37  			t.Fatal(ctx.Err())
    38  		case <-time.After((2 << i) * time.Second):
    39  		}
    40  	}
    41  	if err != nil {
    42  		t.Fatal(err)
    43  	}
    44  	t.Log(nfp)
    45  	defer func() {
    46  		if err := rc.Close(); err != nil {
    47  			t.Log(err)
    48  		}
    49  	}()
    50  
    51  	ers, err := u.ParseEnrichment(ctx, rc)
    52  	if err != nil {
    53  		t.Error(err)
    54  	}
    55  	t.Logf("reported %d records", len(ers))
    56  }