forked from EngineerBetter/hugo-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
82 lines (72 loc) · 1.92 KB
/
main_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
71
72
73
74
75
76
77
78
79
80
81
82
package main_test
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var (
cliPath string
args []string
session *Session
err error
)
func getPaths(dirName string) ([]string, error) {
paths := make([]string, 1)
err = filepath.Walk(dirName, func(path string, _ os.FileInfo, _ error) (errVal error) {
subPath := strings.Replace(path, dirName, "", 1)
paths = append(paths, subPath)
return errVal
})
return paths, err
}
var _ = Describe("hugo-parser", func() {
BeforeSuite(func() {
cliPath, err = Build("github.com/engineerbetter/hugo-parser")
Ω(err).ShouldNot(HaveOccurred(), "Error building source")
})
AfterSuite(func() {
CleanupBuildArtifacts()
})
JustBeforeEach(func() {
command := exec.Command(cliPath, args...)
session, err = Start(command, GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred(), "Error running CLI: "+cliPath)
})
Context("when the files exist", func() {
var dir string
var targetContents []string
BeforeEach(func() {
dir, err = ioutil.TempDir("", "example")
defer os.RemoveAll(dir)
Ω(err).ShouldNot(HaveOccurred(), "Error creating temp dir")
args = []string{"fixtures/hugo-structure.yml", "fixtures/source", dir}
targetContents, err = getPaths("fixtures/target")
Ω(err).ShouldNot(HaveOccurred(), "Error checking contents of target")
})
It("it reads the file", func() {
Eventually(session).Should(Exit(0))
result := `mappings:
- name: A
exercises:
- C
- B
- name: D
exercises:
- E`
Ω(session.Out).Should(Say(result))
actualContents, err := getPaths(dir)
Ω(err).ShouldNot(HaveOccurred(), "Error checking contents of actual")
fmt.Println(targetContents)
fmt.Println(actualContents)
Ω(reflect.DeepEqual(targetContents, actualContents)).Should(BeTrue())
})
})
})