From a9b364b6e188ac3b4b8c74b2c8caa351d71a251a Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 14 Jan 2025 15:39:32 +0100 Subject: [PATCH 1/3] Add support for container-tests written in PyTest. PyTest suite for nginx-container is present Signed-off-by: Petr "Stone" Hracek --- 1.20/test/run-pytest | 1 + 1.20/test/test_container_application.py | 1 + 1.20/test/test_container_basics.py | 1 + 1.20/test/test_container_example_app.py | 1 + 1.20/test/test_container_log.py | 1 + 1.20/test/test_nginx_imagestream_s2i.py | 1 - 1.20/test/test_nginx_imagestreams.py | 1 - 1.20/test/test_nginx_local_example.py | 1 - 1.20/test/test_nginx_remote_example.py | 1 - 1.20/test/test_ocp_imagestream_s2i.py | 1 + 1.20/test/test_ocp_imagestreams.py | 1 + 1.20/test/test_ocp_local_example.py | 1 + 1.20/test/test_ocp_remote_example.py | 1 + .../test/test_ocp_shared_helm_imagestreams.py | 1 + 1.20/test/test_ocp_shared_helm_template.py | 1 + 1.20/test/test_ocp_template_example_app.py | 1 + .../test_shared_helm_nginx_imagestreams.py | 1 - 1.20/test/test_shared_helm_nginx_template.py | 1 - 1.22/test/run-pytest | 1 + 1.22/test/test_container_application.py | 1 + 1.22/test/test_container_basics.py | 1 + 1.22/test/test_container_example_app.py | 1 + 1.22/test/test_container_log.py | 1 + 1.22/test/test_nginx_imagestream_s2i.py | 1 - 1.22/test/test_nginx_imagestreams.py | 1 - 1.22/test/test_nginx_local_example.py | 1 - 1.22/test/test_nginx_remote_example.py | 1 - 1.22/test/test_ocp_imagestream_s2i.py | 1 + 1.22/test/test_ocp_imagestreams.py | 1 + 1.22/test/test_ocp_local_example.py | 1 + 1.22/test/test_ocp_remote_example.py | 1 + .../test/test_ocp_shared_helm_imagestreams.py | 1 + 1.22/test/test_ocp_shared_helm_template.py | 1 + 1.22/test/test_ocp_template_example_app.py | 1 + .../test_shared_helm_nginx_imagestreams.py | 1 - 1.22/test/test_shared_helm_nginx_template.py | 1 - 1.24/test/run-pytest | 1 + 1.24/test/test_container_application.py | 1 + 1.24/test/test_container_basics.py | 1 + 1.24/test/test_container_example_app.py | 1 + 1.24/test/test_container_log.py | 1 + 1.24/test/test_nginx_imagestream_s2i.py | 1 - 1.24/test/test_nginx_imagestreams.py | 1 - 1.24/test/test_nginx_local_example.py | 1 - 1.24/test/test_nginx_remote_example.py | 1 - 1.24/test/test_nginx_template_example_app.py | 1 - 1.24/test/test_ocp_imagestream_s2i.py | 1 + 1.24/test/test_ocp_imagestreams.py | 1 + 1.24/test/test_ocp_local_example.py | 1 + 1.24/test/test_ocp_remote_example.py | 1 + .../test/test_ocp_shared_helm_imagestreams.py | 1 + 1.24/test/test_ocp_shared_helm_template.py | 1 + 1.24/test/test_ocp_template_example_app.py | 1 + .../test_shared_helm_nginx_imagestreams.py | 1 - 1.24/test/test_shared_helm_nginx_template.py | 1 - 1.26/test/run-pytest | 1 + 1.26/test/test_container_application.py | 1 + 1.26/test/test_container_basics.py | 1 + 1.26/test/test_container_example_app.py | 1 + 1.26/test/test_container_log.py | 1 + 1.26/test/test_nginx_imagestream_s2i.py | 1 - 1.26/test/test_nginx_imagestreams.py | 1 - 1.26/test/test_nginx_local_example.py | 1 - 1.26/test/test_nginx_remote_example.py | 1 - 1.26/test/test_nginx_template_example_app.py | 1 - 1.26/test/test_ocp_imagestream_s2i.py | 1 + 1.26/test/test_ocp_imagestreams.py | 1 + 1.26/test/test_ocp_local_example.py | 1 + 1.26/test/test_ocp_remote_example.py | 1 + .../test/test_ocp_shared_helm_imagestreams.py | 1 + 1.26/test/test_ocp_shared_helm_template.py | 1 + 1.26/test/test_ocp_template_example_app.py | 1 + .../test_shared_helm_nginx_imagestreams.py | 1 - 1.26/test/test_shared_helm_nginx_template.py | 1 - test/dockerfile_processor.py | 155 ++++++++++++++++++ test/pytest.ini | 26 +++ test/run | 3 +- test/run-openshift-pytest | 2 +- test/run-pytest | 17 ++ test/test_container_application.py | 99 +++++++++++ test/test_container_basics.py | 86 ++++++++++ test/test_container_example_app.py | 117 +++++++++++++ test/test_container_log.py | 96 +++++++++++ ...eam_s2i.py => test_ocp_imagestream_s2i.py} | 0 ...agestreams.py => test_ocp_imagestreams.py} | 0 ...l_example.py => test_ocp_local_example.py} | 0 ..._example.py => test_ocp_remote_example.py} | 0 ...y => test_ocp_shared_helm_imagestreams.py} | 0 ...te.py => test_ocp_shared_helm_template.py} | 0 ...pp.py => test_ocp_template_example_app.py} | 0 90 files changed, 646 insertions(+), 29 deletions(-) create mode 120000 1.20/test/run-pytest create mode 120000 1.20/test/test_container_application.py create mode 120000 1.20/test/test_container_basics.py create mode 120000 1.20/test/test_container_example_app.py create mode 120000 1.20/test/test_container_log.py delete mode 120000 1.20/test/test_nginx_imagestream_s2i.py delete mode 120000 1.20/test/test_nginx_imagestreams.py delete mode 120000 1.20/test/test_nginx_local_example.py delete mode 120000 1.20/test/test_nginx_remote_example.py create mode 120000 1.20/test/test_ocp_imagestream_s2i.py create mode 120000 1.20/test/test_ocp_imagestreams.py create mode 120000 1.20/test/test_ocp_local_example.py create mode 120000 1.20/test/test_ocp_remote_example.py create mode 120000 1.20/test/test_ocp_shared_helm_imagestreams.py create mode 120000 1.20/test/test_ocp_shared_helm_template.py create mode 120000 1.20/test/test_ocp_template_example_app.py delete mode 120000 1.20/test/test_shared_helm_nginx_imagestreams.py delete mode 120000 1.20/test/test_shared_helm_nginx_template.py create mode 120000 1.22/test/run-pytest create mode 120000 1.22/test/test_container_application.py create mode 120000 1.22/test/test_container_basics.py create mode 120000 1.22/test/test_container_example_app.py create mode 120000 1.22/test/test_container_log.py delete mode 120000 1.22/test/test_nginx_imagestream_s2i.py delete mode 120000 1.22/test/test_nginx_imagestreams.py delete mode 120000 1.22/test/test_nginx_local_example.py delete mode 120000 1.22/test/test_nginx_remote_example.py create mode 120000 1.22/test/test_ocp_imagestream_s2i.py create mode 120000 1.22/test/test_ocp_imagestreams.py create mode 120000 1.22/test/test_ocp_local_example.py create mode 120000 1.22/test/test_ocp_remote_example.py create mode 120000 1.22/test/test_ocp_shared_helm_imagestreams.py create mode 120000 1.22/test/test_ocp_shared_helm_template.py create mode 120000 1.22/test/test_ocp_template_example_app.py delete mode 120000 1.22/test/test_shared_helm_nginx_imagestreams.py delete mode 120000 1.22/test/test_shared_helm_nginx_template.py create mode 120000 1.24/test/run-pytest create mode 120000 1.24/test/test_container_application.py create mode 120000 1.24/test/test_container_basics.py create mode 120000 1.24/test/test_container_example_app.py create mode 120000 1.24/test/test_container_log.py delete mode 120000 1.24/test/test_nginx_imagestream_s2i.py delete mode 120000 1.24/test/test_nginx_imagestreams.py delete mode 120000 1.24/test/test_nginx_local_example.py delete mode 120000 1.24/test/test_nginx_remote_example.py delete mode 120000 1.24/test/test_nginx_template_example_app.py create mode 120000 1.24/test/test_ocp_imagestream_s2i.py create mode 120000 1.24/test/test_ocp_imagestreams.py create mode 120000 1.24/test/test_ocp_local_example.py create mode 120000 1.24/test/test_ocp_remote_example.py create mode 120000 1.24/test/test_ocp_shared_helm_imagestreams.py create mode 120000 1.24/test/test_ocp_shared_helm_template.py create mode 120000 1.24/test/test_ocp_template_example_app.py delete mode 120000 1.24/test/test_shared_helm_nginx_imagestreams.py delete mode 120000 1.24/test/test_shared_helm_nginx_template.py create mode 120000 1.26/test/run-pytest create mode 120000 1.26/test/test_container_application.py create mode 120000 1.26/test/test_container_basics.py create mode 120000 1.26/test/test_container_example_app.py create mode 120000 1.26/test/test_container_log.py delete mode 120000 1.26/test/test_nginx_imagestream_s2i.py delete mode 120000 1.26/test/test_nginx_imagestreams.py delete mode 120000 1.26/test/test_nginx_local_example.py delete mode 120000 1.26/test/test_nginx_remote_example.py delete mode 120000 1.26/test/test_nginx_template_example_app.py create mode 120000 1.26/test/test_ocp_imagestream_s2i.py create mode 120000 1.26/test/test_ocp_imagestreams.py create mode 120000 1.26/test/test_ocp_local_example.py create mode 120000 1.26/test/test_ocp_remote_example.py create mode 120000 1.26/test/test_ocp_shared_helm_imagestreams.py create mode 120000 1.26/test/test_ocp_shared_helm_template.py create mode 120000 1.26/test/test_ocp_template_example_app.py delete mode 120000 1.26/test/test_shared_helm_nginx_imagestreams.py delete mode 120000 1.26/test/test_shared_helm_nginx_template.py create mode 100644 test/dockerfile_processor.py create mode 100644 test/pytest.ini create mode 100755 test/run-pytest create mode 100644 test/test_container_application.py create mode 100644 test/test_container_basics.py create mode 100644 test/test_container_example_app.py create mode 100644 test/test_container_log.py rename test/{test_nginx_imagestream_s2i.py => test_ocp_imagestream_s2i.py} (100%) rename test/{test_nginx_imagestreams.py => test_ocp_imagestreams.py} (100%) rename test/{test_nginx_local_example.py => test_ocp_local_example.py} (100%) rename test/{test_nginx_remote_example.py => test_ocp_remote_example.py} (100%) rename test/{test_shared_helm_nginx_imagestreams.py => test_ocp_shared_helm_imagestreams.py} (100%) rename test/{test_shared_helm_nginx_template.py => test_ocp_shared_helm_template.py} (100%) rename test/{test_nginx_template_example_app.py => test_ocp_template_example_app.py} (100%) diff --git a/1.20/test/run-pytest b/1.20/test/run-pytest new file mode 120000 index 00000000..efe32b48 --- /dev/null +++ b/1.20/test/run-pytest @@ -0,0 +1 @@ +../../test/run-pytest \ No newline at end of file diff --git a/1.20/test/test_container_application.py b/1.20/test/test_container_application.py new file mode 120000 index 00000000..25c1c1ec --- /dev/null +++ b/1.20/test/test_container_application.py @@ -0,0 +1 @@ +../../test/test_container_application.py \ No newline at end of file diff --git a/1.20/test/test_container_basics.py b/1.20/test/test_container_basics.py new file mode 120000 index 00000000..b85dc139 --- /dev/null +++ b/1.20/test/test_container_basics.py @@ -0,0 +1 @@ +../../test/test_container_basics.py \ No newline at end of file diff --git a/1.20/test/test_container_example_app.py b/1.20/test/test_container_example_app.py new file mode 120000 index 00000000..ac4bde53 --- /dev/null +++ b/1.20/test/test_container_example_app.py @@ -0,0 +1 @@ +../../test/test_container_example_app.py \ No newline at end of file diff --git a/1.20/test/test_container_log.py b/1.20/test/test_container_log.py new file mode 120000 index 00000000..7f43a30a --- /dev/null +++ b/1.20/test/test_container_log.py @@ -0,0 +1 @@ +../../test/test_container_log.py \ No newline at end of file diff --git a/1.20/test/test_nginx_imagestream_s2i.py b/1.20/test/test_nginx_imagestream_s2i.py deleted file mode 120000 index 724bb1b6..00000000 --- a/1.20/test/test_nginx_imagestream_s2i.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestream_s2i.py \ No newline at end of file diff --git a/1.20/test/test_nginx_imagestreams.py b/1.20/test/test_nginx_imagestreams.py deleted file mode 120000 index d53a5d99..00000000 --- a/1.20/test/test_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestreams.py \ No newline at end of file diff --git a/1.20/test/test_nginx_local_example.py b/1.20/test/test_nginx_local_example.py deleted file mode 120000 index 7c07f8a6..00000000 --- a/1.20/test/test_nginx_local_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_local_example.py \ No newline at end of file diff --git a/1.20/test/test_nginx_remote_example.py b/1.20/test/test_nginx_remote_example.py deleted file mode 120000 index 82e280f2..00000000 --- a/1.20/test/test_nginx_remote_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_remote_example.py \ No newline at end of file diff --git a/1.20/test/test_ocp_imagestream_s2i.py b/1.20/test/test_ocp_imagestream_s2i.py new file mode 120000 index 00000000..89eb6791 --- /dev/null +++ b/1.20/test/test_ocp_imagestream_s2i.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestream_s2i.py \ No newline at end of file diff --git a/1.20/test/test_ocp_imagestreams.py b/1.20/test/test_ocp_imagestreams.py new file mode 120000 index 00000000..ee905e77 --- /dev/null +++ b/1.20/test/test_ocp_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestreams.py \ No newline at end of file diff --git a/1.20/test/test_ocp_local_example.py b/1.20/test/test_ocp_local_example.py new file mode 120000 index 00000000..f2f3e849 --- /dev/null +++ b/1.20/test/test_ocp_local_example.py @@ -0,0 +1 @@ +../../test/test_ocp_local_example.py \ No newline at end of file diff --git a/1.20/test/test_ocp_remote_example.py b/1.20/test/test_ocp_remote_example.py new file mode 120000 index 00000000..7a912c02 --- /dev/null +++ b/1.20/test/test_ocp_remote_example.py @@ -0,0 +1 @@ +../../test/test_ocp_remote_example.py \ No newline at end of file diff --git a/1.20/test/test_ocp_shared_helm_imagestreams.py b/1.20/test/test_ocp_shared_helm_imagestreams.py new file mode 120000 index 00000000..76d5701d --- /dev/null +++ b/1.20/test/test_ocp_shared_helm_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_imagestreams.py \ No newline at end of file diff --git a/1.20/test/test_ocp_shared_helm_template.py b/1.20/test/test_ocp_shared_helm_template.py new file mode 120000 index 00000000..9cf469bf --- /dev/null +++ b/1.20/test/test_ocp_shared_helm_template.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_template.py \ No newline at end of file diff --git a/1.20/test/test_ocp_template_example_app.py b/1.20/test/test_ocp_template_example_app.py new file mode 120000 index 00000000..49e607f8 --- /dev/null +++ b/1.20/test/test_ocp_template_example_app.py @@ -0,0 +1 @@ +../../test/test_ocp_template_example_app.py \ No newline at end of file diff --git a/1.20/test/test_shared_helm_nginx_imagestreams.py b/1.20/test/test_shared_helm_nginx_imagestreams.py deleted file mode 120000 index 6363402b..00000000 --- a/1.20/test/test_shared_helm_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_imagestreams.py \ No newline at end of file diff --git a/1.20/test/test_shared_helm_nginx_template.py b/1.20/test/test_shared_helm_nginx_template.py deleted file mode 120000 index 01f3b3df..00000000 --- a/1.20/test/test_shared_helm_nginx_template.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_template.py \ No newline at end of file diff --git a/1.22/test/run-pytest b/1.22/test/run-pytest new file mode 120000 index 00000000..efe32b48 --- /dev/null +++ b/1.22/test/run-pytest @@ -0,0 +1 @@ +../../test/run-pytest \ No newline at end of file diff --git a/1.22/test/test_container_application.py b/1.22/test/test_container_application.py new file mode 120000 index 00000000..25c1c1ec --- /dev/null +++ b/1.22/test/test_container_application.py @@ -0,0 +1 @@ +../../test/test_container_application.py \ No newline at end of file diff --git a/1.22/test/test_container_basics.py b/1.22/test/test_container_basics.py new file mode 120000 index 00000000..b85dc139 --- /dev/null +++ b/1.22/test/test_container_basics.py @@ -0,0 +1 @@ +../../test/test_container_basics.py \ No newline at end of file diff --git a/1.22/test/test_container_example_app.py b/1.22/test/test_container_example_app.py new file mode 120000 index 00000000..ac4bde53 --- /dev/null +++ b/1.22/test/test_container_example_app.py @@ -0,0 +1 @@ +../../test/test_container_example_app.py \ No newline at end of file diff --git a/1.22/test/test_container_log.py b/1.22/test/test_container_log.py new file mode 120000 index 00000000..7f43a30a --- /dev/null +++ b/1.22/test/test_container_log.py @@ -0,0 +1 @@ +../../test/test_container_log.py \ No newline at end of file diff --git a/1.22/test/test_nginx_imagestream_s2i.py b/1.22/test/test_nginx_imagestream_s2i.py deleted file mode 120000 index 724bb1b6..00000000 --- a/1.22/test/test_nginx_imagestream_s2i.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestream_s2i.py \ No newline at end of file diff --git a/1.22/test/test_nginx_imagestreams.py b/1.22/test/test_nginx_imagestreams.py deleted file mode 120000 index d53a5d99..00000000 --- a/1.22/test/test_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestreams.py \ No newline at end of file diff --git a/1.22/test/test_nginx_local_example.py b/1.22/test/test_nginx_local_example.py deleted file mode 120000 index 7c07f8a6..00000000 --- a/1.22/test/test_nginx_local_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_local_example.py \ No newline at end of file diff --git a/1.22/test/test_nginx_remote_example.py b/1.22/test/test_nginx_remote_example.py deleted file mode 120000 index 82e280f2..00000000 --- a/1.22/test/test_nginx_remote_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_remote_example.py \ No newline at end of file diff --git a/1.22/test/test_ocp_imagestream_s2i.py b/1.22/test/test_ocp_imagestream_s2i.py new file mode 120000 index 00000000..89eb6791 --- /dev/null +++ b/1.22/test/test_ocp_imagestream_s2i.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestream_s2i.py \ No newline at end of file diff --git a/1.22/test/test_ocp_imagestreams.py b/1.22/test/test_ocp_imagestreams.py new file mode 120000 index 00000000..ee905e77 --- /dev/null +++ b/1.22/test/test_ocp_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestreams.py \ No newline at end of file diff --git a/1.22/test/test_ocp_local_example.py b/1.22/test/test_ocp_local_example.py new file mode 120000 index 00000000..f2f3e849 --- /dev/null +++ b/1.22/test/test_ocp_local_example.py @@ -0,0 +1 @@ +../../test/test_ocp_local_example.py \ No newline at end of file diff --git a/1.22/test/test_ocp_remote_example.py b/1.22/test/test_ocp_remote_example.py new file mode 120000 index 00000000..7a912c02 --- /dev/null +++ b/1.22/test/test_ocp_remote_example.py @@ -0,0 +1 @@ +../../test/test_ocp_remote_example.py \ No newline at end of file diff --git a/1.22/test/test_ocp_shared_helm_imagestreams.py b/1.22/test/test_ocp_shared_helm_imagestreams.py new file mode 120000 index 00000000..76d5701d --- /dev/null +++ b/1.22/test/test_ocp_shared_helm_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_imagestreams.py \ No newline at end of file diff --git a/1.22/test/test_ocp_shared_helm_template.py b/1.22/test/test_ocp_shared_helm_template.py new file mode 120000 index 00000000..9cf469bf --- /dev/null +++ b/1.22/test/test_ocp_shared_helm_template.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_template.py \ No newline at end of file diff --git a/1.22/test/test_ocp_template_example_app.py b/1.22/test/test_ocp_template_example_app.py new file mode 120000 index 00000000..49e607f8 --- /dev/null +++ b/1.22/test/test_ocp_template_example_app.py @@ -0,0 +1 @@ +../../test/test_ocp_template_example_app.py \ No newline at end of file diff --git a/1.22/test/test_shared_helm_nginx_imagestreams.py b/1.22/test/test_shared_helm_nginx_imagestreams.py deleted file mode 120000 index 6363402b..00000000 --- a/1.22/test/test_shared_helm_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_imagestreams.py \ No newline at end of file diff --git a/1.22/test/test_shared_helm_nginx_template.py b/1.22/test/test_shared_helm_nginx_template.py deleted file mode 120000 index 01f3b3df..00000000 --- a/1.22/test/test_shared_helm_nginx_template.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_template.py \ No newline at end of file diff --git a/1.24/test/run-pytest b/1.24/test/run-pytest new file mode 120000 index 00000000..efe32b48 --- /dev/null +++ b/1.24/test/run-pytest @@ -0,0 +1 @@ +../../test/run-pytest \ No newline at end of file diff --git a/1.24/test/test_container_application.py b/1.24/test/test_container_application.py new file mode 120000 index 00000000..25c1c1ec --- /dev/null +++ b/1.24/test/test_container_application.py @@ -0,0 +1 @@ +../../test/test_container_application.py \ No newline at end of file diff --git a/1.24/test/test_container_basics.py b/1.24/test/test_container_basics.py new file mode 120000 index 00000000..b85dc139 --- /dev/null +++ b/1.24/test/test_container_basics.py @@ -0,0 +1 @@ +../../test/test_container_basics.py \ No newline at end of file diff --git a/1.24/test/test_container_example_app.py b/1.24/test/test_container_example_app.py new file mode 120000 index 00000000..ac4bde53 --- /dev/null +++ b/1.24/test/test_container_example_app.py @@ -0,0 +1 @@ +../../test/test_container_example_app.py \ No newline at end of file diff --git a/1.24/test/test_container_log.py b/1.24/test/test_container_log.py new file mode 120000 index 00000000..7f43a30a --- /dev/null +++ b/1.24/test/test_container_log.py @@ -0,0 +1 @@ +../../test/test_container_log.py \ No newline at end of file diff --git a/1.24/test/test_nginx_imagestream_s2i.py b/1.24/test/test_nginx_imagestream_s2i.py deleted file mode 120000 index 724bb1b6..00000000 --- a/1.24/test/test_nginx_imagestream_s2i.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestream_s2i.py \ No newline at end of file diff --git a/1.24/test/test_nginx_imagestreams.py b/1.24/test/test_nginx_imagestreams.py deleted file mode 120000 index d53a5d99..00000000 --- a/1.24/test/test_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestreams.py \ No newline at end of file diff --git a/1.24/test/test_nginx_local_example.py b/1.24/test/test_nginx_local_example.py deleted file mode 120000 index 7c07f8a6..00000000 --- a/1.24/test/test_nginx_local_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_local_example.py \ No newline at end of file diff --git a/1.24/test/test_nginx_remote_example.py b/1.24/test/test_nginx_remote_example.py deleted file mode 120000 index 82e280f2..00000000 --- a/1.24/test/test_nginx_remote_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_remote_example.py \ No newline at end of file diff --git a/1.24/test/test_nginx_template_example_app.py b/1.24/test/test_nginx_template_example_app.py deleted file mode 120000 index efdf9caa..00000000 --- a/1.24/test/test_nginx_template_example_app.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_template_example_app.py \ No newline at end of file diff --git a/1.24/test/test_ocp_imagestream_s2i.py b/1.24/test/test_ocp_imagestream_s2i.py new file mode 120000 index 00000000..89eb6791 --- /dev/null +++ b/1.24/test/test_ocp_imagestream_s2i.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestream_s2i.py \ No newline at end of file diff --git a/1.24/test/test_ocp_imagestreams.py b/1.24/test/test_ocp_imagestreams.py new file mode 120000 index 00000000..ee905e77 --- /dev/null +++ b/1.24/test/test_ocp_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestreams.py \ No newline at end of file diff --git a/1.24/test/test_ocp_local_example.py b/1.24/test/test_ocp_local_example.py new file mode 120000 index 00000000..f2f3e849 --- /dev/null +++ b/1.24/test/test_ocp_local_example.py @@ -0,0 +1 @@ +../../test/test_ocp_local_example.py \ No newline at end of file diff --git a/1.24/test/test_ocp_remote_example.py b/1.24/test/test_ocp_remote_example.py new file mode 120000 index 00000000..7a912c02 --- /dev/null +++ b/1.24/test/test_ocp_remote_example.py @@ -0,0 +1 @@ +../../test/test_ocp_remote_example.py \ No newline at end of file diff --git a/1.24/test/test_ocp_shared_helm_imagestreams.py b/1.24/test/test_ocp_shared_helm_imagestreams.py new file mode 120000 index 00000000..76d5701d --- /dev/null +++ b/1.24/test/test_ocp_shared_helm_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_imagestreams.py \ No newline at end of file diff --git a/1.24/test/test_ocp_shared_helm_template.py b/1.24/test/test_ocp_shared_helm_template.py new file mode 120000 index 00000000..9cf469bf --- /dev/null +++ b/1.24/test/test_ocp_shared_helm_template.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_template.py \ No newline at end of file diff --git a/1.24/test/test_ocp_template_example_app.py b/1.24/test/test_ocp_template_example_app.py new file mode 120000 index 00000000..49e607f8 --- /dev/null +++ b/1.24/test/test_ocp_template_example_app.py @@ -0,0 +1 @@ +../../test/test_ocp_template_example_app.py \ No newline at end of file diff --git a/1.24/test/test_shared_helm_nginx_imagestreams.py b/1.24/test/test_shared_helm_nginx_imagestreams.py deleted file mode 120000 index 6363402b..00000000 --- a/1.24/test/test_shared_helm_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_imagestreams.py \ No newline at end of file diff --git a/1.24/test/test_shared_helm_nginx_template.py b/1.24/test/test_shared_helm_nginx_template.py deleted file mode 120000 index 01f3b3df..00000000 --- a/1.24/test/test_shared_helm_nginx_template.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_template.py \ No newline at end of file diff --git a/1.26/test/run-pytest b/1.26/test/run-pytest new file mode 120000 index 00000000..efe32b48 --- /dev/null +++ b/1.26/test/run-pytest @@ -0,0 +1 @@ +../../test/run-pytest \ No newline at end of file diff --git a/1.26/test/test_container_application.py b/1.26/test/test_container_application.py new file mode 120000 index 00000000..25c1c1ec --- /dev/null +++ b/1.26/test/test_container_application.py @@ -0,0 +1 @@ +../../test/test_container_application.py \ No newline at end of file diff --git a/1.26/test/test_container_basics.py b/1.26/test/test_container_basics.py new file mode 120000 index 00000000..b85dc139 --- /dev/null +++ b/1.26/test/test_container_basics.py @@ -0,0 +1 @@ +../../test/test_container_basics.py \ No newline at end of file diff --git a/1.26/test/test_container_example_app.py b/1.26/test/test_container_example_app.py new file mode 120000 index 00000000..ac4bde53 --- /dev/null +++ b/1.26/test/test_container_example_app.py @@ -0,0 +1 @@ +../../test/test_container_example_app.py \ No newline at end of file diff --git a/1.26/test/test_container_log.py b/1.26/test/test_container_log.py new file mode 120000 index 00000000..7f43a30a --- /dev/null +++ b/1.26/test/test_container_log.py @@ -0,0 +1 @@ +../../test/test_container_log.py \ No newline at end of file diff --git a/1.26/test/test_nginx_imagestream_s2i.py b/1.26/test/test_nginx_imagestream_s2i.py deleted file mode 120000 index 724bb1b6..00000000 --- a/1.26/test/test_nginx_imagestream_s2i.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestream_s2i.py \ No newline at end of file diff --git a/1.26/test/test_nginx_imagestreams.py b/1.26/test/test_nginx_imagestreams.py deleted file mode 120000 index d53a5d99..00000000 --- a/1.26/test/test_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_imagestreams.py \ No newline at end of file diff --git a/1.26/test/test_nginx_local_example.py b/1.26/test/test_nginx_local_example.py deleted file mode 120000 index 7c07f8a6..00000000 --- a/1.26/test/test_nginx_local_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_local_example.py \ No newline at end of file diff --git a/1.26/test/test_nginx_remote_example.py b/1.26/test/test_nginx_remote_example.py deleted file mode 120000 index 82e280f2..00000000 --- a/1.26/test/test_nginx_remote_example.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_remote_example.py \ No newline at end of file diff --git a/1.26/test/test_nginx_template_example_app.py b/1.26/test/test_nginx_template_example_app.py deleted file mode 120000 index efdf9caa..00000000 --- a/1.26/test/test_nginx_template_example_app.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_nginx_template_example_app.py \ No newline at end of file diff --git a/1.26/test/test_ocp_imagestream_s2i.py b/1.26/test/test_ocp_imagestream_s2i.py new file mode 120000 index 00000000..89eb6791 --- /dev/null +++ b/1.26/test/test_ocp_imagestream_s2i.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestream_s2i.py \ No newline at end of file diff --git a/1.26/test/test_ocp_imagestreams.py b/1.26/test/test_ocp_imagestreams.py new file mode 120000 index 00000000..ee905e77 --- /dev/null +++ b/1.26/test/test_ocp_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_imagestreams.py \ No newline at end of file diff --git a/1.26/test/test_ocp_local_example.py b/1.26/test/test_ocp_local_example.py new file mode 120000 index 00000000..f2f3e849 --- /dev/null +++ b/1.26/test/test_ocp_local_example.py @@ -0,0 +1 @@ +../../test/test_ocp_local_example.py \ No newline at end of file diff --git a/1.26/test/test_ocp_remote_example.py b/1.26/test/test_ocp_remote_example.py new file mode 120000 index 00000000..7a912c02 --- /dev/null +++ b/1.26/test/test_ocp_remote_example.py @@ -0,0 +1 @@ +../../test/test_ocp_remote_example.py \ No newline at end of file diff --git a/1.26/test/test_ocp_shared_helm_imagestreams.py b/1.26/test/test_ocp_shared_helm_imagestreams.py new file mode 120000 index 00000000..76d5701d --- /dev/null +++ b/1.26/test/test_ocp_shared_helm_imagestreams.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_imagestreams.py \ No newline at end of file diff --git a/1.26/test/test_ocp_shared_helm_template.py b/1.26/test/test_ocp_shared_helm_template.py new file mode 120000 index 00000000..9cf469bf --- /dev/null +++ b/1.26/test/test_ocp_shared_helm_template.py @@ -0,0 +1 @@ +../../test/test_ocp_shared_helm_template.py \ No newline at end of file diff --git a/1.26/test/test_ocp_template_example_app.py b/1.26/test/test_ocp_template_example_app.py new file mode 120000 index 00000000..49e607f8 --- /dev/null +++ b/1.26/test/test_ocp_template_example_app.py @@ -0,0 +1 @@ +../../test/test_ocp_template_example_app.py \ No newline at end of file diff --git a/1.26/test/test_shared_helm_nginx_imagestreams.py b/1.26/test/test_shared_helm_nginx_imagestreams.py deleted file mode 120000 index 6363402b..00000000 --- a/1.26/test/test_shared_helm_nginx_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_imagestreams.py \ No newline at end of file diff --git a/1.26/test/test_shared_helm_nginx_template.py b/1.26/test/test_shared_helm_nginx_template.py deleted file mode 120000 index 01f3b3df..00000000 --- a/1.26/test/test_shared_helm_nginx_template.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_shared_helm_nginx_template.py \ No newline at end of file diff --git a/test/dockerfile_processor.py b/test/dockerfile_processor.py new file mode 100644 index 00000000..c31573cb --- /dev/null +++ b/test/dockerfile_processor.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +""" +Dockerfile processor module to replace sed commands with Python functionality. +This module provides utilities to process Dockerfiles by replacing version strings +and environment variables. +""" + +import re +import os +import tempfile +from pathlib import Path +from typing import Optional, Union + + +class DockerfileProcessor: + """ + A class to process Dockerfiles by replacing version strings and environment variables. + This replaces the functionality of sed commands used in shell scripts. + """ + + def __init__(self, dockerfile_path: Union[str, Path]): + """ + Initialize the DockerfileProcessor with a path to a Dockerfile. + + Args: + dockerfile_path: Path to the Dockerfile to process + """ + self.dockerfile_path = Path(dockerfile_path) + if not self.dockerfile_path.exists(): + raise FileNotFoundError(f"Dockerfile not found: {dockerfile_path}") + + def process_nginx_version(self, version: str, output_path: Optional[Union[str, Path]] = None) -> str: + """ + Process the Dockerfile to replace NGINX version strings. + + This method performs the same operations as the sed command: + sed -e "s/^ENV NGINX_VERSION.*$/ENV NGINX_VERSION=$version/" -e "s/\$NGINX_VERSION/$version/g" + + Args: + version: The NGINX version to use for replacement + output_path: Optional path to write the processed content. If None, returns content as string. + + Returns: + The processed Dockerfile content as a string + """ + with open(self.dockerfile_path, 'r') as f: + content = f.read() + + # Replace ENV NGINX_VERSION line (equivalent to s/^ENV NGINX_VERSION.*$/ENV NGINX_VERSION=$version/) + content = re.sub(r'^ENV NGINX_VERSION.*$', f'ENV NGINX_VERSION={version}', content, flags=re.MULTILINE) + + # Replace all occurrences of $NGINX_VERSION (equivalent to s/\$NGINX_VERSION/$version/g) + content = content.replace('$NGINX_VERSION', version) + + if output_path: + output_path = Path(output_path) + with open(output_path, 'w') as f: + f.write(content) + + return content + + def create_temp_dockerfile(self, version: str) -> str: + """ + Create a temporary Dockerfile with processed version strings. + + Args: + version: The NGINX version to use for replacement + + Returns: + Path to the temporary Dockerfile + """ + # Create a temporary file + fd, temp_path = tempfile.mkstemp(suffix='.dockerfile', prefix='nginx_test_') + os.close(fd) # Close the file descriptor, we'll write to it separately + + # Process and write the content + self.process_nginx_version(version, temp_path) + + return temp_path + + def validate_dockerfile_syntax(self, content: str) -> bool: + """ + Basic validation of Dockerfile syntax. + + Args: + content: Dockerfile content to validate + + Returns: + True if basic syntax checks pass, False otherwise + """ + lines = content.strip().split('\n') + + # Check for basic Dockerfile structure + has_from = any(line.strip().upper().startswith('FROM') for line in lines) + if not has_from: + return False + + # Check for valid instruction format + valid_instructions = { + 'FROM', 'RUN', 'CMD', 'LABEL', 'EXPOSE', 'ENV', 'ADD', 'COPY', + 'ENTRYPOINT', 'VOLUME', 'USER', 'WORKDIR', 'ARG', 'ONBUILD', + 'STOPSIGNAL', 'HEALTHCHECK', 'SHELL' + } + + for line in lines: + line = line.strip() + if not line or line.startswith('#'): + continue + + # Extract the instruction (first word) + instruction = line.split()[0].upper() + if instruction not in valid_instructions: + return False + + return True + + @staticmethod + def replace_version_in_file(dockerfile_path: Union[str, Path], version: str, output_path: Union[str, Path]) -> None: + """ + Static method to replace version in a Dockerfile and write to output file. + This is the direct replacement for the sed command functionality. + + Args: + dockerfile_path: Path to input Dockerfile + version: Version string to replace + output_path: Path to output the processed Dockerfile + """ + processor = DockerfileProcessor(dockerfile_path) + processor.process_nginx_version(version, output_path) + + +def main(): + """ + Command-line interface for the Dockerfile processor. + Usage: python dockerfile_processor.py + """ + import sys + + if len(sys.argv) != 4: + print("Usage: python dockerfile_processor.py ") + sys.exit(1) + + dockerfile_path, version, output_path = sys.argv[1:4] + + try: + DockerfileProcessor.replace_version_in_file(dockerfile_path, version, output_path) + print(f"Successfully processed {dockerfile_path} -> {output_path} with version {version}") + except Exception as e: + print(f"Error: {e}") + sys.exit(1) + + +if __name__ == "__main__": + main() + diff --git a/test/pytest.ini b/test/pytest.ini new file mode 100644 index 00000000..9cf6f4be --- /dev/null +++ b/test/pytest.ini @@ -0,0 +1,26 @@ +[tool:pytest] +# Pytest configuration for nginx-container tests +testpaths = . +python_files = test_*.py +python_classes = Test* +python_functions = test_* +addopts = + -v + --tb=short + --strict-markers + --strict-config + --disable-warnings + -ra +markers = + unit: Unit tests for individual components + integration: Integration tests that test component interaction + dockerfile: Tests related to Dockerfile processing + slow: Tests that take a long time to run + network: Tests that require network access + container: Tests that require container runtime + openshift: Tests that require OpenShift environment + parametrize: Parametrized tests with multiple inputs +filterwarnings = + ignore::DeprecationWarning + ignore::PendingDeprecationWarning + diff --git a/test/run b/test/run index 9e92e043..a7896312 100755 --- a/test/run +++ b/test/run @@ -25,7 +25,6 @@ TEST_LIST_HOOK_APP="test_pre_init_script" TEST_LIST_PERL_APP="test_perl_directive" TEST_LIST_MISC=run_dockerfiles_test - source "$test_dir/test-lib.sh" # TODO: This should be part of the image metadata @@ -421,7 +420,7 @@ TEST_SET=${TEST_LIST_HOOK_APP} ct_run_tests_from_testset "start-hook-test-app" # Run the chosen tests (not for micro variant which lacks perl) if ! [[ "${IMAGE_NAME}" =~ .*micro.* ]] ; then build_image "perl-test-app" - TEST_LIST=${TEST_LIST_PERL_APP} ct_run_tests_from_testset "perl-test-app" + TEST_SET=${TEST_LIST_PERL_APP} ct_run_tests_from_testset "perl-test-app" fi diff --git a/test/run-openshift-pytest b/test/run-openshift-pytest index 8f6bd18c..ed9d8a39 100755 --- a/test/run-openshift-pytest +++ b/test/run-openshift-pytest @@ -10,4 +10,4 @@ THISDIR=$(dirname ${BASH_SOURCE[0]}) git show -s -cd "${THISDIR}" && python3.12 -m pytest -s -rA --showlocals -vv test_*.py +cd "${THISDIR}" && python3.12 -m pytest -s -rA --showlocals -vv test_ocp_*.py diff --git a/test/run-pytest b/test/run-pytest new file mode 100755 index 00000000..abe61217 --- /dev/null +++ b/test/run-pytest @@ -0,0 +1,17 @@ +#!/bin/bash +# +# IMAGE_NAME specifies a name of the candidate image used for testing. +# The image has to be available before this script is executed. +# SINGLE_VERSION specifies the major version of the MariaDB in format of X.Y +# OS specifies RHEL version (e.g. OS=rhel8) +# + +THISDIR=$(dirname ${BASH_SOURCE[0]}) + +git show -s + +PYTHON_VERSION="3.12" +if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then + PYTHON_VERSION="3.13" +fi +cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container*.py diff --git a/test/test_container_application.py b/test/test_container_application.py new file mode 100644 index 00000000..d113dd12 --- /dev/null +++ b/test/test_container_application.py @@ -0,0 +1,99 @@ +import os +import sys +import pytest + +from pathlib import Path +from container_ci_suite.container_lib import ContainerTestLib +from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper +from container_ci_suite.utils import check_variables, ContainerTestLibUtils + +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET") + +image_name = IMAGE_NAME.split(":")[0] +image_tag = IMAGE_NAME.split(":")[1] +test_dir = os.path.join(os.getcwd()) +print(f"Test dir is: {TEST_DIR}") +test_app = os.path.join(TEST_DIR, "test-app") +app_params_test = [test_app] + +@pytest.fixture(scope="module", params=app_params_test) +def app(request): + container_lib = ContainerTestLib(IMAGE_NAME) + app_name = os.path.basename(request.param) + print(f"APP reuqest: {request.param}") + s2i_app = container_lib.build_as_df( + app_path=request.param, + s2i_args="--pull-policy=never", + src_image=IMAGE_NAME, + dst_image=f"{IMAGE_NAME}-{app_name}" + ) + yield s2i_app + s2i_app.clean_containers() + + +class TestNginxApplicationContainer: + + # test_application + def test_application(self, app): + cid_file_name = "test-app" + app.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") + assert app.create_container( + cid_file=cid_file_name, + container_args=f"--user 10001" + ) + cip = app.get_cip(cid_name=cid_file_name) + assert PodmanCLIWrapper.podman_run_command( + f"--rm {app.image_name} /bin/bash -c 'nginx -v'" + ).startswith(f"nginx version: nginx/{VERSION}") + assert app.test_response( + url=f"http://{cip}", expected_output="NGINX is working" + ) + assert app.test_response( + url=f"http://{cip}", expected_output="NGINX2 is working", + host="localhost2" + ) + assert app.test_response( + url=f"http://{cip}", expected_output="NGINX2 is working", + page="/aliased/index2.html" + ) + assert app.test_response( + url=f"http://{cip}", expected_code=404, + page="/nginx-cfg/default.conf" + ) + + + # test_application_user + def test_application_user(self, app): + cid_file_name = "test-app" + app.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") + assert app.create_container( + cid_file=cid_file_name, + container_args=f"--user 10001 --user 12345" + ) + cip = app.get_cip(cid_name=cid_file_name) + assert PodmanCLIWrapper.podman_run_command( + f"--rm {app.image_name} /bin/bash -c 'nginx -v'" + ).startswith(f"nginx version: nginx/{VERSION}") + assert app.test_response( + url=f"http://{cip}", expected_output="NGINX is working" + ) + assert app.test_response( + url=f"http://{cip}", expected_output="NGINX2 is working", + host="localhost2" + ) + assert app.test_response( + url=f"http://{cip}", expected_output="NGINX2 is working", + page="/aliased/index2.html" + ) + assert app.test_response( + url=f"http://{cip}", expected_code=404, + page="/nginx-cfg/default.conf" + ) diff --git a/test/test_container_basics.py b/test/test_container_basics.py new file mode 100644 index 00000000..e37e7580 --- /dev/null +++ b/test/test_container_basics.py @@ -0,0 +1,86 @@ +import os +import sys +import pytest + +from pathlib import Path +from container_ci_suite.container_lib import ContainerTestLib +from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper +from container_ci_suite.utils import check_variables, ContainerTestLibUtils +from container_ci_suite.dockerfile_processor import DockerfileProcessor +from container_ci_suite.git import Git + +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) + +if not check_variables(): + print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") + sys.exit(1) + +VERSION = os.getenv("VERSION", None) +IMAGE_NAME = os.getenv("IMAGE_NAME", None) +OS = os.getenv("TARGET", None) + +image_name = IMAGE_NAME.split(":")[0] +image_tag = IMAGE_NAME.split(":")[1] +test_dir = os.path.join(os.getcwd()) +print(f"Test dir is: {TEST_DIR}") + + +@pytest.fixture(scope="module") +def app(request): + app = ContainerTestLib(image_name=IMAGE_NAME, s2i_image=True) + # app_name = os.path.basename(request.param) + yield app + app.clean_containers() + app.clean_app_images() + +class TestNginxContainer: + + # test_s2i_usage + def test_run_s2i_usage(self, app): + output = app.s2i_usage() + print(f"S2i_USAGE output: '{output}'") + assert output != "" + + # # test_docker_run_usage + def test_docker_run_usage(self): + assert PodmanCLIWrapper.call_podman_command( + cmd=f"run --rm {IMAGE_NAME} &>/dev/null", + return_output=False + ) == 0 + + + # test_scl_usage + @pytest.mark.parametrize( + "command,expected", + [ + ("nginx -v", f"nginx version: nginx/{VERSION}"), + ] + ) + def test_scl_usage(self, command, expected): + assert PodmanCLIWrapper.podman_run_command( + f"--rm {IMAGE_NAME} /bin/bash -c '{command}'" + ).startswith(expected) + + @pytest.mark.parametrize( + "dockerfile", + [ + "Dockerfile", + "Dockerfile.s2i" + ] + ) + def test_dockerfiles(self, app, dockerfile): + version = VERSION.replace("-micro", "") + dp = DockerfileProcessor(dockerfile_path=f"{TEST_DIR}/examples/{dockerfile}") + dp.update_env_in_dockerfile(version=version, what_to_replace="ENV NGINX_VERSION") + dp.update_variable_in_dockerfile(version=version, variable="NGINX_VERSION") + new_docker_file = dp.create_temp_dockerfile() + + assert app.build_test_container( + dockerfile=new_docker_file, app_url="https://github.com/sclorg/nginx-container.git", + app_dir="nginx-container" + ) + assert app.test_app_dockerfile() + cip = app.get_cip() + assert cip + assert app.test_response(url=f"{cip}", expected_code=200, + expected_output="NGINX is working") diff --git a/test/test_container_example_app.py b/test/test_container_example_app.py new file mode 100644 index 00000000..c81ae350 --- /dev/null +++ b/test/test_container_example_app.py @@ -0,0 +1,117 @@ +import os +import sys +import pytest + +from pathlib import Path + +from container_ci_suite.container_lib import ContainerTestLib +from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper +from container_ci_suite.utils import check_variables, ContainerTestLibUtils +from container_ci_suite.engines.container import ContainerImage + +if not check_variables(): + print("At least one variable from OS, VERSION is missing.") + sys.exit(1) + +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) + +VERSION = os.getenv("VERSION") +OS = os.getenv("TARGET") + +IMAGE_NAME = os.getenv("IMAGE_NAME") +if not IMAGE_NAME: + print(f"Built container for version {VERSION} on OS {OS} does not exist.") + sys.exit(1) + +image_tag_wo_tag = IMAGE_NAME.split(":")[0] +image_tag = IMAGE_NAME.split(":")[1] +perl_test_app = os.path.join(TEST_DIR, "perl-test-app") +start_hook_test_app = os.path.join(TEST_DIR, "start-hook-test-app") + +app_params_perl_test_app = [perl_test_app] +app_params_start_hook = [start_hook_test_app] + + +@pytest.fixture(scope="module", params=app_params_start_hook) +def example_app_test(request): + container_lib = ContainerTestLib(IMAGE_NAME) + app_name = os.path.basename(request.param) + print(f"App Name: {app_name}") + s2i_app = container_lib.build_as_df( + app_path=request.param, + s2i_args="--pull-policy=never", + src_image=IMAGE_NAME, + dst_image=f"{IMAGE_NAME}-{app_name}" + ) + s2i_app.set_new_image(image_name=f"{IMAGE_NAME}-{app_name}") + yield s2i_app + s2i_app.clean_containers() + +@pytest.fixture(scope="module", params=app_params_perl_test_app) +def example_perl_test(request): + container_lib = ContainerTestLib(IMAGE_NAME) + app_name = os.path.basename(request.param) + print(f"App Name: {app_name}") + s2i_app = container_lib.build_as_df( + app_path=request.param, + s2i_args="--pull-policy=never", + src_image=IMAGE_NAME, + dst_image=f"{IMAGE_NAME}-{app_name}" + ) + s2i_app.set_new_image(image_name=f"{IMAGE_NAME}-{app_name}") + yield s2i_app + s2i_app.clean_containers() + +@pytest.mark.usefixtures("example_app_test") +class TestNginxExampleAppContainer: + + def test_run_app_test(self, example_app_test): + cid_file = example_app_test.app_name + assert example_app_test.create_container(cid_file=cid_file, container_args="--user 10001") + assert ContainerImage.wait_for_cid(cid_file=cid_file) + cid = example_app_test.get_cid(cid_name=cid_file) + assert cid + cip = example_app_test.get_cip(cid_name=cid_file) + assert cip + command = PodmanCLIWrapper.podman_get_file_content(cid_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf") + print(f"Content of default.conf is {command}") + assert ContainerTestLibUtils.check_regexp_output(regexp_to_check="resolver", logs_to_check=command) + assert not ContainerTestLibUtils.check_regexp_output(regexp_to_check="DNS_SERVER", logs_to_check=command) + assert PodmanCLIWrapper.podman_run_command( + f"--rm {example_app_test.image_name} /bin/bash -c 'nginx -v'" + ).startswith(f"nginx version: nginx/{VERSION}") + assert example_app_test.test_response( + url=f"http://{cip}", expected_output="NGINX is working" + ) + assert example_app_test.test_response( + url=f"http://{cip}", expected_output="NGINX2 is working", + host="localhost2" + ) + assert example_app_test.test_response( + url=f"http://{cip}", expected_code=404, + page="/nginx-cfg/default.conf" + ) + +@pytest.mark.usefixtures("example_perl_test") +class TestNginxExamplePerlAppContainer: + + def test_run_app_test(self, example_perl_test): + cid_file = example_perl_test.app_name + print(cid_file) + example_perl_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file}") + assert example_perl_test.create_container(cid_file=cid_file, container_args="--user 10001") + cid = example_perl_test.get_cid(cid_name=cid_file) + assert cid + cip = example_perl_test.get_cip(cid_name=cid_file) + assert cip + print(f"CIP: {cip}") + perl_version = PodmanCLIWrapper.podman_exec_bash_command(cid_name=cid, cmd="perl -e 'print \"$^V\"'") + print(f"Content of perl is: '{perl_version}'.") + assert example_perl_test.test_response( + url=f"http://{cip}", port=8080, + expected_output=f"X-Perl-Version: {perl_version}" + ) + assert example_perl_test.test_response( + url=f"http://{cip}", port=8080, page="/perl", expected_output="Perl location handler is working" + ) + diff --git a/test/test_container_log.py b/test/test_container_log.py new file mode 100644 index 00000000..65681aca --- /dev/null +++ b/test/test_container_log.py @@ -0,0 +1,96 @@ +import os +import sys +import pytest + +from pathlib import Path + +from container_ci_suite.container_lib import ContainerTestLib +from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper +from container_ci_suite.utils import check_variables, ContainerTestLibUtils, get_file_content +from container_ci_suite.git import Git + +if not check_variables(): + print("At least one variable from OS, VERSION is missing.") + sys.exit(1) + +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) + +VERSION = os.getenv("VERSION") +OS = os.getenv("TARGET") + +IMAGE_NAME = os.getenv("IMAGE_NAME") +if not IMAGE_NAME: + print(f"Built container for version {VERSION} on OS {OS} does not exist.") + sys.exit(1) + +test_app = os.path.join(TEST_DIR, "test-app") +app_params_test = [test_app] + +@pytest.fixture(scope="module", params=app_params_test) +def s2i_log_test(request): + container_lib = ContainerTestLib(IMAGE_NAME) + app_name = os.path.basename(request.param) + s2i_app = container_lib.build_as_df( + app_path=request.param, + s2i_args="--pull-policy=never", + src_image=IMAGE_NAME, + dst_image=f"{IMAGE_NAME}-{app_name}" + ) + yield s2i_app + s2i_app.clean_containers() + +class TestNginxLogContainer: + + # test_log_output + def test_log_output(self, s2i_log_test): + cid_file_name = "test-app" + s2i_log_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") + assert s2i_log_test.create_container( + cid_file=cid_file_name, + container_args=f"--user 10001" + ) + cid = s2i_log_test.get_cid(cid_name=cid_file_name) + assert cid + cip = s2i_log_test.get_cip(cid_name=cid_file_name) + assert s2i_log_test.test_response(url=f"http://{cip}", port=8080, expected_output="NGINX is working") + assert '"GET / HTTP/1.1" 200' in s2i_log_test.get_logs(cid_name=cid_file_name) + assert s2i_log_test.test_response( + url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404 + ) + logs = s2i_log_test.get_logs(cid_name=cid_file_name) + assert logs + ContainerTestLibUtils.check_regexp_output( + regexp_to_check="open.*failed.*No such file or directory", + logs_to_check=logs + ) + + # test_log_volume_output + def test_log_volume_output(self, s2i_log_test): + cid_file_name = "test-app" + s2i_log_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") + assert s2i_log_test.create_container( + cid_file=cid_file_name, + container_args=f"-e NGINX_LOG_TO_VOLUME=y --user 10001" + ) + cid = s2i_log_test.get_cid(cid_name=cid_file_name) + assert cid + cip = s2i_log_test.get_cip(cid_name=cid_file_name) + assert s2i_log_test.test_response(url=f"http://{cip}", port=8080, expected_output="NGINX is working") + assert '"GET / HTTP/1.1" 200' in PodmanCLIWrapper.podman_get_file_content( + cid_name=cid, + filename="/var/log/nginx/access.log" + ) + assert s2i_log_test.test_response( + url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404 + ) + assert '"GET /nothing-at-all HTTP/1.1" 404' in PodmanCLIWrapper.podman_get_file_content( + cid_name=cid, + filename="/var/log/nginx/access.log" + ) + assert ContainerTestLibUtils.check_regexp_output( + regexp_to_check="open.*failed.*No such file or directory", + logs_to_check=PodmanCLIWrapper.podman_get_file_content( + cid_name=cid, + filename="/var/log/nginx/error.log" + ) + ) diff --git a/test/test_nginx_imagestream_s2i.py b/test/test_ocp_imagestream_s2i.py similarity index 100% rename from test/test_nginx_imagestream_s2i.py rename to test/test_ocp_imagestream_s2i.py diff --git a/test/test_nginx_imagestreams.py b/test/test_ocp_imagestreams.py similarity index 100% rename from test/test_nginx_imagestreams.py rename to test/test_ocp_imagestreams.py diff --git a/test/test_nginx_local_example.py b/test/test_ocp_local_example.py similarity index 100% rename from test/test_nginx_local_example.py rename to test/test_ocp_local_example.py diff --git a/test/test_nginx_remote_example.py b/test/test_ocp_remote_example.py similarity index 100% rename from test/test_nginx_remote_example.py rename to test/test_ocp_remote_example.py diff --git a/test/test_shared_helm_nginx_imagestreams.py b/test/test_ocp_shared_helm_imagestreams.py similarity index 100% rename from test/test_shared_helm_nginx_imagestreams.py rename to test/test_ocp_shared_helm_imagestreams.py diff --git a/test/test_shared_helm_nginx_template.py b/test/test_ocp_shared_helm_template.py similarity index 100% rename from test/test_shared_helm_nginx_template.py rename to test/test_ocp_shared_helm_template.py diff --git a/test/test_nginx_template_example_app.py b/test/test_ocp_template_example_app.py similarity index 100% rename from test/test_nginx_template_example_app.py rename to test/test_ocp_template_example_app.py From 3527c295dc6aa24107b5db8b66cfd25c90e2e3cc Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 16 Sep 2025 13:11:22 +0200 Subject: [PATCH 2/3] Do not run Perl test on micro image because it lacks with perl Do not use micro version, but only a VERSION Signed-off-by: Petr "Stone" Hracek --- test/test_container_application.py | 6 ++++-- test/test_container_basics.py | 15 +++++---------- test/test_container_example_app.py | 6 ++++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/test/test_container_application.py b/test/test_container_application.py index d113dd12..f533eb53 100644 --- a/test/test_container_application.py +++ b/test/test_container_application.py @@ -43,6 +43,7 @@ class TestNginxApplicationContainer: # test_application def test_application(self, app): + version = VERSION.replace("-micro", "") cid_file_name = "test-app" app.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") assert app.create_container( @@ -52,7 +53,7 @@ def test_application(self, app): cip = app.get_cip(cid_name=cid_file_name) assert PodmanCLIWrapper.podman_run_command( f"--rm {app.image_name} /bin/bash -c 'nginx -v'" - ).startswith(f"nginx version: nginx/{VERSION}") + ).startswith(f"nginx version: nginx/{version}") assert app.test_response( url=f"http://{cip}", expected_output="NGINX is working" ) @@ -72,6 +73,7 @@ def test_application(self, app): # test_application_user def test_application_user(self, app): + version = VERSION.replace("-micro", "") cid_file_name = "test-app" app.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") assert app.create_container( @@ -81,7 +83,7 @@ def test_application_user(self, app): cip = app.get_cip(cid_name=cid_file_name) assert PodmanCLIWrapper.podman_run_command( f"--rm {app.image_name} /bin/bash -c 'nginx -v'" - ).startswith(f"nginx version: nginx/{VERSION}") + ).startswith(f"nginx version: nginx/{version}") assert app.test_response( url=f"http://{cip}", expected_output="NGINX is working" ) diff --git a/test/test_container_basics.py b/test/test_container_basics.py index e37e7580..61f8752e 100644 --- a/test/test_container_basics.py +++ b/test/test_container_basics.py @@ -19,6 +19,7 @@ IMAGE_NAME = os.getenv("IMAGE_NAME", None) OS = os.getenv("TARGET", None) + image_name = IMAGE_NAME.split(":")[0] image_tag = IMAGE_NAME.split(":")[1] test_dir = os.path.join(os.getcwd()) @@ -49,17 +50,11 @@ def test_docker_run_usage(self): ) == 0 - # test_scl_usage - @pytest.mark.parametrize( - "command,expected", - [ - ("nginx -v", f"nginx version: nginx/{VERSION}"), - ] - ) - def test_scl_usage(self, command, expected): + def test_scl_usage(self): + version = VERSION.replace("-micro", "") assert PodmanCLIWrapper.podman_run_command( - f"--rm {IMAGE_NAME} /bin/bash -c '{command}'" - ).startswith(expected) + f"--rm {IMAGE_NAME} /bin/bash -c 'nginx -v'" + ).startswith(f"nginx version: nginx/{version}") @pytest.mark.parametrize( "dockerfile", diff --git a/test/test_container_example_app.py b/test/test_container_example_app.py index c81ae350..c0253f4b 100644 --- a/test/test_container_example_app.py +++ b/test/test_container_example_app.py @@ -66,6 +66,7 @@ def example_perl_test(request): class TestNginxExampleAppContainer: def test_run_app_test(self, example_app_test): + version = VERSION.replace("-micro", "") cid_file = example_app_test.app_name assert example_app_test.create_container(cid_file=cid_file, container_args="--user 10001") assert ContainerImage.wait_for_cid(cid_file=cid_file) @@ -79,7 +80,7 @@ def test_run_app_test(self, example_app_test): assert not ContainerTestLibUtils.check_regexp_output(regexp_to_check="DNS_SERVER", logs_to_check=command) assert PodmanCLIWrapper.podman_run_command( f"--rm {example_app_test.image_name} /bin/bash -c 'nginx -v'" - ).startswith(f"nginx version: nginx/{VERSION}") + ).startswith(f"nginx version: nginx/{version}") assert example_app_test.test_response( url=f"http://{cip}", expected_output="NGINX is working" ) @@ -96,8 +97,9 @@ def test_run_app_test(self, example_app_test): class TestNginxExamplePerlAppContainer: def test_run_app_test(self, example_perl_test): + if VERSION.endswith("-micro"): + pytest.skip("Run the chosen tests (not for micro variant which lacks perl)") cid_file = example_perl_test.app_name - print(cid_file) example_perl_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file}") assert example_perl_test.create_container(cid_file=cid_file, container_args="--user 10001") cid = example_perl_test.get_cid(cid_name=cid_file) From 07a11271961f8cdf6aef3927987bd195e18e85c6 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Fri, 19 Sep 2025 09:46:34 +0200 Subject: [PATCH 3/3] Update PyTest tests for containers based on review https://github.com/sclorg/httpd-container/pull/234 Signed-off-by: Petr "Stone" Hracek --- test/constants.py | 7 ++++ test/test_container_application.py | 26 ++++++-------- test/test_container_basics.py | 20 +++-------- test/test_container_example_app.py | 56 ++++++++++++------------------ test/test_container_log.py | 39 ++++++++++----------- 5 files changed, 64 insertions(+), 84 deletions(-) diff --git a/test/constants.py b/test/constants.py index e0402ba6..b83f17fc 100644 --- a/test/constants.py +++ b/test/constants.py @@ -1,5 +1,12 @@ +import os + + TAGS = { "rhel8": "-ubi8", "rhel9": "-ubi9", "rhel10": "-ubi10", } + + +def return_app_name(request): + return os.path.basename(request.param) diff --git a/test/test_container_application.py b/test/test_container_application.py index f533eb53..2e8024af 100644 --- a/test/test_container_application.py +++ b/test/test_container_application.py @@ -2,33 +2,27 @@ import sys import pytest + from pathlib import Path from container_ci_suite.container_lib import ContainerTestLib from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper -from container_ci_suite.utils import check_variables, ContainerTestLibUtils +from container_ci_suite.utils import check_variables -TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) if not check_variables(): print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") sys.exit(1) - VERSION = os.getenv("VERSION") IMAGE_NAME = os.getenv("IMAGE_NAME") -OS = os.getenv("TARGET") - -image_name = IMAGE_NAME.split(":")[0] -image_tag = IMAGE_NAME.split(":")[1] -test_dir = os.path.join(os.getcwd()) -print(f"Test dir is: {TEST_DIR}") +OS = os.getenv("TARGET").lower() test_app = os.path.join(TEST_DIR, "test-app") -app_params_test = [test_app] -@pytest.fixture(scope="module", params=app_params_test) + +@pytest.fixture(scope="module", params=[test_app]) def app(request): container_lib = ContainerTestLib(IMAGE_NAME) app_name = os.path.basename(request.param) - print(f"APP reuqest: {request.param}") s2i_app = container_lib.build_as_df( app_path=request.param, s2i_args="--pull-policy=never", @@ -47,10 +41,10 @@ def test_application(self, app): cid_file_name = "test-app" app.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") assert app.create_container( - cid_file=cid_file_name, + cid_file_name=cid_file_name, container_args=f"--user 10001" ) - cip = app.get_cip(cid_name=cid_file_name) + cip = app.get_cip(cid_file_name=cid_file_name) assert PodmanCLIWrapper.podman_run_command( f"--rm {app.image_name} /bin/bash -c 'nginx -v'" ).startswith(f"nginx version: nginx/{version}") @@ -77,10 +71,10 @@ def test_application_user(self, app): cid_file_name = "test-app" app.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") assert app.create_container( - cid_file=cid_file_name, + cid_file_name=cid_file_name, container_args=f"--user 10001 --user 12345" ) - cip = app.get_cip(cid_name=cid_file_name) + cip = app.get_cip(cid_file_name=cid_file_name) assert PodmanCLIWrapper.podman_run_command( f"--rm {app.image_name} /bin/bash -c 'nginx -v'" ).startswith(f"nginx version: nginx/{version}") diff --git a/test/test_container_basics.py b/test/test_container_basics.py index 61f8752e..7e78cb9a 100644 --- a/test/test_container_basics.py +++ b/test/test_container_basics.py @@ -5,31 +5,22 @@ from pathlib import Path from container_ci_suite.container_lib import ContainerTestLib from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper -from container_ci_suite.utils import check_variables, ContainerTestLibUtils +from container_ci_suite.utils import check_variables from container_ci_suite.dockerfile_processor import DockerfileProcessor -from container_ci_suite.git import Git -TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) +TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) if not check_variables(): print("At least one variable from IMAGE_NAME, OS, VERSION is missing.") sys.exit(1) - -VERSION = os.getenv("VERSION", None) -IMAGE_NAME = os.getenv("IMAGE_NAME", None) -OS = os.getenv("TARGET", None) - - -image_name = IMAGE_NAME.split(":")[0] -image_tag = IMAGE_NAME.split(":")[1] -test_dir = os.path.join(os.getcwd()) -print(f"Test dir is: {TEST_DIR}") +VERSION = os.getenv("VERSION") +IMAGE_NAME = os.getenv("IMAGE_NAME") +OS = os.getenv("TARGET").lower() @pytest.fixture(scope="module") def app(request): app = ContainerTestLib(image_name=IMAGE_NAME, s2i_image=True) - # app_name = os.path.basename(request.param) yield app app.clean_containers() app.clean_app_images() @@ -39,7 +30,6 @@ class TestNginxContainer: # test_s2i_usage def test_run_s2i_usage(self, app): output = app.s2i_usage() - print(f"S2i_USAGE output: '{output}'") assert output != "" # # test_docker_run_usage diff --git a/test/test_container_example_app.py b/test/test_container_example_app.py index c0253f4b..8628d666 100644 --- a/test/test_container_example_app.py +++ b/test/test_container_example_app.py @@ -8,35 +8,27 @@ from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper from container_ci_suite.utils import check_variables, ContainerTestLibUtils from container_ci_suite.engines.container import ContainerImage +from constants import return_app_name + if not check_variables(): print("At least one variable from OS, VERSION is missing.") sys.exit(1) - TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) - VERSION = os.getenv("VERSION") -OS = os.getenv("TARGET") - +OS = os.getenv("TARGET").lower() IMAGE_NAME = os.getenv("IMAGE_NAME") if not IMAGE_NAME: print(f"Built container for version {VERSION} on OS {OS} does not exist.") sys.exit(1) - -image_tag_wo_tag = IMAGE_NAME.split(":")[0] -image_tag = IMAGE_NAME.split(":")[1] perl_test_app = os.path.join(TEST_DIR, "perl-test-app") start_hook_test_app = os.path.join(TEST_DIR, "start-hook-test-app") -app_params_perl_test_app = [perl_test_app] -app_params_start_hook = [start_hook_test_app] - -@pytest.fixture(scope="module", params=app_params_start_hook) +@pytest.fixture(scope="module", params=[start_hook_test_app]) def example_app_test(request): container_lib = ContainerTestLib(IMAGE_NAME) - app_name = os.path.basename(request.param) - print(f"App Name: {app_name}") + app_name = return_app_name(request) s2i_app = container_lib.build_as_df( app_path=request.param, s2i_args="--pull-policy=never", @@ -47,11 +39,10 @@ def example_app_test(request): yield s2i_app s2i_app.clean_containers() -@pytest.fixture(scope="module", params=app_params_perl_test_app) +@pytest.fixture(scope="module", params=[perl_test_app]) def example_perl_test(request): container_lib = ContainerTestLib(IMAGE_NAME) - app_name = os.path.basename(request.param) - print(f"App Name: {app_name}") + app_name = return_app_name(request) s2i_app = container_lib.build_as_df( app_path=request.param, s2i_args="--pull-policy=never", @@ -62,20 +53,21 @@ def example_perl_test(request): yield s2i_app s2i_app.clean_containers() -@pytest.mark.usefixtures("example_app_test") + class TestNginxExampleAppContainer: def test_run_app_test(self, example_app_test): version = VERSION.replace("-micro", "") - cid_file = example_app_test.app_name - assert example_app_test.create_container(cid_file=cid_file, container_args="--user 10001") - assert ContainerImage.wait_for_cid(cid_file=cid_file) - cid = example_app_test.get_cid(cid_name=cid_file) + cid_file_name = example_app_test.app_name + assert example_app_test.create_container(cid_file_name=cid_file_name, container_args="--user 10001") + assert ContainerImage.wait_for_cid(cid_file_name=cid_file_name) + cid = example_app_test.get_cid(cid_file_name=cid_file_name) assert cid - cip = example_app_test.get_cip(cid_name=cid_file) + cip = example_app_test.get_cip(cid_file_name=cid_file_name) assert cip - command = PodmanCLIWrapper.podman_get_file_content(cid_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf") - print(f"Content of default.conf is {command}") + command = PodmanCLIWrapper.podman_get_file_content( + cid_file_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf" + ) assert ContainerTestLibUtils.check_regexp_output(regexp_to_check="resolver", logs_to_check=command) assert not ContainerTestLibUtils.check_regexp_output(regexp_to_check="DNS_SERVER", logs_to_check=command) assert PodmanCLIWrapper.podman_run_command( @@ -93,22 +85,20 @@ def test_run_app_test(self, example_app_test): page="/nginx-cfg/default.conf" ) -@pytest.mark.usefixtures("example_perl_test") + class TestNginxExamplePerlAppContainer: def test_run_app_test(self, example_perl_test): if VERSION.endswith("-micro"): pytest.skip("Run the chosen tests (not for micro variant which lacks perl)") - cid_file = example_perl_test.app_name - example_perl_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file}") - assert example_perl_test.create_container(cid_file=cid_file, container_args="--user 10001") - cid = example_perl_test.get_cid(cid_name=cid_file) + cid_file_name = example_perl_test.app_name + example_perl_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") + assert example_perl_test.create_container(cid_file_name=cid_file_name, container_args="--user 10001") + cid = example_perl_test.get_cid(cid_file_name=cid_file_name) assert cid - cip = example_perl_test.get_cip(cid_name=cid_file) + cip = example_perl_test.get_cip(cid_file_name=cid_file_name) assert cip - print(f"CIP: {cip}") - perl_version = PodmanCLIWrapper.podman_exec_bash_command(cid_name=cid, cmd="perl -e 'print \"$^V\"'") - print(f"Content of perl is: '{perl_version}'.") + perl_version = PodmanCLIWrapper.podman_exec_bash_command(cid_file_name=cid, cmd="perl -e 'print \"$^V\"'") assert example_perl_test.test_response( url=f"http://{cip}", port=8080, expected_output=f"X-Perl-Version: {perl_version}" diff --git a/test/test_container_log.py b/test/test_container_log.py index 65681aca..04d15412 100644 --- a/test/test_container_log.py +++ b/test/test_container_log.py @@ -7,26 +7,22 @@ from container_ci_suite.container_lib import ContainerTestLib from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper from container_ci_suite.utils import check_variables, ContainerTestLibUtils, get_file_content -from container_ci_suite.git import Git + if not check_variables(): print("At least one variable from OS, VERSION is missing.") sys.exit(1) - TEST_DIR = Path(os.path.abspath(os.path.dirname(__file__))) - VERSION = os.getenv("VERSION") -OS = os.getenv("TARGET") - +OS = os.getenv("TARGET").lower() IMAGE_NAME = os.getenv("IMAGE_NAME") if not IMAGE_NAME: print(f"Built container for version {VERSION} on OS {OS} does not exist.") sys.exit(1) - test_app = os.path.join(TEST_DIR, "test-app") -app_params_test = [test_app] -@pytest.fixture(scope="module", params=app_params_test) + +@pytest.fixture(scope="module", params=[test_app]) def s2i_log_test(request): container_lib = ContainerTestLib(IMAGE_NAME) app_name = os.path.basename(request.param) @@ -39,6 +35,7 @@ def s2i_log_test(request): yield s2i_app s2i_app.clean_containers() + class TestNginxLogContainer: # test_log_output @@ -46,18 +43,20 @@ def test_log_output(self, s2i_log_test): cid_file_name = "test-app" s2i_log_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") assert s2i_log_test.create_container( - cid_file=cid_file_name, + cid_file_name=cid_file_name, container_args=f"--user 10001" ) - cid = s2i_log_test.get_cid(cid_name=cid_file_name) + cid = s2i_log_test.get_cid(cid_file_name=cid_file_name) assert cid - cip = s2i_log_test.get_cip(cid_name=cid_file_name) - assert s2i_log_test.test_response(url=f"http://{cip}", port=8080, expected_output="NGINX is working") - assert '"GET / HTTP/1.1" 200' in s2i_log_test.get_logs(cid_name=cid_file_name) + cip = s2i_log_test.get_cip(cid_file_name=cid_file_name) + assert s2i_log_test.test_response( + url=f"http://{cip}", port=8080, expected_output="NGINX is working" + ) + assert '"GET / HTTP/1.1" 200' in s2i_log_test.get_logs(cid_file_name=cid_file_name) assert s2i_log_test.test_response( url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404 ) - logs = s2i_log_test.get_logs(cid_name=cid_file_name) + logs = s2i_log_test.get_logs(cid_file_name=cid_file_name) assert logs ContainerTestLibUtils.check_regexp_output( regexp_to_check="open.*failed.*No such file or directory", @@ -69,28 +68,28 @@ def test_log_volume_output(self, s2i_log_test): cid_file_name = "test-app" s2i_log_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}") assert s2i_log_test.create_container( - cid_file=cid_file_name, + cid_file_name=cid_file_name, container_args=f"-e NGINX_LOG_TO_VOLUME=y --user 10001" ) - cid = s2i_log_test.get_cid(cid_name=cid_file_name) + cid = s2i_log_test.get_cid(cid_file_name=cid_file_name) assert cid - cip = s2i_log_test.get_cip(cid_name=cid_file_name) + cip = s2i_log_test.get_cip(cid_file_name=cid_file_name) assert s2i_log_test.test_response(url=f"http://{cip}", port=8080, expected_output="NGINX is working") assert '"GET / HTTP/1.1" 200' in PodmanCLIWrapper.podman_get_file_content( - cid_name=cid, + cid_file_name=cid, filename="/var/log/nginx/access.log" ) assert s2i_log_test.test_response( url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404 ) assert '"GET /nothing-at-all HTTP/1.1" 404' in PodmanCLIWrapper.podman_get_file_content( - cid_name=cid, + cid_file_name=cid, filename="/var/log/nginx/access.log" ) assert ContainerTestLibUtils.check_regexp_output( regexp_to_check="open.*failed.*No such file or directory", logs_to_check=PodmanCLIWrapper.podman_get_file_content( - cid_name=cid, + cid_file_name=cid, filename="/var/log/nginx/error.log" ) )