...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v1
16
17 import (
18 "strings"
19 "testing"
20
21 "github.com/google/go-cmp/cmp"
22 )
23
24 func TestGoodManifestSimple(t *testing.T) {
25 got, err := ParseManifest(strings.NewReader(`{}`))
26 if err != nil {
27 t.Errorf("Unexpected error parsing manifest: %v", err)
28 }
29
30 want := Manifest{}
31 if diff := cmp.Diff(want, *got); diff != "" {
32 t.Errorf("ParseManifest({}); (-want +got) %s", diff)
33 }
34 }
35
36 func TestGoodManifestWithHash(t *testing.T) {
37 good, err := ParseManifest(strings.NewReader(`{
38 "config": {
39 "digest": "sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
40 }
41 }`))
42 if err != nil {
43 t.Errorf("Unexpected error parsing manifest: %v", err)
44 }
45
46 if got, want := good.Config.Digest.Algorithm, "sha256"; got != want {
47 t.Errorf("ParseManifest().Config.Digest.Algorithm; got %v, want %v", got, want)
48 }
49 }
50
51 func TestManifestWithBadHash(t *testing.T) {
52 bad, err := ParseManifest(strings.NewReader(`{
53 "config": {
54 "digest": "sha256:deadbeed"
55 }
56 }`))
57 if err == nil {
58 t.Errorf("Expected error parsing manifest, but got: %v", bad)
59 }
60 }
61
62 func TestParseIndexManifest(t *testing.T) {
63 got, err := ParseIndexManifest(strings.NewReader(`{}`))
64 if err != nil {
65 t.Errorf("Unexpected error parsing manifest: %v", err)
66 }
67
68 want := IndexManifest{}
69 if diff := cmp.Diff(want, *got); diff != "" {
70 t.Errorf("ParseIndexManifest({}); (-want +got) %s", diff)
71 }
72
73 if got, err := ParseIndexManifest(strings.NewReader("{")); err == nil {
74 t.Errorf("expected error, got: %v", got)
75 }
76 }
77
View as plain text