generated from actions/container-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script that uses docker to execute tests (#7)
- Loading branch information
1 parent
c45a386
commit 8e11a62
Showing
2 changed files
with
59 additions
and
1 deletion.
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 +1 @@ | ||
0.0.6 | ||
0.0.7 |
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 |
---|---|---|
@@ -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() |