Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script that uses docker to execute tests #7

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.6
0.0.7
58 changes: 58 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import docker


def test_healthy_package(client, image):
print("Testing healthy package...")

container = client.containers.run(
image,
volumes={os.getcwd(): {"bind": "/test", "mode": "rw"}},
working_dir="/test/healthypkg/",
entrypoint="nilaway ./...",
detach=True,
)

exit_code = container.wait()
logs = container.logs(stdout=True, stderr=True).decode("utf-8")
print(exit_code, "\n", logs)

container.remove()

assert exit_code["StatusCode"] == 0
assert "Potential nil panic detected" not in logs


def test_unhealthy_package(client, image):
print("Testing unhealthy package...")

container = client.containers.run(
image,
volumes={os.getcwd(): {"bind": "/test", "mode": "rw"}},
working_dir="/test/unhealthypkg/",
entrypoint="nilaway ./...",
detach=True,
)

exit_code = container.wait()
logs = container.logs(stdout=True, stderr=True).decode("utf-8")
print(exit_code, "\n", logs)

container.remove()

assert exit_code["StatusCode"] != 0
assert "Potential nil panic detected" in logs


def main():
client = docker.from_env()
image, _ = client.images.build(path="../", tag="nilaway-action-test-image")

test_healthy_package(client, image)
test_unhealthy_package(client, image)

print("All tests passed!")


if __name__ == "__main__":
main()