github.com/quay/claircore@v1.5.28/enricher/cvss/feed_test.go (about)

     1  package cvss
     2  
     3  import (
     4  	"bytes"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/quay/zlog"
     9  )
    10  
    11  func TestFeedIngest(t *testing.T) {
    12  	ctx := zlog.Test(nil, t)
    13  	in, err := os.Open("testdata/feed.json")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	defer in.Close()
    18  	f, err := newItemFeed(1970, in)
    19  	if err != nil {
    20  		t.Error(err)
    21  	}
    22  	var out bytes.Buffer
    23  	if err := f.WriteCVSS(ctx, &out); err != nil {
    24  		t.Error(err)
    25  	}
    26  	b := out.Bytes()
    27  	c := bytes.IndexByte(b, '\n')
    28  	if c == -1 {
    29  		t.Error("no lines?")
    30  	}
    31  	t.Logf("initial output:\n\t%s", string(b[:c]))
    32  	if got, want := bytes.Count(b, []byte("\n")), 218; got != want {
    33  		t.Errorf("got: %d lines, want: %d lines", got, want)
    34  	}
    35  }