Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ruby-ex repositories #570

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 2.5/test/test_helm_rails_ex_application.py
1 change: 1 addition & 0 deletions 2.5/test/test_helm_ruby_ex_application.py
1 change: 0 additions & 1 deletion 2.5/test/test_helm_ruby_rails_application.py

This file was deleted.

1 change: 1 addition & 0 deletions 3.0/test/test_helm_rails_ex_application.py
1 change: 1 addition & 0 deletions 3.0/test/test_helm_ruby_ex_application.py
1 change: 0 additions & 1 deletion 3.0/test/test_helm_ruby_rails_application.py

This file was deleted.

1 change: 1 addition & 0 deletions 3.1/test/test_helm_rails_ex_application.py
1 change: 1 addition & 0 deletions 3.1/test/test_helm_ruby_ex_application.py
1 change: 0 additions & 1 deletion 3.1/test/test_helm_ruby_rails_application.py

This file was deleted.

1 change: 1 addition & 0 deletions 3.3/test/test_helm_rails_ex_application.py
1 change: 1 addition & 0 deletions 3.3/test/test_helm_ruby_ex_application.py
1 change: 0 additions & 1 deletion 3.3/test/test_helm_ruby_rails_application.py

This file was deleted.

30 changes: 21 additions & 9 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ function test_application() {
function test_from_dockerfile() {
dockerfile="Dockerfile${1:-}"
TESTCASE_RESULT=0
info "Check building using a $dockerfile"

# Ruby 3.3 introduced too many incompatibilities to be able
# to use the same Gemfile for RHEL 7 and also newer RHELs.
# we can use the same Gemfile for RHEL 7 and newer
# as long as Ruby MAJOR.MINOR <= 3.1. Newer Ruby needs dependencies
# that are not compatible with RHEL 7.
info "Check building using a $dockerfile on rails-ex repository."

# Latest stable
rails_example_repo_branch="3.3"
Expand All @@ -158,6 +152,21 @@ function test_from_dockerfile_s2i() {
test_from_dockerfile ".s2i"
}

function test_from_dockerfile_ruby_ex() {
dockerfile="Dockerfile${1:-}"
TESTCASE_RESULT=0
info "Check building using a $dockerfile on ruby-ex repository."

ruby_example_repo_url="https://github.com/sclorg/ruby-ex.git@master"

ct_test_app_dockerfile $test_dir/examples/from-dockerfile/$dockerfile "$ruby_example_repo_url" 'Welcome to your Ruby application' app-src
ct_check_testcase_result $?
}

function test_from_dockerfile_ruby_ex_s2i() {
test_from_dockerfile_ruby_ex ".s2i"
}

app_cleanup() {
info "Cleaning up the test app folders"
for server in ${WEB_SERVERS[*]}; do
Expand Down Expand Up @@ -235,8 +244,11 @@ for server in ${WEB_SERVERS[@]}; do
cleanup
done

TEST_LIST="test_from_dockerfile test_from_dockerfile_s2i"
TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "from_dockerfile"
TEST_RAILS_LIST="test_from_dockerfile test_from_dockerfile_s2i"
TEST_SET=${TESTS:-$TEST_RAILS_LIST} ct_run_tests_from_testset "from_dockerfile_rails_ex"

TEST_RUBY_LIST="test_from_dockerfile_ruby_ex test_from_dockerfile_ruby_ex_s2i"
TEST_SET=${TESTS:-$TEST_RUBY_LIST} ct_run_tests_from_testset "from_dockerfile_ruby_ex"


# Remove all test dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
TAG = TAGS.get(OS, None)


class TestHelmCakePHPTemplate:
class TestHelmRailsExTemplate:

def setup_method(self):
package_name = "ruby-rails-application"
package_name = "redhat-ruby-rails-application"
path = test_dir
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, remote=True)
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=False)
self.hc_api.clone_helm_chart_repo(
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
subdir="charts/redhat"
Expand All @@ -48,39 +48,45 @@ def test_curl_connection(self):
rails_ex_branch = "master"
if VERSION == "3.3":
rails_ex_branch = VERSION
self.hc_api.package_name = "ruby-imagestreams"
self.hc_api.package_name = "redhat-ruby-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "ruby-rails-application"
self.hc_api.package_name = "redhat-ruby-rails-application"
assert self.hc_api.helm_package()
pod_name = f"rails-{VERSION.replace(".", "")}"
assert self.hc_api.helm_installation(
values={
"ruby_version": f"{VERSION}{TAG}",
"namespace": self.hc_api.namespace,
"source_repository_ref": rails_ex_branch,
"source_repository_url": "https://github.com/sclorg/rails-ex.git",
"name": pod_name,
}
)
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="rails-example")
assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name, timeout=480)
assert self.hc_api.test_helm_curl_output(
route_name="rails-example",
route_name=pod_name,
expected_str="Welcome to your Rails application"
)

