github.com/quay/claircore@v1.5.28/java/jar/properties_test.go (about)

     1  package jar
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"io"
     7  	"io/fs"
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/quay/zlog"
    12  )
    13  
    14  func TestParseProperties(t *testing.T) {
    15  	t.Parallel()
    16  	ctx := zlog.Test(context.Background(), t)
    17  
    18  	md := os.DirFS("testdata/properties")
    19  	fs, err := fs.ReadDir(md, ".")
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	// Tee the properties for easier diagnosing.
    24  	var buf bytes.Buffer
    25  	for _, d := range fs {
    26  		buf.Reset()
    27  		f, err := md.Open(d.Name())
    28  		if err != nil {
    29  			t.Error(err)
    30  			continue
    31  		}
    32  		tee := io.TeeReader(f, &buf)
    33  		var i Info
    34  		err = i.parseProperties(ctx, tee)
    35  		f.Close()
    36  		if err != nil {
    37  			t.Error(err)
    38  			continue
    39  		}
    40  		t.Logf("%s: %+v", d.Name(), i)
    41  		t.Logf("%s: %+q", d.Name(), buf.String())
    42  	}
    43  }