1515package schema_test
1616
1717import (
18- "crypto/sha256"
19- "encoding/hex"
20- "fmt"
18+ _ "crypto/sha256"
2119 "strings"
2220 "testing"
2321
22+ "github.com/opencontainers/go-digest"
2423 "github.com/opencontainers/image-spec/schema"
2524 "github.com/opencontainers/image-spec/specs-go/v1"
2625)
@@ -46,8 +45,8 @@ func convertFormats(input string) string {
4645func TestBackwardsCompatibilityManifestList (t * testing.T ) {
4746 for i , tt := range []struct {
4847 manifestlist string
49- digest string
50- fail bool
48+ digest digest. Digest
49+ fail bool
5150 }{
5251 {
5352 digest : "sha256:219f4b61132fe9d09b0ec5c15517be2ca712e4744b0e0cc3be71295b35b2a467" ,
@@ -110,8 +109,7 @@ func TestBackwardsCompatibilityManifestList(t *testing.T) {
110109 fail : false ,
111110 },
112111 } {
113- sum := sha256 .Sum256 ([]byte (tt .manifestlist ))
114- got := fmt .Sprintf ("sha256:%s" , hex .EncodeToString (sum [:]))
112+ got := digest .FromString (tt .manifestlist )
115113 if tt .digest != got {
116114 t .Errorf ("test %d: expected digest %s but got %s" , i , tt .digest , got )
117115 }
@@ -129,7 +127,7 @@ func TestBackwardsCompatibilityManifestList(t *testing.T) {
129127func TestBackwardsCompatibilityManifest (t * testing.T ) {
130128 for i , tt := range []struct {
131129 manifest string
132- digest string
130+ digest digest. Digest
133131 fail bool
134132 }{
135133 // manifest pulled from docker hub using hash value
@@ -173,8 +171,7 @@ func TestBackwardsCompatibilityManifest(t *testing.T) {
173171 fail : false ,
174172 },
175173 } {
176- sum := sha256 .Sum256 ([]byte (tt .manifest ))
177- got := fmt .Sprintf ("sha256:%s" , hex .EncodeToString (sum [:]))
174+ got := digest .FromString (tt .manifest )
178175 if tt .digest != got {
179176 t .Errorf ("test %d: expected digest %s but got %s" , i , tt .digest , got )
180177 }
@@ -192,7 +189,7 @@ func TestBackwardsCompatibilityManifest(t *testing.T) {
192189func TestBackwardsCompatibilityConfig (t * testing.T ) {
193190 for i , tt := range []struct {
194191 config string
195- digest string
192+ digest digest. Digest
196193 fail bool
197194 }{
198195 // config pulled from docker hub blob store
@@ -213,8 +210,7 @@ func TestBackwardsCompatibilityConfig(t *testing.T) {
213210 fail : false ,
214211 },
215212 } {
216- sum := sha256 .Sum256 ([]byte (tt .config ))
217- got := fmt .Sprintf ("sha256:%s" , hex .EncodeToString (sum [:]))
213+ got := digest .FromString (tt .config )
218214 if tt .digest != got {
219215 t .Errorf ("test %d: expected digest %s but got %s" , i , tt .digest , got )
220216 }
0 commit comments