def test_by_helm_test(self):
rails_ex_branch = "master"
if VERSION == "3.3":
rails_ex_branch = VERSION
self.hc_api.package_name = "ruby-imagestreams"
self.hc_api.package_name = "redhat-ruby-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "ruby-rails-application"
self.hc_api.package_name = "redhat-ruby-rails-application"
assert self.hc_api.helm_package()
pod_name = f"rails-{VERSION.replace(".", "")}"
assert self.hc_api.helm_installation(
values={
"ruby_version": f"{VERSION}{TAG}",
"namespace": self.hc_api.namespace,
"source_repository_ref": rails_ex_branch,
"source_repository_url": "https://github.com/sclorg/rails-ex.git",
"name": pod_name
}
)
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="rails-example")
assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name, timeout=480)
assert self.hc_api.test_helm_chart(expected_str=["Welcome to your Rails application"])
92 changes: 92 additions & 0 deletions test/test_helm_ruby_ex_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import os
import sys

import pytest

from pathlib import Path

from container_ci_suite.helm import HelmChartsAPI
from container_ci_suite.utils import check_variables

if not check_variables():
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
sys.exit(1)


test_dir = Path(os.path.abspath(os.path.dirname(__file__)))


VERSION = os.getenv("VERSION")
IMAGE_NAME = os.getenv("IMAGE_NAME")
OS = os.getenv("TARGET")


TAGS = {
"rhel8": "-ubi8",
"rhel9": "-ubi9"
}
TAG = TAGS.get(OS, None)


class TestHelmRubyExTemplate:

def setup_method(self):
package_name = "redhat-ruby-rails-application"
path = test_dir
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, shared_cluster=False)
self.hc_api.clone_helm_chart_repo(
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
subdir="charts/redhat"
)

def teardown_method(self):
self.hc_api.delete_project()

def test_curl_connection(self):
if self.hc_api.oc_api.shared_cluster:
pytest.skip("Do NOT test on shared cluster")
rails_ex_branch = "master"
if VERSION == "3.3":
rails_ex_branch = VERSION
self.hc_api.package_name = "redhat-ruby-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "redhat-ruby-rails-application"
assert self.hc_api.helm_package()
pod_name = f"rails-{VERSION.replace(".", "")}"
assert self.hc_api.helm_installation(
values={
"ruby_version": f"{VERSION}{TAG}",
"namespace": self.hc_api.namespace,
"source_repository_ref": rails_ex_branch,
"source_repository_url": "https://github.com/sclorg/ruby-ex.git",
"name": pod_name,
}
)
assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name, timeout=480)
assert self.hc_api.test_helm_curl_output(
route_name=pod_name,
expected_str="Welcome to your Ruby application"
)

