-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalogSerial_test.go
58 lines (54 loc) · 1.33 KB
/
catalogSerial_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package api
import (
"bytes"
"testing"
"github.com/polydawn/refmt"
"github.com/polydawn/refmt/json"
. "github.com/warpfork/go-wish"
)
func TestLineageSerialization(t *testing.T) {
atl := Atlas_Catalog
t.Run("examplary lineage should roundtrip", func(t *testing.T) {
obj := Lineage{
Name: "froob.org/base",
Releases: []Release{
{
Name: "v1",
Items: map[ItemName]WareID{"linux-amd64": WareID{"tar", "6q7G4hWr"}},
Metadata: map[string]string{"optional": "foobaring"},
Hazards: map[string]string{"facemelting": "true"},
},
},
}
canon := Dedent(`
{
"name": "froob.org/base",
"releases": [
{
"name": "v1",
"items": {
"linux-amd64": "tar:6q7G4hWr"
},
"metadata": {
"optional": "foobaring"
},
"hazards": {
"facemelting": "true"
}
}
]
}
`)
t.Run("marshal", func(t *testing.T) {
bs, err := refmt.MarshalAtlased(json.EncodeOptions{Line: []byte{'\n'}, Indent: []byte{'\t'}}, obj, atl)
Wish(t, err, ShouldEqual, nil)
Wish(t, string(bs), ShouldEqual, canon)
})
t.Run("unmarshal", func(t *testing.T) {
targ := Lineage{}
err := refmt.UnmarshalAtlased(json.DecodeOptions{}, bytes.NewBufferString(canon).Bytes(), &targ, atl)
Wish(t, err, ShouldEqual, nil)
Wish(t, targ, ShouldEqual, obj)
})
})
}