Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adoptium/containers
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: df9f8cffa9bff42d0ced5cf9d18c6707592b015e
Choose a base ref
..
head repository: adoptium/containers
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6c975a47b10723d69abb0ecf7beafacaec09f604
Choose a head ref
Showing with 26 additions and 58 deletions.
  1. +26 −58 test_generate_dockerfiles.py
84 changes: 26 additions & 58 deletions test_generate_dockerfiles.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@


class TestHelperFunctions(unittest.TestCase):

def test_archHelper(self):
test_data = [
("aarch64", "some-os", "aarch64|arm64"),
@@ -16,22 +15,22 @@ def test_archHelper(self):
("arm", "some-os", "armhf|arm"),
("x64", "alpine-linux", "amd64|x86_64"),
("x64", "ubuntu", "amd64|i386:x86-64"),
("random-arch", "some-os", "random-arch")
("random-arch", "some-os", "random-arch"),
]

for arch, os_family, expected in test_data:
self.assertEqual(generate_dockerfiles.archHelper(arch, os_family), expected)

def test_osFamilyHelper(self):
test_data = [
("ubuntu", "linux"),
("centos", "linux"),
("ubi9-minimal", "linux"),
("nanoserver", "windows"),
("servercore", "windows"),
("random-os", "random-os")
("random-os", "random-os"),
]

for os_name, expected in test_data:
self.assertEqual(generate_dockerfiles.osFamilyHelper(os_name), expected)

@@ -44,7 +43,9 @@ def test_fetch_latest_release(self, mock_get):
mock_get.return_value = mock_response

url = "https://api.adoptium.net/v3/assets/feature_releases/some_version/ga?page=0&image_type=some_type&page_size=1&vendor=eclipse"
response = generate_dockerfiles.requests.get(url, headers=generate_dockerfiles.headers)
response = generate_dockerfiles.requests.get(
url, headers=generate_dockerfiles.headers
)
data = response.json()
self.assertIn("key", data[0])
self.assertEqual(data[0]["key"], "value")
@@ -55,19 +56,19 @@ def test_load_config(self, mock_file):
config = generate_dockerfiles.yaml.safe_load(file)
self.assertIn("configurations", config)

class TestJinjaRendering(unittest.TestCase):

class TestJinjaRendering(unittest.TestCase):
def setUp(self):
# Setup the Jinja2 environment
self.env = Environment(loader=FileSystemLoader("docker_templates"))

def test_armhf_ubuntu8_rendering(self):
template_name = "ubuntu.Dockerfile.j2"
template = self.env.get_template(template_name)

arch_data = {}

arch_data['armhf|arm'] = {
arch_data["armhf|arm"] = {
"download_url": "http://fake-url.com",
"checksum": "fake-checksum",
}
@@ -91,10 +92,7 @@ def test_version_checker(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "11",
"image_type": "jdk"
}
context = {"version": "11", "image_type": "jdk"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -103,10 +101,7 @@ def test_version_checker(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "8",
"image_type": "jdk"
}
context = {"version": "8", "image_type": "jdk"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -115,10 +110,7 @@ def test_version_checker(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "11",
"image_type": "jre"
}
context = {"version": "11", "image_type": "jre"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -127,10 +119,7 @@ def test_version_checker(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "8",
"image_type": "jre"
}
context = {"version": "8", "image_type": "jre"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -143,10 +132,7 @@ def test_version_checker_windows(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "11",
"image_type": "jdk"
}
context = {"version": "11", "image_type": "jdk"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -155,10 +141,7 @@ def test_version_checker_windows(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "8",
"image_type": "jdk"
}
context = {"version": "8", "image_type": "jdk"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -167,10 +150,7 @@ def test_version_checker_windows(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "11",
"image_type": "jre"
}
context = {"version": "11", "image_type": "jre"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
@@ -179,56 +159,44 @@ def test_version_checker_windows(self):

with self.subTest():
# The context/variables to render the template
context = {
"version": "8",
"image_type": "jre"
}
context = {"version": "8", "image_type": "jre"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
expected_string = "Write-Host 'javac -version'; javac -version;"
self.assertNotIn(expected_string, rendered_template)


def test_jdk11plus_jshell_cmd(self):
template_name = "partials/jshell.j2"
template = self.env.get_template(template_name)

with self.subTest():
# The context/variables to render the template
context = {
"version": "11",
"image_type": "jdk"
}
context = {"version": "11", "image_type": "jdk"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
expected_string = "CMD [\"jshell\"]"
expected_string = 'CMD ["jshell"]'
self.assertIn(expected_string, rendered_template)

with self.subTest():
# The context/variables to render the template
context = {
"version": "17",
"image_type": "jre"
}
context = {"version": "17", "image_type": "jre"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
expected_string = "CMD [\"jshell\"]"
expected_string = 'CMD ["jshell"]'
self.assertNotIn(expected_string, rendered_template)

with self.subTest():
# The context/variables to render the template
context = {
"version": "8",
"image_type": "jdk"
}
context = {"version": "8", "image_type": "jdk"}
rendered_template = template.render(**context)

# Expected string/partial in the rendered output
expected_string = "CMD [\"jshell\"]"
expected_string = 'CMD ["jshell"]'
self.assertNotIn(expected_string, rendered_template)


if __name__ == "__main__":
unittest.main()