mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: add latest-official docker tag (#25322)
This commit is contained in:
committed by
GitHub
parent
be82657940
commit
26498fc099
44
tests/unit_tests/fixtures/bash_mock.py
Normal file
44
tests/unit_tests/fixtures/bash_mock.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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 subprocess
|
||||
|
||||
|
||||
class BashMock:
|
||||
@staticmethod
|
||||
def tag_latest_release(tag):
|
||||
bash_command = f"./scripts/tag_latest_release.sh {tag} --dry-run"
|
||||
result = subprocess.run(
|
||||
bash_command,
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={"TEST_ENV": "true"},
|
||||
)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def docker_build_push(tag, branch):
|
||||
bash_command = f"./scripts/docker_build_push.sh {tag}"
|
||||
result = subprocess.run(
|
||||
bash_command,
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={"TEST_ENV": "true", "GITHUB_REF": f"refs/heads/{branch}"},
|
||||
)
|
||||
return result
|
||||
44
tests/unit_tests/scripts/docker_build_push_test.py
Normal file
44
tests/unit_tests/scripts/docker_build_push_test.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import re
|
||||
import subprocess
|
||||
from unittest import mock
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.unit_tests.fixtures.bash_mock import BashMock
|
||||
|
||||
original_run = subprocess.run
|
||||
|
||||
|
||||
def wrapped(*args, **kwargs):
|
||||
return original_run(*args, **kwargs)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tag, expected_output, branch",
|
||||
[
|
||||
("1.0.0", "LATEST_TAG is master", "master"),
|
||||
("2.1.0", "LATEST_TAG is master", "master"),
|
||||
("2.1.1", "LATEST_TAG is latest", "master"),
|
||||
("3.0.0", "LATEST_TAG is latest", "master"),
|
||||
("2.1.0rc1", "LATEST_TAG is 2.1.0", "2.1.0"),
|
||||
("", "LATEST_TAG is foo", "foo"),
|
||||
("2.1", "LATEST_TAG is 2.1", "2.1"),
|
||||
("does_not_exist", "LATEST_TAG is does-not-exist", "does_not_exist"),
|
||||
],
|
||||
)
|
||||
def test_tag_latest_release(tag, expected_output, branch):
|
||||
with mock.patch(
|
||||
"tests.unit_tests.fixtures.bash_mock.subprocess.run", wraps=wrapped
|
||||
) as subprocess_mock:
|
||||
result = BashMock.docker_build_push(tag, branch)
|
||||
|
||||
subprocess_mock.assert_called_once_with(
|
||||
f"./scripts/docker_build_push.sh {tag}",
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={"TEST_ENV": "true", "GITHUB_REF": f"refs/heads/{branch}"},
|
||||
)
|
||||
|
||||
assert re.search(expected_output, result.stdout, re.MULTILINE)
|
||||
49
tests/unit_tests/scripts/tag_latest_release_test.py
Normal file
49
tests/unit_tests/scripts/tag_latest_release_test.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import subprocess
|
||||
from unittest import mock
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.unit_tests.fixtures.bash_mock import BashMock
|
||||
|
||||
original_run = subprocess.run
|
||||
|
||||
|
||||
def wrapped(*args, **kwargs):
|
||||
return original_run(*args, **kwargs)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tag, expected_output",
|
||||
[
|
||||
("1.0.0", "This release tag 1.0.0 is older than the latest."),
|
||||
("2.1.0", "Versions are equal\n::set-output name=SKIP_TAG::true"),
|
||||
("2.1.1", "This release tag 2.1.1 is newer than the latest."),
|
||||
("3.0.0", "This release tag 3.0.0 is newer than the latest."),
|
||||
("2.1.0rc1", "This tag 2.1.0rc1 is not a valid release version. Not tagging."),
|
||||
(
|
||||
"",
|
||||
"Missing tag parameter, usage: ./scripts/tag_latest_release.sh <GITHUB_TAG_NAME>",
|
||||
),
|
||||
("2.1", "This tag 2.1 is not a valid release version. Not tagging."),
|
||||
(
|
||||
"does_not_exist",
|
||||
"The tag does_not_exist does not exist. Please use a different tag.\n::set-output name=SKIP_TAG::true",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_tag_latest_release(tag, expected_output):
|
||||
with mock.patch(
|
||||
"tests.unit_tests.fixtures.bash_mock.subprocess.run", wraps=wrapped
|
||||
) as subprocess_mock:
|
||||
result = BashMock.tag_latest_release(tag)
|
||||
|
||||
subprocess_mock.assert_called_once_with(
|
||||
f"./scripts/tag_latest_release.sh {tag} --dry-run",
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={"TEST_ENV": "true"},
|
||||
)
|
||||
|
||||
assert expected_output in result.stdout
|
||||
Reference in New Issue
Block a user