From d4016223d551eb79bb7468b3abc726552912601a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 10 Jul 2021 00:49:36 -0400 Subject: [PATCH] tests: add tests for build-dir --- tests/apps/python/sub-app/Procfile | 2 ++ tests/apps/python/sub-app/null | 0 tests/apps/python/sub-app/release.py | 10 +++++++ tests/apps/python/sub-app/web.py | 23 ++++++++++++++++ tests/unit/builder.bats | 39 ++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 tests/apps/python/sub-app/Procfile create mode 100644 tests/apps/python/sub-app/null create mode 100644 tests/apps/python/sub-app/release.py create mode 100644 tests/apps/python/sub-app/web.py diff --git a/tests/apps/python/sub-app/Procfile b/tests/apps/python/sub-app/Procfile new file mode 100644 index 000000000..bb1e3346a --- /dev/null +++ b/tests/apps/python/sub-app/Procfile @@ -0,0 +1,2 @@ +web: python3 web.py +release: python3 release.py diff --git a/tests/apps/python/sub-app/null b/tests/apps/python/sub-app/null new file mode 100644 index 000000000..e69de29bb diff --git a/tests/apps/python/sub-app/release.py b/tests/apps/python/sub-app/release.py new file mode 100644 index 000000000..0fc4d2495 --- /dev/null +++ b/tests/apps/python/sub-app/release.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os + + +def main(): + print("SECRET_KEYS: {0}".format(os.getenv('SECRET_KEY'))) + + +if __name__ == '__main__': + main() diff --git a/tests/apps/python/sub-app/web.py b/tests/apps/python/sub-app/web.py new file mode 100644 index 000000000..c7c3d36a3 --- /dev/null +++ b/tests/apps/python/sub-app/web.py @@ -0,0 +1,23 @@ +import http.server +import json +import os + + +class GetHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(200) + self.send_header("Content-Type", "text/plain; charset=utf-8") + self.end_headers() + + if self.path == '/': + self.wfile.write("python/http.server".encode("utf-8")) + else: + data = json.dumps(dict(os.environ), sort_keys=True, indent=4) + self.wfile.write(data.encode("utf-8")) + + +if __name__ == "__main__": + port = int(os.getenv("PORT", 5000)) + server = http.server.HTTPServer(("0.0.0.0", port), GetHandler) + print("Listening on port {0}".format(port)) + server.serve_forever() diff --git a/tests/unit/builder.bats b/tests/unit/builder.bats index 3ee605314..9caf52f3c 100644 --- a/tests/unit/builder.bats +++ b/tests/unit/builder.bats @@ -187,3 +187,42 @@ teardown() { assert_success assert_line 0 "herokuish" } + +@test "(builder:set)" { + run deploy_app python + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku builder:set $TEST_APP build-dir nonexistent-app" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku builder:set $TEST_APP build-dir sub-app" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'SECRET_KEYS:' + + run /bin/bash -c "dokku builder:set $TEST_APP build-dir" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'SECRET_KEY:' +}