-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsection_test.go
More file actions
59 lines (54 loc) · 1.46 KB
/
section_test.go
File metadata and controls
59 lines (54 loc) · 1.46 KB
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
package yamlpack
import (
"io"
"strings"
"testing"
"github.com/lithammer/dedent"
. "github.com/smartystreets/goconvey/convey"
)
func TestSection(t *testing.T) {
Convey("sections from reader", t, func() {
yp := New()
err := yp.Import("file1", sectionData())
So(err, ShouldBeNil)
Convey("Can export generate *Sections", func() {
sections := yp.AllSections()
So(sections, ShouldHaveLength, 2)
Convey("can read exported sections", func() {
sectionNumber := sections[0].GetString("SectionNumber")
So(sectionNumber, ShouldEqual, "1")
})
Convey("exported sections have File name", func() {
So(sections[0].File, ShouldEqual, "file1")
})
})
})
Convey("sections from file", t, func() {
yp := New()
err := yp.ImportFile("testdata/filenameTest.yaml")
So(err, ShouldBeNil)
Convey("Can export generate *Sections", func() {
sections := yp.AllSections()
So(sections, ShouldHaveLength, 1)
Convey("exported sections have File name", func() {
So(sections[0].File, ShouldEqual, "testdata/filenameTest.yaml")
})
Convey("section can export subsection", func() {
subSection, err := sections[0].Sub("subField")
So(err, ShouldBeNil)
So(subSection, ShouldNotBeNil)
Convey("sub sections have File", func() {
So(subSection.File, ShouldEqual, "testdata/filenameTest.yaml")
})
})
})
})
}
func sectionData() io.Reader {
return strings.NewReader(dedent.Dedent(`
---
SectionNumber: 1
---
SectionNumber: 2
`))
}