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

SAT: verify AIRBYTE_ENTRYPOINT is defined #4478

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
69aa7a6
save changes required for work; TODO locate all places that need to b…
vovavovavovavova Jul 1, 2021
fd4db49
Merge remote-tracking branch 'origin/master' into valdemar/#4262_asse…
vovavovavovavova Jul 1, 2021
1da955d
move new test inside test_spec
vovavovavovavova Jul 1, 2021
075a044
apply suggestions
vovavovavovavova Jul 2, 2021
9b66d50
change return type + add check env = space_joined_entrypoint
vovavovavovavova Jul 2, 2021
ad4274a
requested
vovavovavovavova Jul 2, 2021
472ad1a
add check entrypoint with env
vovavovavovavova Jul 2, 2021
b62ae92
bump SAT --version && changelog update
vovavovavovavova Jul 2, 2021
62f84d5
Merge remote-tracking branch 'origin/master' into valdemar/#4262_asse…
vovavovavovavova Jul 2, 2021
a2ba9b6
merge && fix changelog
vovavovavovavova Jul 2, 2021
b143ad5
changes
vovavovavovavova Jul 5, 2021
b74e6ff
add dynamic docker runner creator + test having properties
vovavovavovavova Jul 6, 2021
076d31e
update the names
vovavovavovavova Jul 6, 2021
d5da978
change names
vovavovavovavova Jul 6, 2021
28505cc
make fixtures
vovavovavovavova Jul 6, 2021
7ab4c81
Merge remote-tracking branch 'origin/master' into valdemar/#4262_asse…
vovavovavovavova Jul 6, 2021
214209b
upd text
vovavovavovavova Jul 6, 2021
d4b6d4f
Update airbyte-integrations/bases/source-acceptance-test/unit_tests/t…
vovavovavovavova Jul 7, 2021
770b508
requested changes
vovavovavovavova Jul 7, 2021
6f52aed
Update airbyte-integrations/bases/source-acceptance-test/unit_tests/t…
vovavovavovavova Jul 7, 2021
b9991f1
Update airbyte-integrations/bases/source-acceptance-test/unit_tests/t…
vovavovavovavova Jul 7, 2021
387493c
apply requested changes
vovavovavovavova Jul 7, 2021
36f76f9
change names (requested)
vovavovavovavova Jul 7, 2021
c6e2bd4
move binary strings to standard with convertation in builder
vovavovavovavova Jul 7, 2021
045c749
fixing merge-conflict side effect
vovavovavovavova Jul 7, 2021
64a811b
resolve new conflict (both)
vovavovavovavova Jul 7, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Add: `test_spec` additionally checks if Dockerfile has `ENV AIRBYTE_ENTRYPOINT`
Add test whether PKs present and not None if `source_defined_primary_key` defined: https://github.com/airbytehq/airbyte/pull/4140

## 0.1.5
Add configurable timeout for the acceptance tests: https://github.com/airbytehq/airbyte/pull/4296
Add configurable timeout for the acceptance tests: https://github.com/airbytehq/airbyte/pull/4296
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def test_match_expected(self, connector_spec: ConnectorSpecification, connector_
if connector_spec:
assert spec_messages[0].spec == connector_spec, "Spec should be equal to the one in spec.json file"

assert docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT"), "AIRBYTE_ENTRYPOINT must be set in dockerfile"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪🏼

assert docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT") == " ".join(
docker_runner.entry_point
), "env should be equal to space-joined entrypoint"

# Getting rid of technical variables that start with an underscore
config = {key: value for key, value in connector_config.data.items() if not key.startswith("_")}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ def run(self, cmd, config=None, state=None, catalog=None, **kwargs) -> Iterable[
yield AirbyteMessage.parse_raw(line)
except ValidationError as exc:
logging.warning("Unable to parse connector's output %s", exc)

@property
def env_variables(self):
env_vars = self._image.attrs["Config"]["Env"]
return {env.split("=", 1)[0]: env.split("=", 1)[1] for env in env_vars}

@property
def entry_point(self):
return self._image.attrs["Config"]["Entrypoint"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# MIT License
#
# Copyright (c) 2020 Airbyte
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

import io

import docker
import pytest
from source_acceptance_test.utils import ConnectorRunner


def build_docker_image(text: str, tag: str) -> docker.models.images.Image:
"""
Really for this test we dont need to remove the image since we access it by a string name
and remove it also by a string name. But maybe we wanna use it somewhere
"""
client = docker.from_env()
fileobj = io.BytesIO(bytes(text, "utf-8"))
image, iterools_tee = client.images.build(fileobj=fileobj, tag=tag, forcerm=True, rm=True)
return image


@pytest.fixture
def correct_connector_image() -> str:
dockerfile_text = """
FROM scratch
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
"""
tag = "my-valid-one"
build_docker_image(dockerfile_text, tag)
yield tag
client = docker.from_env()
client.images.remove(image=tag, force=True)


@pytest.fixture
def connector_image_without_env():
dockerfile_text = """
FROM scratch
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
"""
tag = "my-no-env"
build_docker_image(dockerfile_text, tag)
yield tag
client = docker.from_env()
client.images.remove(image=tag, force=True)


@pytest.fixture
def connector_image_with_ne_properties():
dockerfile_text = """
FROM scratch
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python3", "/airbyte/integration_code/main.py"]
"""
tag = "my-ne-properties"
build_docker_image(dockerfile_text, tag)
yield tag
client = docker.from_env()
client.images.remove(image=tag, force=True)


class TestEnvAttributes:
def test_correct_connector_image(self, correct_connector_image, tmp_path):
docker_runner = ConnectorRunner(image_name=correct_connector_image, volume=tmp_path)
assert docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT"), "AIRBYTE_ENTRYPOINT must be set in dockerfile"
assert docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT") == " ".join(
docker_runner.entry_point
), "env should be equal to space-joined entrypoint"

def test_connector_image_without_env(self, connector_image_without_env, tmp_path):
docker_runner = ConnectorRunner(image_name=connector_image_without_env, volume=tmp_path)
assert not docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT"), "this test should fail if AIRBYTE_ENTRYPOINT defined"

def test_docker_image_env_ne_entrypoint(self, connector_image_with_ne_properties, tmp_path):
docker_runner = ConnectorRunner(image_name=connector_image_with_ne_properties, volume=tmp_path)
assert docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT"), "AIRBYTE_ENTRYPOINT must be set in dockerfile"
assert docker_runner.env_variables.get("AIRBYTE_ENTRYPOINT") != " ".join(docker_runner.entry_point), (
"This test should fail if we have " ".join(ENTRYPOINT)==ENV"
)