From eb2d60562c998fb05b4a229988c94abc61657d6f Mon Sep 17 00:00:00 2001 From: Vedant Padwal <79689323+js-ts@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:23:28 +0530 Subject: [PATCH 1/2] Add simple tests --- test/get-results.sh | 16 ++++++++++++++++ test/hello-world-docker-v2.sh | 14 ++++++++++++++ test/list_nodes.sh | 12 ++++++++++++ testdata/jobs/docker-hello.yaml | 14 ++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 test/get-results.sh create mode 100644 test/hello-world-docker-v2.sh create mode 100644 test/list_nodes.sh create mode 100644 testdata/jobs/docker-hello.yaml diff --git a/test/get-results.sh b/test/get-results.sh new file mode 100644 index 0000000000..62687020f1 --- /dev/null +++ b/test/get-results.sh @@ -0,0 +1,16 @@ +#!bin/bashtub + +source bin/bacalhau.sh + +testcase_can_get_results() { + # Assuming create_node is a function that takes two arguments separated by space, not comma + create_node requester,compute + + job_id=$(bacalhau job run --id-only $ROOT/testdata/jobs/docker-output.yaml) + bacalhau get $job_id > /dev/null 2>&1 + subject cat job-*/output_custom/output.txt + assert_equal 0 $status + assert_match "15" $(echo $stdout) + assert_equal '' $stderr + rm -rf job-* +} \ No newline at end of file diff --git a/test/hello-world-docker-v2.sh b/test/hello-world-docker-v2.sh new file mode 100644 index 0000000000..217271cc02 --- /dev/null +++ b/test/hello-world-docker-v2.sh @@ -0,0 +1,14 @@ +#!bin/bashtub + +source bin/bacalhau.sh + +testcase_can_run_docker_hello_world() { + # Assuming create_node is a function that takes two arguments separated by space, not comma + create_node requester,compute + + # source $BACALHAU_DIR/bacalhau.run + subject bacalhau job run --follow $ROOT/testdata/jobs/docker-hello.yaml + assert_equal 0 $status + assert_match "Hello Bacalhau!" $(echo $stdout) + assert_equal '' $stderr +} \ No newline at end of file diff --git a/test/list_nodes.sh b/test/list_nodes.sh new file mode 100644 index 0000000000..7edda85081 --- /dev/null +++ b/test/list_nodes.sh @@ -0,0 +1,12 @@ +#!bin/bashtub + +source bin/bacalhau.sh + +testcase_can_list_nodes_and_count() { + create_node requester,compute + + subject bacalhau node list --output json + assert_equal 0 $status + assert_match '1' $(echo $stdout | jq '. | length') + assert_equal '' $stderr +} \ No newline at end of file diff --git a/testdata/jobs/docker-hello.yaml b/testdata/jobs/docker-hello.yaml new file mode 100644 index 0000000000..24bde0ea66 --- /dev/null +++ b/testdata/jobs/docker-hello.yaml @@ -0,0 +1,14 @@ +name: A Simple Docker Job +type: batch +count: 1 +tasks: + - name: My main task + engine: + type: docker + params: + Image: ubuntu:latest + Entrypoint: + - /bin/bash + Parameters: + - -c + - echo Hello Bacalhau! \ No newline at end of file From a516adf58f5367507e6f09736f0445ee185844bb Mon Sep 17 00:00:00 2001 From: Vedant Padwal <79689323+js-ts@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:23:37 +0530 Subject: [PATCH 2/2] made chsnges as simon suggested --- test/get-results.sh | 2 +- test/hello-world-docker-v2.sh | 3 +-- test/list_nodes.sh | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/get-results.sh b/test/get-results.sh index 62687020f1..355925ec65 100644 --- a/test/get-results.sh +++ b/test/get-results.sh @@ -12,5 +12,5 @@ testcase_can_get_results() { assert_equal 0 $status assert_match "15" $(echo $stdout) assert_equal '' $stderr - rm -rf job-* + rm -rf job-${job_id%%-*} } \ No newline at end of file diff --git a/test/hello-world-docker-v2.sh b/test/hello-world-docker-v2.sh index 217271cc02..32badaeda9 100644 --- a/test/hello-world-docker-v2.sh +++ b/test/hello-world-docker-v2.sh @@ -3,10 +3,9 @@ source bin/bacalhau.sh testcase_can_run_docker_hello_world() { - # Assuming create_node is a function that takes two arguments separated by space, not comma + # Assuming create_node is a function that takes two arguments separated by comma, not space create_node requester,compute - # source $BACALHAU_DIR/bacalhau.run subject bacalhau job run --follow $ROOT/testdata/jobs/docker-hello.yaml assert_equal 0 $status assert_match "Hello Bacalhau!" $(echo $stdout) diff --git a/test/list_nodes.sh b/test/list_nodes.sh index 7edda85081..407fda62c5 100644 --- a/test/list_nodes.sh +++ b/test/list_nodes.sh @@ -7,6 +7,6 @@ testcase_can_list_nodes_and_count() { subject bacalhau node list --output json assert_equal 0 $status - assert_match '1' $(echo $stdout | jq '. | length') + assert_match '1' $(echo $stdout | jq length) assert_equal '' $stderr } \ No newline at end of file