Skip to main content

Manage the infrastructure for running tests against

Project description

Test an application with infrastructure.

teststack.toml

[tests.steps]
ping = "ping -c4 8.8.8.8"
env = "env"
raw = "{posargs}"

[services.database]
image = "postgres:12"

[services.database.ports]
"5432/tcp" = ""

[services.database.environment]
POSTGRES_USER = "bebop"
POSTGRES_PASSWORD = "secret"
POSTGRES_DB = "bebop"

[services.database.export]
SQLALCHEMY_DATABASE_URI = "postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{HOST}:{PORT;5432/tcp}/{POSTGRES_DB}"
POSTGRES_MAIN_USER = "{POSTGRES_USER}"
POSTGRES_MAIN_PASSWORD = "{POSTGRES_USER}"
POSTGRES_MAIN_HOST = "{POSTGRES_USER}"
POSTGRES_MAIN_RDS_HOST = "{POSTGRES_USER}"
POSTGRES_MAIN_PORT = "{PORT;5432/tcp}"
POSTGRES_MAIN_DBNAME = "{POSTGRES_DB}"

There are two main sections: tests and services.

The test section is for information about the docker container that is going to be used for testing. It renders the Dockerfile.j2, and injects environment variables for customization. The tests.steps section specifies which steps should be run on a test machine. Any unprocessed commandline arguments that are passed into teststack are stuck into commands as posargs.

teststack render
teststack build
teststack run -s raw -- pytest -k mytest
teststack stop

The services section specifies the services that need to be started along side a test container. In this example, a postgres container is started. Then the ports specify which ports need to be exposed, so 5432/tcp. And what environment variables should be passed to the service docker container when starting up, so that it can be configured. In this case, we set the username, password and db for the database. The three commands around the services are start, stop and restart, they do what they say.

teststack start
teststack stop
teststack restart

Everything that is set in the environment section is available when exporting. The other special variables that are made available is the HOST of the docker container. By default, the env command exports localhost for the {HOST} variable. And then the port that is exported has the number appended after a semicolon. So if you have specified 5432/tcp as a port for a service container, the variable {PORT;5432/tcp} will be made available for exporting, or to add to connection strings.

If however, the env is being used to start a test container (like run does) the HOST variable will be the default docker network IPAddress of the container, and the port will be just the port, and not adapted to the forwarding port on the Host network.

If you choose to run tests locally, instead of in the tests container, you can export the environment variables for the stack and source them or put them in a file for something like vscode to read.

$ source <(teststack env)
$ teststack env --no-export > .env

Tests

Once I can figure out why github actions do not want to install the commands directory, I will write more tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teststack-0.2.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teststack-0.2.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file teststack-0.2.0.tar.gz.

File metadata

  • Download URL: teststack-0.2.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6

File hashes

Hashes for teststack-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a6068fb48dfa86dc05b9a4bd712c1d73356b346297fd5b13443ef7429865fd3a
MD5 5e5a32e99fa7ae30e892ef93e96a350c
BLAKE2b-256 5809eef87a9adb4efc5e08e83aaa0ca1725d883108286f7257732993ffe1f8ff

See more details on using hashes here.

File details

Details for the file teststack-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: teststack-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6

File hashes

Hashes for teststack-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6828603cf03a5b7f8fc6236b842edf5eb6c15d586df050a1c0023c1a568e6f03
MD5 d1ded6d0aef2ed256894837653e6c962
BLAKE2b-256 0b817418ffbae01708e822f1de9795be1bc867e90d1bf9cd9d9305c1a1cb4bbf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page