Skip to content

Commit

Permalink
Move tests (#16)
Browse files Browse the repository at this point in the history
* move tests ouf of main dockerfile
* rename file
* up only sut
* remove tests related to testinfra and python
* copy only necessary folders
  • Loading branch information
aifrak authored Aug 7, 2020
1 parent 9148d82 commit 9b99685
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
21 changes: 0 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,3 @@ COPY --chown=$APP_USER:$APP_USER_GROUP ./config/.zshrc ./config/.p10k.zsh $APP_U
COPY --chown=$APP_USER:$APP_USER_GROUP ./config/aliases.zsh $ZSH_CUSTOM

CMD ["zsh"]

# -------------------------- #
# TESTS #
# -------------------------- #

FROM aifrak/testinfra:5.2.2-python-3.8.5-slim-buster as test-testinfra
FROM base as test-build

# fix issue "/usr/local/bin/python: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory"
ENV LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

ARG DOCKER_TEST_DIR=./docker/test

RUN mkdir -p $DOCKER_TEST_DIR

WORKDIR $DOCKER_TEST_DIR

COPY --from=test-testinfra /usr/local/ /usr/local/
COPY --chown=$APP_USER:$APP_USER_GROUP ./test .

ENTRYPOINT ["pytest"]
17 changes: 17 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM aifrak/testinfra:5.2.2-python-3.8.5-slim-buster as test-testinfra
FROM aifrak/base-image:sut as test-build

# fix issue "/usr/local/bin/python: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory"
ENV LD_LIBRARY_PATH=/usr/local/lib

ARG DOCKER_TEST_DIR=./docker/test

RUN mkdir -p $DOCKER_TEST_DIR

WORKDIR $DOCKER_TEST_DIR

COPY --from=test-testinfra /usr/local/lib /usr/local/lib
COPY --from=test-testinfra /usr/local/bin /usr/local/bin
COPY --chown=$APP_USER:$APP_USER_GROUP ./test .

ENTRYPOINT ["pytest"]
8 changes: 7 additions & 1 deletion docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ services:
sut:
build:
context: .
target: test-build
dockerfile: Dockerfile.test
depends_on:
- base-image
# base image to be tested by sut
base-image:
image: aifrak/base-image:sut
build: .
2 changes: 1 addition & 1 deletion test.sh → test-build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

docker-compose --file docker-compose.test.yml up --build
docker-compose --file docker-compose.test.yml up --build sut
docker-compose --file docker-compose.test.yml down --volumes --remove-orphans --rmi all
12 changes: 0 additions & 12 deletions test/build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
OH_MY_ZSH_PATH = HOME_PATH + '/.oh-my-zsh'


def test_python():
assert platform.python_version() == '3.8.5'


def test_pip_packages(host):
pip_packages = host.pip_package.get_packages

assert pip_packages()['pip']['version'] == '20.1.1'
assert pip_packages()['pytest']['version'] == '5.4.3'
assert pip_packages()['testinfra']['version'] == '5.2.2'


@pytest.mark.parametrize('name,version', [
('git', ''),
('wget', ''),
Expand Down

0 comments on commit 9b99685

Please sign in to comment.