Skip to content

Commit

Permalink
Add integration test for app in module
Browse files Browse the repository at this point in the history
The example in testdata has a Procfile to show how the service can be started
when the procfile buildpack gets involved. It is currently not used as part of
the testing of this buildpack and provided for documentation purpose.
  • Loading branch information
sgaist authored and robdimsdale committed Nov 15, 2022
1 parent 06e2f8d commit 5acb33f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
40 changes: 40 additions & 0 deletions integration/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,46 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
)
})

it("builds an oci image with site-packages and module", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "module_app"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
cpythonBuildpack,
pipBuildpack,
pipInstallBuildpack,
buildpack,
).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, buildpackInfo.Buildpack.Name)),
" Assigning launch processes:",
" web (default): python",
))

container, err = docker.Container.Run.
WithTTY().
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
And(
MatchRegexp(`Python 3\.\d+\.\d+`),
ContainSubstring(`Type "help", "copyright", "credits" or "license" for more information.`),
),
)
})

it("builds an oci image with conda-environment", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "conda_app"))
Expand Down
1 change: 1 addition & 0 deletions integration/testdata/module_app/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn module.server:run
12 changes: 12 additions & 0 deletions integration/testdata/module_app/module/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello, World!'

def run():
app.run()

if __name__ == "__main__":
run()
5 changes: 5 additions & 0 deletions integration/testdata/module_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Flask==2.2.2
Jinja2==3.1.2
MarkupSafe==2.1.1
Werkzeug==2.2.2
gunicorn==20.1.0

0 comments on commit 5acb33f

Please sign in to comment.