From 5acb33fabac6023c7472e7159f48227776112b3c Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 15 Nov 2022 11:03:30 +0100 Subject: [PATCH] Add integration test for app in module 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. --- integration/default_test.go | 40 +++++++++++++++++++ integration/testdata/module_app/Procfile | 1 + .../testdata/module_app/module/server.py | 12 ++++++ .../testdata/module_app/requirements.txt | 5 +++ 4 files changed, 58 insertions(+) create mode 100644 integration/testdata/module_app/Procfile create mode 100644 integration/testdata/module_app/module/server.py create mode 100644 integration/testdata/module_app/requirements.txt diff --git a/integration/default_test.go b/integration/default_test.go index b94f04f..782a066 100644 --- a/integration/default_test.go +++ b/integration/default_test.go @@ -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")) diff --git a/integration/testdata/module_app/Procfile b/integration/testdata/module_app/Procfile new file mode 100644 index 0000000..e735d11 --- /dev/null +++ b/integration/testdata/module_app/Procfile @@ -0,0 +1 @@ +web: gunicorn module.server:run \ No newline at end of file diff --git a/integration/testdata/module_app/module/server.py b/integration/testdata/module_app/module/server.py new file mode 100644 index 0000000..3f1b91e --- /dev/null +++ b/integration/testdata/module_app/module/server.py @@ -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() diff --git a/integration/testdata/module_app/requirements.txt b/integration/testdata/module_app/requirements.txt new file mode 100644 index 0000000..c2221c0 --- /dev/null +++ b/integration/testdata/module_app/requirements.txt @@ -0,0 +1,5 @@ +Flask==2.2.2 +Jinja2==3.1.2 +MarkupSafe==2.1.1 +Werkzeug==2.2.2 +gunicorn==20.1.0