forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.go
79 lines (65 loc) · 3.15 KB
/
hooks.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
package builds
import (
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("[Feature:Builds][Slow] testing build configuration hooks", func() {
defer g.GinkgoRecover()
var (
buildFixture = exutil.FixturePath("testdata", "test-build-postcommit.json")
oc = exutil.NewCLI("cli-test-hooks", exutil.KubeConfigPath())
)
g.JustBeforeEach(func() {
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
oc.Run("create").Args("-f", buildFixture).Execute()
g.By("waiting for istag to initialize")
exutil.WaitForAnImageStreamTag(oc, oc.Namespace(), "busybox", "1")
})
g.Describe("testing postCommit hook", func() {
g.It("successful postCommit script with args", func() {
err := oc.Run("patch").Args("bc/busybox", "-p", `{"spec":{"postCommit":{"script":"echo hello $1","args":["world"],"command":null}}}`).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
br, _ := exutil.StartBuildAndWait(oc, "busybox")
br.AssertSuccess()
o.Expect(br.Logs()).To(o.ContainSubstring("hello world"))
})
g.It("successful postCommit explicit command", func() {
err := oc.Run("patch").Args("bc/busybox", "-p", `{"spec":{"postCommit":{"command":["sh","-c"],"args":["echo explicit command"],"script":""}}}`).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
br, _ := exutil.StartBuildAndWait(oc, "busybox")
br.AssertSuccess()
o.Expect(br.Logs()).To(o.ContainSubstring("explicit command"))
})
g.It("successful postCommit default entrypoint", func() {
err := oc.Run("patch").Args("bc/busybox", "-p", `{"spec":{"postCommit":{"args":["echo","default entrypoint"],"command":null,"script":""}}}`).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
br, _ := exutil.StartBuildAndWait(oc, "busybox")
br.AssertSuccess()
o.Expect(br.Logs()).To(o.ContainSubstring("default entrypoint"))
})
g.It("failing postCommit script", func() {
err := oc.Run("patch").Args("bc/busybox", "-p", `{"spec":{"postCommit":{"script":"echo about to fail && false","command":null}}}`).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
br, _ := exutil.StartBuildAndWait(oc, "busybox")
br.AssertFailure()
o.Expect(br.Logs()).To(o.ContainSubstring("about to fail"))
})
g.It("failing postCommit explicit command", func() {
err := oc.Run("patch").Args("bc/busybox", "-p", `{"spec":{"postCommit":{"command":["sh","-c"],"args":["echo about to fail && false"],"script":""}}}`).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
br, _ := exutil.StartBuildAndWait(oc, "busybox")
br.AssertFailure()
o.Expect(br.Logs()).To(o.ContainSubstring("about to fail"))
})
g.It("failing postCommit default entrypoint", func() {
err := oc.Run("patch").Args("bc/busybox", "-p", `{"spec":{"postCommit":{"args":["sh","-c","echo about to fail && false"],"command":null,"script":""}}}`).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
br, _ := exutil.StartBuildAndWait(oc, "busybox")
br.AssertFailure()
o.Expect(br.Logs()).To(o.ContainSubstring("about to fail"))
})
})
})