From 055951f262664d5d9490f829e79a82e96ad3e780 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 9 Oct 2023 12:32:32 +0300 Subject: [PATCH] add 'stop' test --- api.w | 6 ++++-- test/containers.test.w | 30 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/api.w b/api.w index 941ae33..1ffec59 100644 --- a/api.w +++ b/api.w @@ -1,9 +1,11 @@ interface IWorkload { - /** starts the workload */ + /** starts the container */ inflight start(): void; - /** stops containers */ + /** stops the container */ inflight stop(): void; + + /** if `port` is specified, this includes the external url of the container */ inflight url(): str?; } diff --git a/test/containers.test.w b/test/containers.test.w index 201084a..cfeb253 100644 --- a/test/containers.test.w +++ b/test/containers.test.w @@ -12,10 +12,32 @@ let hello = new containers.Workload( } ); -test "workload started" { +let getBody = inflight (): str? => { if let url = hello.url() { - assert(http.get(url).body?.contains(message) ?? false); - } else { - assert(false); + return http.get(url).body; } + + return nil; +}; + + +test "container started automatically and port exposed" { + let body = getBody(); + assert(body?.contains(message) ?? false); +} + +test "container stopped after stop() is called" { + assert(getBody()?); + + // stop the container and check that there is no body + hello.stop(); + + // check that we can't reach the container + let var error = false; + try { + getBody(); + } catch { + error = true; + } + assert(error); } \ No newline at end of file