-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialize_test.go
70 lines (54 loc) · 1.48 KB
/
serialize_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
59
60
61
62
63
64
65
66
67
68
69
70
package goci_test
import (
"encoding/json"
"io"
"io/ioutil"
"os"
"path"
"github.com/cloudfoundry-incubator/goci"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Saving", func() {
var tmp string
BeforeEach(func() {
var err error
tmp, err = ioutil.TempDir("", "gocitest")
Expect(err).NotTo(HaveOccurred())
bndle := &goci.Bndle{
Spec: goci.Spec{
Version: "abcd",
},
RuntimeSpec: goci.RuntimeSpec{
Mounts: map[string]goci.RuntimeSpecMount{
"foo": goci.RuntimeSpecMount{},
},
},
}
Expect(bndle.Save(tmp)).To(Succeed())
})
AfterEach(func() {
Expect(os.RemoveAll(tmp)).To(Succeed())
})
It("serializes the spec to spec.json", func() {
var configJson map[string]interface{}
Expect(json.NewDecoder(mustOpen(path.Join(tmp, "config.json"))).Decode(&configJson)).To(Succeed())
Expect(configJson).To(HaveKeyWithValue("version", Equal("abcd")))
})
It("serializes the runtime spec to runtime.json", func() {
Expect(path.Join(tmp, "runtime.json")).To(BeAnExistingFile())
var runtimeJson map[string]interface{}
Expect(json.NewDecoder(mustOpen(path.Join(tmp, "runtime.json"))).Decode(&runtimeJson)).To(Succeed())
Expect(runtimeJson).To(HaveKeyWithValue("mounts", HaveKey("foo")))
})
})
func read(path string) []byte {
b, err := ioutil.ReadAll(mustOpen(path))
Expect(err).NotTo(HaveOccurred())
return b
}
func mustOpen(path string) io.Reader {
r, err := os.Open(path)
Expect(err).NotTo(HaveOccurred())
return r
}