github.com/quay/claircore@v1.5.28/datastore/postgres/digest_test.go (about)

     1  package postgres
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  
     9  	"github.com/quay/claircore"
    10  )
    11  
    12  func TestDigestEncode(t *testing.T) {
    13  	var ds digestSlice = []claircore.Digest{
    14  		claircore.MustParseDigest(`sha256:` + strings.Repeat(`a`, 64)),
    15  		claircore.MustParseDigest(`sha256:` + strings.Repeat(`b`, 64)),
    16  		claircore.MustParseDigest(`sha256:` + strings.Repeat(`c`, 64)),
    17  		claircore.MustParseDigest(`sha256:` + strings.Repeat(`d`, 64)),
    18  		claircore.MustParseDigest(`sha256:` + strings.Repeat(`e`, 64)),
    19  		claircore.MustParseDigest(`sha256:` + strings.Repeat(`f`, 64)),
    20  	}
    21  	want := `{"sha256:` + strings.Repeat(`a`, 64) +
    22  		`","sha256:` + strings.Repeat(`b`, 64) +
    23  		`","sha256:` + strings.Repeat(`c`, 64) +
    24  		`","sha256:` + strings.Repeat(`d`, 64) +
    25  		`","sha256:` + strings.Repeat(`e`, 64) +
    26  		`","sha256:` + strings.Repeat(`f`, 64) +
    27  		`"}`
    28  	got, err := ds.EncodeText(nil, nil)
    29  	if err != nil {
    30  		t.Error(err)
    31  	}
    32  	if got, want := got, []byte(want); !cmp.Equal(got, want) {
    33  		t.Error(cmp.Diff(got, want))
    34  	}
    35  }