Skip to content

Commit

Permalink
test: add describe feature test
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxr authored and t0t07 committed Sep 29, 2021
1 parent 165a81f commit 49e09d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
24 changes: 24 additions & 0 deletions featctl/test/test_describe_feature.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
SDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) && cd "$SDIR" || exit 1
source ./util.sh

init_store
import_sample v1
register_features v1

case='featctl describe feature works'
expected='
Name: price
Group: device
Revision: v1
Status: disabled
Category: batch
ValueType: int(11)
Description: device average price
RevisionsLimit: 3
CreateTime: 2021-09-28T05:59:15Z
ModifyTime: 2021-09-28T05:59:15Z
'
actual=$(featctl describe feature -g device -n price)
ignore_time() { grep -Ev '^(CreateTime|ModifyTime)' <<<"$1"; }
assert_eq "$case" "$(ignore_time "$expected")" "$(ignore_time "$actual")"
11 changes: 6 additions & 5 deletions featctl/test/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ set -euo pipefail
PATH="$SDIR/../build:$HOME/bin:$PATH"

info() { printf "$(date +'%Y/%m/%d %H:%M:%S') [info] %s\n" "$*" >&2; }
erro() { printf "$(date +'%Y/%m/%d %H:%M:%S') [erro] %s\n" "$*" >&2; }
erro() { printf "$(date +'%Y/%m/%d %H:%M:%S') %b[erro]%b %s\n" '\e[0;31m\033[1m' '\e[0m' "$*" >&2; }

BLD=$(tput bold)
RST=$(tput sgr0)
GRN=$(tput setaf 2)
YLW=$(tput setaf 3)

export FEATCTL_HOST=127.0.0.1
export FEATCTL_PORT=4000
Expand All @@ -35,12 +36,12 @@ assert_eq() {
return 0
else
erro "${BLD}${GRN}Failed $case${RST}"
erro "expected:"
echo "${BLD}${YLW}=> expected:${RST}"
echo "$expected"
erro "actual:"
echo "${BLD}${YLW}=> actual:${RST}"
echo "$actual"
erro "diff:"
diff <(echo "$expected" ) <(echo "$actual")
echo "${BLD}${YLW}=> diff:${RST}"
diff --color=auto <(echo "$expected" ) <(echo "$actual")
return 1
fi
}
Expand Down

0 comments on commit 49e09d7

Please sign in to comment.