Add container structure tests for apache-git-http-backend
Change-Id: Ie031eb9fb9cc8ce6781500bd49cbf21eae4f39b4
diff --git a/tests/conftest.py b/tests/conftest.py
index 6e486c5..a2f95fd 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -63,3 +63,9 @@
@pytest.fixture(scope="session")
def gitgc_image(container_images, docker_build, base_image):
return docker_build(container_images["git-gc"], "git-gc")
+
+@pytest.fixture(scope="session")
+def apache_git_http_backend_image(container_images, docker_build, base_image):
+ return docker_build(
+ container_images["apache-git-http-backend"],
+ "apache-git-http-backend")
diff --git a/tests/container-images/apache-git-http-backend/test_container_build_apache_git_http_backend.py b/tests/container-images/apache-git-http-backend/test_container_build_apache_git_http_backend.py
new file mode 100644
index 0000000..80ed635
--- /dev/null
+++ b/tests/container-images/apache-git-http-backend/test_container_build_apache_git_http_backend.py
@@ -0,0 +1,16 @@
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def test_build_apache_git_http_backend_image(apache_git_http_backend_image):
+ assert apache_git_http_backend_image.id is not None
diff --git a/tests/container-images/apache-git-http-backend/test_container_structure_apache_git_http_backend.py b/tests/container-images/apache-git-http-backend/test_container_structure_apache_git_http_backend.py
new file mode 100755
index 0000000..1315ea2
--- /dev/null
+++ b/tests/container-images/apache-git-http-backend/test_container_structure_apache_git_http_backend.py
@@ -0,0 +1,79 @@
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+
+@pytest.fixture(scope="module")
+def container_run(request, docker_client, apache_git_http_backend_image):
+ print("Starting apache-git-http-backend-container...")
+ container_run = docker_client.containers.run(
+ image=apache_git_http_backend_image.id,
+ entrypoint="/bin/bash",
+ command=["-c", "tail -f /dev/null"],
+ user="gerrit",
+ detach=True,
+ auto_remove=True
+ )
+
+ def stop_container():
+ print("Stopping apache-git-http-backend-container...")
+ container_run.stop(timeout=1)
+
+ request.addfinalizer(stop_container)
+
+ return container_run
+
+
+def test_apache_git_http_backend_inherits_from_base(apache_git_http_backend_image):
+ contains_tag = False
+ for layer in apache_git_http_backend_image.history():
+ contains_tag = layer['Tags'] is not None and "base:latest" in layer['Tags']
+ if contains_tag:
+ break
+ assert contains_tag
+
+def test_apache_git_http_backend_contains_apache2(container_run):
+ exit_code, _ = container_run.exec_run(
+ "which apache2"
+ )
+ assert exit_code == 0
+
+def test_apache_git_http_backend_http_site_configured(container_run):
+ exit_code, _ = container_run.exec_run(
+ "test -f /etc/apache2/sites-enabled/git-http-backend.conf"
+ )
+ assert exit_code == 0
+
+def test_apache_git_http_backend_https_site_configured(container_run):
+ exit_code, _ = container_run.exec_run(
+ "test -f /etc/apache2/sites-enabled/git-https-backend.conf"
+ )
+ assert exit_code == 0
+
+def test_apache_git_http_backend_contains_start_script(container_run):
+ exit_code, _ = container_run.exec_run(
+ "test -f /var/tools/start"
+ )
+ assert exit_code == 0
+
+def test_apache_git_http_backend_contains_repo_creation_cgi_script(container_run):
+ exit_code, _ = container_run.exec_run(
+ "test -f /var/cgi/create_repo.sh"
+ )
+ assert exit_code == 0
+
+def test_apache_git_http_backend_has_entrypoint(apache_git_http_backend_image):
+ entrypoint = apache_git_http_backend_image.attrs["ContainerConfig"]["Entrypoint"]
+ assert len(entrypoint) == 1
+ assert entrypoint[0] == "/var/tools/start"