Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
116 lines (95 loc) · 4.07 KB

File metadata and controls

116 lines (95 loc) · 4.07 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package hooks_test
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"github.com/cloudfoundry/python-buildpack/src/python/hooks"
"github.com/cloudfoundry/libbuildpack"
"github.com/cloudfoundry/libbuildpack/ansicleaner"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Hooks", func() {
var (
err error
buildDir string
stager *libbuildpack.Stager
hook libbuildpack.Hook
buffer *bytes.Buffer
)
BeforeEach(func() {
buildDir, err = ioutil.TempDir("", "python-buildpack.build.")
Expect(err).To(BeNil())
buffer = new(bytes.Buffer)
logger := libbuildpack.NewLogger(ansicleaner.New(buffer))
args := []string{buildDir, "", "/tmp/not-exist", "9"}
stager = libbuildpack.NewStager(args, logger, &libbuildpack.Manifest{})
hook = &hooks.AppHook{}
})
AfterEach(func() {
Expect(os.RemoveAll(buildDir)).To(Succeed())
})
Describe("BeforeCompile", func() {
Context("bin/pre_compile exists", func() {
BeforeEach(func() {
Expect(os.Mkdir(filepath.Join(buildDir, "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(buildDir, "bin", "pre_compile"), []byte("#!/usr/bin/env bash\n\necho -n jane > fred.txt\n"), 0644)).To(Succeed())
})
It("changes file to executable", func() {
Expect(hook.BeforeCompile(stager)).To(Succeed())
fileInfo, err := os.Stat(filepath.Join(buildDir, "bin", "pre_compile"))
Expect(err).ToNot(HaveOccurred())
Expect(fileInfo.Mode()).To(Equal(os.FileMode(0755)))
Expect(buffer.String()).To(ContainSubstring("Running pre_compile hook"))
})
It("runs successfully", func() {
Expect(filepath.Join(buildDir, "fred.txt")).ToNot(BeARegularFile())
Expect(hook.BeforeCompile(stager)).To(Succeed())
Expect(filepath.Join(buildDir, "fred.txt")).To(BeARegularFile())
Expect(ioutil.ReadFile(filepath.Join(buildDir, "fred.txt"))).To(Equal([]byte("jane")))
})
})
It("runs successfully when bin/pre_compile exists but has no shebang", func() {
Expect(os.Mkdir(filepath.Join(buildDir, "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(buildDir, "bin", "pre_compile"), []byte("echo 'Hello world!'"), 0644)).To(Succeed())
Expect(hook.BeforeCompile(stager)).To(Succeed())
Expect(buffer.String()).To(ContainSubstring("Hello world!"))
})
It("does nothing when bin/pre_compile does NOT exist", func() {
Expect(hook.BeforeCompile(stager)).To(Succeed())
Expect(buffer.String()).NotTo(ContainSubstring("Running pre_compile hook"))
})
})
Describe("AfterCompile", func() {
Context("bin/post_compile exists", func() {
BeforeEach(func() {
Expect(os.Mkdir(filepath.Join(buildDir, "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(buildDir, "bin", "post_compile"), []byte("#!/usr/bin/env bash\n\necho -n john > fred.txt\n"), 0644)).To(Succeed())
})
It("changes file to executable", func() {
Expect(hook.AfterCompile(stager)).To(Succeed())
fileInfo, err := os.Stat(filepath.Join(buildDir, "bin", "post_compile"))
Expect(err).ToNot(HaveOccurred())
Expect(fileInfo.Mode()).To(Equal(os.FileMode(0755)))
Expect(buffer.String()).To(ContainSubstring("Running post_compile hook"))
})
It("runs successfully", func() {
Expect(filepath.Join(buildDir, "fred.txt")).ToNot(BeARegularFile())
Expect(hook.AfterCompile(stager)).To(Succeed())
Expect(filepath.Join(buildDir, "fred.txt")).To(BeARegularFile())
Expect(ioutil.ReadFile(filepath.Join(buildDir, "fred.txt"))).To(Equal([]byte("john")))
})
})
It("runs successfully when bin/post_compile exists but has no shebang", func() {
Expect(os.Mkdir(filepath.Join(buildDir, "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(buildDir, "bin", "post_compile"), []byte("echo 'Hello world!'"), 0644)).To(Succeed())
Expect(hook.AfterCompile(stager)).To(Succeed())
Expect(buffer.String()).To(ContainSubstring("Hello world!"))
})
It("does nothing when bin/post_compile does NOT exist", func() {
Expect(hook.AfterCompile(stager)).To(Succeed())
Expect(buffer.String()).NotTo(ContainSubstring("Running post_compile hook"))
})
})
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.