-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cisagov/improvement/pull_in_upstream_goodies
Pull in pytests from upstream skeleton-docker
- Loading branch information
Showing
1 changed file
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |