Skip to content

Commit

Permalink
Add script that uses docker to execute some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgospodinow committed Feb 10, 2024
1 parent c45a386 commit 02a43bc
Showing 1 changed file with 58 additions and 0 deletions.
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()

0 comments on commit 02a43bc

Please sign in to comment.