Skip to content

Commit

Permalink
Merge pull request #4 from cisagov/improvement/pull_in_upstream_goodies
Browse files Browse the repository at this point in the history
Pull in pytests from upstream skeleton-docker
  • Loading branch information
dav3r authored Jul 19, 2019
2 parents 1edb636 + 559a3bc commit 63f7f36
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions tests/container_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
#!/usr/bin/env pytest -vs
"""Tests for gophish container."""

import os
import pytest
import time

def test_squat():
"""Test squat."""
pass
READY_MESSAGE = "Starting admin server"
TRAVIS_TAG = os.getenv("TRAVIS_TAG")
VERSION_FILE = "src/version.txt"


def test_container_count(dockerc):
"""Verify the test composition and container."""
# stopped parameter allows non-running containers in results
assert (
len(dockerc.containers(stopped=True)) == 1
), "Wrong number of containers were started."


def test_wait_for_ready(main_container):
"""Wait for container to be ready."""
TIMEOUT = 10
for i in range(TIMEOUT):
if READY_MESSAGE in main_container.logs().decode("utf-8"):
break
time.sleep(1)
else:
raise Exception(
f"Container does not seem ready. "
f'Expected "{READY_MESSAGE}" in the log within {TIMEOUT} seconds.'
)


@pytest.mark.skipif(
TRAVIS_TAG in [None, ""], reason="this is not a release (TRAVIS_TAG not set)"
)
def test_release_version():
"""Verify that release tag version agrees with the module version."""
pkg_vars = {}
with open(VERSION_FILE) as f:
exec(f.read(), pkg_vars) # nosec
project_version = pkg_vars["__version__"]
assert (
TRAVIS_TAG == f"v{project_version}"
), "TRAVIS_TAG does not match the project version"


def test_container_version_label_matches(main_container):
"""Verify the container version label is the correct version."""
pkg_vars = {}
with open(VERSION_FILE) as f:
exec(f.read(), pkg_vars) # nosec
project_version = pkg_vars["__version__"]
assert (
main_container.labels["version"] == project_version
), "Dockerfile version label does not match project version"

0 comments on commit 63f7f36

Please sign in to comment.