60 lines
1.1 KiB
Bash
60 lines
1.1 KiB
Bash
#! /bin/bash
|
|
|
|
main() {
|
|
for t in $(grep ^test_* ./notea_test.sh | sed 's/(.*//'); do
|
|
each
|
|
echo run $t >&2
|
|
if ! eval "$t"; then
|
|
echo failed $t >&2
|
|
fi
|
|
done
|
|
}
|
|
|
|
each() {
|
|
export CACHE=$(mktemp -d)
|
|
source ./notea.sh
|
|
source ./cache.sh
|
|
}
|
|
|
|
test_ids() {
|
|
notea eval "$(cat <<EOF
|
|
ncurl() {
|
|
echo "$*" | grep -q \/api\/tree
|
|
echo '{
|
|
"items": {
|
|
"root": {
|
|
"children": [
|
|
"abc"
|
|
]
|
|
},
|
|
"abc": {
|
|
"id": "def"
|
|
},
|
|
"def": {}
|
|
}
|
|
}'
|
|
}
|
|
ids | wc -l | grep -q 1
|
|
ids | grep -q def
|
|
EOF
|
|
)"
|
|
}
|
|
|
|
test_get() {
|
|
notea eval "$(cat <<EOF
|
|
ncurl() {
|
|
echo "$*" | grep -q \/api\/notes\/abc
|
|
echo 'asdf'
|
|
}
|
|
! cache get "notea cache abc" | grep -q asdf
|
|
get abc | wc -l | grep -q 1
|
|
get abc | grep -q asdf
|
|
cache get "notea cache abc" | grep -q asdf
|
|
EOF
|
|
)"
|
|
}
|
|
|
|
if [ "$0" == "$BASH_SOURCE" ]; then
|
|
main "$@"
|
|
fi
|