forked from paketo-buildpacks/dotnet-execute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildpack_yml_parser_test.go
98 lines (79 loc) · 2.29 KB
/
buildpack_yml_parser_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package dotnetexecute_test
import (
"io/ioutil"
"os"
"testing"
dotnetexecute "github.com/paketo-buildpacks/dotnet-execute"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testBuildpackYMLParser(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
path string
parser dotnetexecute.BuildpackYMLParser
)
it.Before(func() {
file, err := ioutil.TempFile("", "buildpack.yml")
Expect(err).NotTo(HaveOccurred())
defer file.Close()
_, err = file.WriteString(`---
dotnet-build:
project-path: "src/proj1"
`)
Expect(err).NotTo(HaveOccurred())
path = file.Name()
parser = dotnetexecute.NewBuildpackYMLParser()
})
it.After(func() {
Expect(os.RemoveAll(path)).To(Succeed())
})
context("Parse", func() {
it("parses a buildpack.yml file", func() {
configData, err := parser.Parse(path)
Expect(err).NotTo(HaveOccurred())
Expect(configData.ProjectPath).To(Equal("src/proj1"))
})
})
context("ParseProjectPath", func() {
it("parses the project-path from a buildpack.yml file", func() {
projectPath, err := parser.ParseProjectPath(path)
Expect(err).NotTo(HaveOccurred())
Expect(projectPath).To(Equal("src/proj1"))
})
context("when the buildpack.yml file does not exist", func() {
it.Before(func() {
Expect(os.Remove(path)).To(Succeed())
})
it("returns an empty project-path", func() {
projectPath, err := parser.ParseProjectPath(path)
Expect(err).NotTo(HaveOccurred())
Expect(projectPath).To(BeEmpty())
})
})
})
context("failure cases", func() {
context("when the buildpack.yml file cannot be read", func() {
it.Before(func() {
Expect(os.Chmod(path, 0000)).To(Succeed())
})
it.After(func() {
Expect(os.Chmod(path, 0644)).To(Succeed())
})
it("returns an error", func() {
_, err := parser.ParseProjectPath(path)
Expect(err).To(MatchError(ContainSubstring("permission denied")))
})
})
context("when the contents of the buildpack.yml file are malformed", func() {
it.Before(func() {
err := ioutil.WriteFile(path, []byte("%%%"), 0644)
Expect(err).NotTo(HaveOccurred())
})
it("returns an error", func() {
_, err := parser.ParseProjectPath(path)
Expect(err).To(MatchError(ContainSubstring("could not find expected directive name")))
})
})
})
}