test meta notnotea
parent
6723c77c11
commit
954b8e932e
|
|
@ -1,13 +1,24 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
notnotea() (
|
notnotea() (
|
||||||
_nncurl() {
|
ids() {
|
||||||
curl -sS "$@"
|
_recurse_ids "" "$(_tree)"
|
||||||
}
|
}
|
||||||
|
|
||||||
ids() {
|
_tree() {
|
||||||
local tree="$(_nncurl $NNOTEA_ADDR/api/v0/tree)"
|
local cache_key="notnotea cache _tree"
|
||||||
_recurse_ids "" "$tree"
|
if cache get "$cache_key"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
__tree "$@" | cache put "$cache_key"
|
||||||
|
}
|
||||||
|
|
||||||
|
__tree() {
|
||||||
|
_nncurl $NNOTEA_ADDR/api/v0/tree
|
||||||
|
}
|
||||||
|
|
||||||
|
_nncurl() {
|
||||||
|
curl -sS "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_recurse_ids() {
|
_recurse_ids() {
|
||||||
|
|
@ -29,24 +40,10 @@ notnotea() (
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
ids() {
|
|
||||||
for id in $(_tree_ids); do
|
|
||||||
if ! _is_deleted $id; then
|
|
||||||
echo $id
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
meta() {
|
meta() {
|
||||||
local cache_key="notea cache meta $1"
|
local key="$1"
|
||||||
if cache get "$cache_key"; then
|
key="${key//\//.Branches.}"
|
||||||
return 0
|
_tree | jq -c ".Branches.$key.Leaf"
|
||||||
fi
|
|
||||||
_meta "$@" | cache put "$cache_key"
|
|
||||||
}
|
|
||||||
|
|
||||||
_meta() {
|
|
||||||
_ncurl $NOTEA_ADDR/api/notes/$1/meta
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_is_deleted() {
|
_is_deleted() {
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,25 @@ test__recurse_ids() {
|
||||||
(notnotea _recurse_ids "" "$two_levels"; true) | tail -n 1 | grep -q '^id\/subid$' || return 102
|
(notnotea _recurse_ids "" "$two_levels"; true) | tail -n 1 | grep -q '^id\/subid$' || return 102
|
||||||
notnotea _recurse_ids "" "$two_levels" | wc -l | grep -q 2 || return 103
|
notnotea _recurse_ids "" "$two_levels" | wc -l | grep -q 2 || return 103
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_meta() {
|
||||||
|
local two_levels='{
|
||||||
|
"Branches": {
|
||||||
|
"id": {
|
||||||
|
"Leaf": {"Title": "top level"},
|
||||||
|
"Branches": {
|
||||||
|
"subid": {
|
||||||
|
"Leaf": {"Title": "sub level"},
|
||||||
|
"Branches": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
notnotea eval "$(cat <<EOF
|
||||||
|
_tree() { echo '$two_levels'; }
|
||||||
|
meta id | jq .Title | grep -q top.level || return 101
|
||||||
|
meta id/subid | jq .Title | grep -q sub.level || return 102
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue