forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s2i_ruby.go
78 lines (64 loc) · 3.09 KB
/
s2i_ruby.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
package images
import (
"fmt"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
kapi "k8s.io/kubernetes/pkg/api"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("[images][ruby] openshift ruby image", func() {
defer g.GinkgoRecover()
var (
railsTemplate = "https://raw.githubusercontent.com/openshift/rails-ex/master/openshift/templates/rails-postgresql.json"
oc = exutil.NewCLI("s2i-ruby", exutil.KubeConfigPath())
modifyCommand = []string{"sed", "-ie", `s%render :file => 'public/index.html'%%`, "app/controllers/welcome_controller.rb"}
removeCommand = []string{"rm", "-f", "public/index.html"}
dcName = "rails-postgresql-example-1"
dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName))
)
g.Describe("Rails example", func() {
g.It(fmt.Sprintf("should work with hot deploy"), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
g.By(fmt.Sprintf("calling oc new-app -f %q", railsTemplate))
err := oc.Run("new-app").Args("-f", railsTemplate).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for build to finish")
err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), dcName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for endpoint")
err = oc.KubeFramework().WaitForAnEndpoint("rails-postgresql-example")
o.Expect(err).NotTo(o.HaveOccurred())
assertPageContent := func(content string) {
_, err := exutil.WaitForPods(oc.KubeREST().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute)
o.Expect(err).NotTo(o.HaveOccurred())
result, err := CheckPageContains(oc, "rails-postgresql-example", "", content)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(result).To(o.BeTrue())
}
g.By("testing application content")
assertPageContent("Welcome to your Rails application on OpenShift")
g.By("modifying the source code with disabled hot deploy")
RunInPodContainer(oc, dcLabel, modifyCommand)
RunInPodContainer(oc, dcLabel, removeCommand)
g.By("testing application content source modification")
assertPageContent("Welcome to your Rails application on OpenShift")
pods, err := oc.KubeREST().Pods(oc.Namespace()).List(kapi.ListOptions{LabelSelector: dcLabel})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(pods.Items)).To(o.Equal(1))
g.By("turning on hot-deploy")
err = oc.Run("env").Args("rc", dcName, "RAILS_ENV=development").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
err = oc.Run("scale").Args("rc", dcName, "--replicas=0").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
err = exutil.WaitUntilPodIsGone(oc.KubeREST().Pods(oc.Namespace()), pods.Items[0].Name, 1*time.Minute)
o.Expect(err).NotTo(o.HaveOccurred())
err = oc.Run("scale").Args("rc", dcName, "--replicas=1").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("modifying the source code with enabled hot deploy")
RunInPodContainer(oc, dcLabel, modifyCommand)
RunInPodContainer(oc, dcLabel, removeCommand)
assertPageContent("Hello, Rails!")
})
})
})