|
| 1 | +import os |
| 2 | +import docker |
| 3 | + |
| 4 | + |
| 5 | +def test_healthy_package(client, image): |
| 6 | + print("Testing healthy package...") |
| 7 | + |
| 8 | + container = client.containers.run( |
| 9 | + image, |
| 10 | + volumes={os.getcwd(): {"bind": "/test", "mode": "rw"}}, |
| 11 | + working_dir="/test/healthypkg/", |
| 12 | + entrypoint="nilaway ./...", |
| 13 | + detach=True, |
| 14 | + ) |
| 15 | + |
| 16 | + exit_code = container.wait() |
| 17 | + logs = container.logs(stdout=True, stderr=True).decode("utf-8") |
| 18 | + print(exit_code, "\n", logs) |
| 19 | + |
| 20 | + container.remove() |
| 21 | + |
| 22 | + assert exit_code["StatusCode"] == 0 |
| 23 | + assert "Potential nil panic detected" not in logs |
| 24 | + |
| 25 | + |
| 26 | +def test_unhealthy_package(client, image): |
| 27 | + print("Testing unhealthy package...") |
| 28 | + |
| 29 | + container = client.containers.run( |
| 30 | + image, |
| 31 | + volumes={os.getcwd(): {"bind": "/test", "mode": "rw"}}, |
| 32 | + working_dir="/test/unhealthypkg/", |
| 33 | + entrypoint="nilaway ./...", |
| 34 | + detach=True, |
| 35 | + ) |
| 36 | + |
| 37 | + exit_code = container.wait() |
| 38 | + logs = container.logs(stdout=True, stderr=True).decode("utf-8") |
| 39 | + print(exit_code, "\n", logs) |
| 40 | + |
| 41 | + container.remove() |
| 42 | + |
| 43 | + assert exit_code["StatusCode"] != 0 |
| 44 | + assert "Potential nil panic detected" in logs |
| 45 | + |
| 46 | + |
| 47 | +def main(): |
| 48 | + client = docker.from_env() |
| 49 | + image, _ = client.images.build(path="../", tag="nilaway-action-test-image") |
| 50 | + |
| 51 | + test_healthy_package(client, image) |
| 52 | + test_unhealthy_package(client, image) |
| 53 | + |
| 54 | + print("All tests passed!") |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + main() |
0 commit comments