Skip to content

Commit

Permalink
[CONSUL-212] Create/update dummy test case using jq or curl as test o…
Browse files Browse the repository at this point in the history
…utput (#17)
  • Loading branch information
cocolavayen authored and ezfepo committed Sep 8, 2022
1 parent 5877849 commit 5561827
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/integration/connect/envoy/Dockerfile-bats-windows
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ RUN choco install openssl -yf
RUN choco install jq -yf

COPY --from=fortio C:\\fortio C:\\fortio
ENV PATH C:\\fortio;%PATH%

ENV PATH C:\\fortio;%PATH%
ENV PATH C:\\Windows\\System32;%PATH%
ENV PATH C:\\ProgramData\\chocolatey\\lib\\jq\\tools;%PATH%
12 changes: 12 additions & 0 deletions test/integration/connect/envoy/case-dummy-bats/dummy-function.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ function dummyFunction {
local LOCAL_VAR=$1
echo $LOCAL_VAR $COMMON_VAR
}

function curlFunction {
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://www.google.com)
echo $STATUS_CODE
}

function jqFunction {
INPUT_RAW_JSON=$1
KEY_TO_FIND=$2
RESULT=$(echo $INPUT_RAW_JSON | jq .$KEY_TO_FIND)
echo $RESULT
}
17 changes: 17 additions & 0 deletions test/integration/connect/envoy/case-dummy-bats/verify_2.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ teardown() {

[ "$status" -eq 100000 ]
}

@test "Test Function with Curl" {
run curlFunction

[ $status -eq 0 ]
[ -n "$output" ]
[ "$output" = "200" ]
}

@test "Test Function with jq" {
local INPUT='{"key1": "Test Value 1", "key2": "Test Value 2"}'
run jqFunction "$INPUT" "key1"

[ $status -eq 0 ]
[ -n "$output" ]
[ "$output" = "\"Test Value 1\"" ]
}
2 changes: 2 additions & 0 deletions test/integration/connect/envoy/docker.windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ verify_1.bats
verify_2.bats
✔ Test with dummyFunction invoked
- Test skipped (skipped)
✔ Test Function with Curl
✔ Test Function with jq

4 tests, 0 failures, 1 skipped
```
Expand Down

0 comments on commit 5561827

Please sign in to comment.