Files
container.training/slides/k8s/testing.md
2020-01-27 13:42:02 +01:00

1.5 KiB

Testing

There multiple levels of testing. At this point we will focus on

unit-testing, (Just Say No to More End-to-End Tests)

where system interaction are ideally mocked everywhere (no real database, no real backend).

Sadly this is easier said that to be done...


Multi-stage build

FROM <baseimage>
RUN <install dependencies>
COPY <code>
RUN <build code>
RUN <install test dependencies>
COPY <test data sets and fixtures>
RUN <unit tests>
FROM <baseimage>
RUN <install dependencies>
COPY <code>
RUN <build code>
CMD, EXPOSE ...
  • If code don't change, test don't run, leveraging the docker cache

  • Could use docker build --network to make database or backend available during build

  • But no artifact(image) generated if build fails


Docker Compose

version: 3
service:
  project:
    image: my_image_name
    build:
      context: .
      target: dev

  database:
    image: redis
  backend:
    image: backend

docker-compose build && docker-compose run project pytest -v

Skaffold/Container-structure-test

  • The test field of the skaffold.yaml instructs skaffold to run test against your image.

  • It uses the container-structure-test

  • It allows to run custom command

  • Sadly nothing to run other docker image to make a database or a backend reachable