test meta notnotea
parent
6723c77c11
commit
954b8e932e
|
|
@ -1,13 +1,24 @@
|
|||
#! /bin/bash
|
||||
|
||||
notnotea() (
|
||||
_nncurl() {
|
||||
curl -sS "$@"
|
||||
ids() {
|
||||
_recurse_ids "" "$(_tree)"
|
||||
}
|
||||
|
||||
ids() {
|
||||
local tree="$(_nncurl $NNOTEA_ADDR/api/v0/tree)"
|
||||
_recurse_ids "" "$tree"
|
||||
_tree() {
|
||||
local cache_key="notnotea cache _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() {
|
||||
|
|
@ -29,24 +40,10 @@ notnotea() (
|
|||
done
|
||||
}
|
||||
|
||||
ids() {
|
||||
for id in $(_tree_ids); do
|
||||
if ! _is_deleted $id; then
|
||||
echo $id
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
meta() {
|
||||
local cache_key="notea cache meta $1"
|
||||
if cache get "$cache_key"; then
|
||||
return 0
|
||||
fi
|
||||
_meta "$@" | cache put "$cache_key"
|
||||
}
|
||||
|
||||
_meta() {
|
||||
_ncurl $NOTEA_ADDR/api/notes/$1/meta
|
||||
local key="$1"
|
||||
key="${key//\//.Branches.}"
|
||||
_tree | jq -c ".Branches.$key.Leaf"
|
||||
}
|
||||
|
||||
_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" | 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