forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sti_env.go
77 lines (60 loc) · 2.81 KB
/
sti_env.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
package builds
import (
"fmt"
"path/filepath"
"strings"
"k8s.io/kubernetes/test/e2e"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("builds: parallel: STI build with .sti/environment file", func() {
defer g.GinkgoRecover()
var (
imageStreamFixture = exutil.FixturePath("..", "integration", "fixtures", "test-image-stream.json")
stiEnvBuildFixture = exutil.FixturePath("fixtures", "test-env-build.json")
oc = exutil.NewCLI("build-sti-env", exutil.KubeConfigPath())
)
g.JustBeforeEach(func() {
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeREST().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.Describe("Building from a template", func() {
g.It(fmt.Sprintf("should create a image from %q template and run it in a pod", stiEnvBuildFixture), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
g.By(fmt.Sprintf("calling oc create -f %q", imageStreamFixture))
err := oc.Run("create").Args("-f", imageStreamFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc create -f %q", stiEnvBuildFixture))
err = oc.Run("create").Args("-f", stiEnvBuildFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting a test build")
buildName, err := oc.Run("start-build").Args("test").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("expecting the build is in Complete phase")
err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFunc, exutil.CheckBuildFailedFunc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("getting the Docker image reference from ImageStream")
imageName, err := exutil.GetDockerImageReference(oc.REST().ImageStreams(oc.Namespace()), "test", "latest")
o.Expect(err).NotTo(o.HaveOccurred())
g.By("writing the pod defintion to a file")
outputPath := filepath.Join(exutil.TestContext.OutputDir, oc.Namespace()+"-sample-pod.json")
pod := exutil.CreatePodForImage(imageName)
err = exutil.WriteObjectToFile(pod, outputPath)
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc create -f %q", outputPath))
err = oc.Run("create").Args("-f", outputPath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("expecting the pod to be running")
err = oc.KubeFramework().WaitForPodRunning(pod.Name)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("expecting the pod container has TEST_ENV variable set")
out, err := oc.Run("exec").Args("-p", pod.Name, "--", "curl", "http://0.0.0.0:8080").Output()
o.Expect(err).NotTo(o.HaveOccurred())
if !strings.Contains(out, "success") {
e2e.Failf("Pod %q contains does not contain expected variable: %q", pod.Name, out)
}
})
})
})