def test_by_helm_test(self):
rails_ex_branch = "master"
if VERSION == "3.3":
rails_ex_branch = VERSION
self.hc_api.package_name = "redhat-ruby-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "redhat-ruby-rails-application"
assert self.hc_api.helm_package()
pod_name = f"rails-{VERSION.replace(".", "")}"
assert self.hc_api.helm_installation(
values={
"ruby_version": f"{VERSION}{TAG}",
"namespace": self.hc_api.namespace,
"source_repository_ref": rails_ex_branch,
"source_repository_url": "https://github.com/sclorg/ruby-ex.git",
"name": pod_name,
}
)
assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name, timeout=480)
assert self.hc_api.test_helm_chart(expected_str=["Welcome to your Ruby application"])
33 changes: 18 additions & 15 deletions test/test_helm_ruby_imagestreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@
OS = os.getenv("TARGET")


class TestHelmRHELRubyImageStreams:
@pytest.fixture(scope="module")
def helm_api(request):
helm_api = HelmChartsAPI(
path=test_dir / "../charts/redhat", package_name="redhat-ruby-imagestreams", tarball_dir=test_dir
)
helm_api.clone_helm_chart_repo(
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
subdir="charts/redhat"
)
# app_name = os.path.basename(request.param)
yield helm_api
pass
helm_api.delete_project()

def setup_method(self):
package_name = "ruby-imagestreams"
path = test_dir
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, remote=True)
self.hc_api.clone_helm_chart_repo(
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
subdir="charts/redhat"
)

def teardown_method(self):
self.hc_api.delete_project()
class TestHelmRHELRubyImageStreams:

@pytest.mark.parametrize(
"version,registry,expected",
Expand All @@ -47,7 +50,7 @@ def teardown_method(self):
("2.5-ubi8", "registry.redhat.io/ubi8/ruby-25:latest", True),
],
)
def test_package_imagestream(self, version, registry, expected):
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
assert self.hc_api.check_imagestreams(version=version, registry=registry) == expected
def test_package_imagestream(self, helm_api, version, registry, expected):
assert helm_api.helm_package()
assert helm_api.helm_installation()
assert helm_api.check_imagestreams(version=version, registry=registry) == expected
41 changes: 41 additions & 0 deletions test/test_rails_ex_standalone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import sys

import pytest

from container_ci_suite.utils import check_variables
from container_ci_suite.openshift import OpenShiftAPI

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")


# Replacement with 'test_python_s2i_app_ex'
class TestS2IRailsExTemplate:

def setup_method(self):
self.oc_api = OpenShiftAPI(pod_name_prefix="ruby-testing", version=VERSION)

def teardown_method(self):
self.oc_api.delete_project()

def test_dancer_ex_template_inside_cluster(self):
service_name = "ruby-testing"
rails_ex_branch = "master"
if VERSION == "3.3":
rails_ex_branch = VERSION
assert self.oc_api.deploy_s2i_app(
image_name=IMAGE_NAME, app=f"https://github.com/sclorg/rails-ex#{rails_ex_branch}",
context=".",
service_name=service_name
)
assert self.oc_api.template_deployed(name_in_template=service_name)
assert self.oc_api.check_response_inside_cluster(
name_in_template=service_name, expected_output="Welcome to your Rails application"
)
9 changes: 3 additions & 6 deletions test/test_ruby_ex_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


# Replacement with 'test_python_s2i_app_ex'
class TestS2IRailsExTemplate:
class TestS2IRubyExTemplate:

def setup_method(self):
self.oc_api = OpenShiftAPI(pod_name_prefix="ruby-testing", version=VERSION)
Expand All @@ -27,15 +27,12 @@ def teardown_method(self):

def test_dancer_ex_template_inside_cluster(self):
service_name = "ruby-testing"
rails_ex_branch = "master"
if VERSION == "3.3":
rails_ex_branch = VERSION
assert self.oc_api.deploy_s2i_app(
image_name=IMAGE_NAME, app=f"https://github.com/sclorg/rails-ex#{rails_ex_branch}",
image_name=IMAGE_NAME, app=f"https://github.com/sclorg/ruby-ex",
context=".",
service_name=service_name
)
assert self.oc_api.template_deployed(name_in_template=service_name)
assert self.oc_api.check_response_inside_cluster(
name_in_template=service_name, expected_output="Welcome to your Rails application"
name_in_template=service_name, expected_output="Welcome to your Ruby application"
)