Skip to content

Instantly share code, notes, and snippets.

@johnpena
Created November 25, 2023 14:51
Show Gist options
  • Save johnpena/4623e8911b11e2f9fcce413a6d99c8bf to your computer and use it in GitHub Desktop.
Save johnpena/4623e8911b11e2f9fcce413a6d99c8bf to your computer and use it in GitHub Desktop.
kvtest.bash
#!/usr/bin/env bash
function kvset {
curl -s "localhost:4000/set?$1=$2" > /dev/null
}
function kvget {
url="localhost:4000/get?key=$1"
curl -s "$url" | jq '.value?'
}
function kverr {
url="localhost:4000/get?key=$1"
curl -s "$url" | jq '.message?'
}
function kvtest {
got=$(kvget $1)
expected="\"$2\""
[[ $got == $expected ]] && echo "PASS" || echo "FAIL"
}
kvset "foo" "bar"
kvget "foo"
kvtest "foo" "bar"
kvset "a" "b"
kvset "b" "c"
kvset "c" "d"
kvset "a" "a"
kvtest "a" "a"
kvtest "b" "c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment