-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathcomposer_test.go
More file actions
138 lines (118 loc) · 4.28 KB
/
composer_test.go
File metadata and controls
138 lines (118 loc) · 4.28 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package integration_test
import (
"os"
"path/filepath"
"testing"
"github.com/cloudfoundry/switchblade"
"github.com/sclevine/spec"
. "github.com/cloudfoundry/switchblade/matchers"
. "github.com/onsi/gomega"
)
func testComposer(platform switchblade.Platform, fixtures string) func(*testing.T, spec.G, spec.S) {
return func(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
name string
)
it.Before(func() {
var err error
name, err = switchblade.RandomName()
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
if t.Failed() && name != "" {
t.Logf("❌ FAILED TEST - App/Container: %s", name)
t.Logf(" Platform: %s", settings.Platform)
}
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
Expect(platform.Delete.Execute(name)).To(Succeed())
}
})
context("default PHP composer app", func() {
it("builds and runs the app", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"COMPOSER_GITHUB_OAUTH_TOKEN": os.Getenv("COMPOSER_GITHUB_OAUTH_TOKEN"),
}).
Execute(name, filepath.Join(fixtures, "composer_default"))
Expect(err).NotTo(HaveOccurred())
Eventually(logs).Should(SatisfyAll(
ContainSubstring("Installing Composer dependencies"),
))
if !settings.Cached {
Eventually(logs).Should(
ContainSubstring("-----> Using custom GitHub OAuth token in $COMPOSER_GITHUB_OAUTH_TOKEN"),
)
}
Eventually(deployment).Should(Serve(
ContainSubstring("<p style='text-align: center'>Powered By Cloud Foundry Buildpacks</p>"),
))
})
})
context("Composer app with custom path", func() {
it("builds and runs the app", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"COMPOSER_PATH": "meatball/sub",
"COMPOSER_GITHUB_OAUTH_TOKEN": os.Getenv("COMPOSER_GITHUB_OAUTH_TOKEN"),
}).
Execute(name, filepath.Join(fixtures, "composer_custom_path"))
Expect(err).NotTo(HaveOccurred())
Eventually(logs).Should(SatisfyAll(
ContainSubstring("Installing Composer dependencies"),
))
})
})
context("composer app with non-existent dependency", func() {
it("fails with error", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"COMPOSER_GITHUB_OAUTH_TOKEN": os.Getenv("COMPOSER_GITHUB_OAUTH_TOKEN"),
}).
Execute(name, filepath.Join(fixtures, "composer_invalid_dependency"))
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ContainSubstring("App staging failed")))
Eventually(logs).Should(
ContainSubstring("-----> Composer command failed"),
)
})
})
if !settings.Cached {
context("deployed with invalid COMPOSER_GITHUB_OAUTH_TOKEN", func() {
it("logs warning", func() {
_, logs, err := platform.Deploy.
WithEnv(map[string]string{
"COMPOSER_GITHUB_OAUTH_TOKEN": "badtoken123123",
}).
Execute(name, filepath.Join(fixtures, "composer_default"))
Expect(err).NotTo(HaveOccurred())
Eventually(logs.String()).Should(SatisfyAll(
ContainSubstring("-----> The GitHub OAuth token supplied from $COMPOSER_GITHUB_OAUTH_TOKEN is invalid"),
))
})
})
}
context("composer app with extensions in .bp-config/php/php.ini.d", func() {
it("loads extensions during composer install and at runtime", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{
"COMPOSER_GITHUB_OAUTH_TOKEN": os.Getenv("COMPOSER_GITHUB_OAUTH_TOKEN"),
}).
Execute(name, filepath.Join(fixtures, "composer_with_extensions"))
Expect(err).NotTo(HaveOccurred())
// Check build logs first (composer phase)
Expect(logs.String()).To(SatisfyAll(
ContainSubstring("Loading user-requested extensions from .bp-config/php/php.ini.d"),
ContainSubstring("Found 1 extension(s)"),
ContainSubstring("Installing Composer dependencies"),
ContainSubstring("SUCCESS: All required extensions are loaded during composer install"),
Not(ContainSubstring("composer install failed")),
Not(ContainSubstring("ERROR")),
))
// Then wait for deployment and check runtime
Eventually(deployment).Should(Serve(ContainSubstring("apcu:</strong> ✓ LOADED")))
})
})
}
}