From 3caf12f4112fa8b9ce136d5e475461e1ffb76508 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 2 Jul 2020 14:36:18 +0800 Subject: Add bats test --- test.bats | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test.bats (limited to 'test.bats') diff --git a/test.bats b/test.bats new file mode 100644 index 0000000..0316236 --- /dev/null +++ b/test.bats @@ -0,0 +1,78 @@ +#!/usr/bin/env bats + +export TOOL_NAME='gist' +export GIST_USER='phamhsieh' +export GIST_API_TOKEN='dd43dc9949a5b4a1d6c7''b779f13af357282016e4' + +@test "Testing ${TOOL_NAME} tool" { + echo "${TOOL_NAME}" +} + +@test "The help command should print usage" { + run ./gist help + + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "${TOOL_NAME}" ]] +} + +@test "Use config command to add configuarion for user" { + run ./gist config user ${GIST_USER} + [ "$status" -eq 0 ] + [ "${lines[0]}" = "user='${GIST_USER}'" ] +} + +@test "Use config command to add configuarion for token" { + run ./gist config token ${GIST_API_TOKEN} + [ "$status" -eq 0 ] + [ "${lines[0]}" = "token=${GIST_API_TOKEN}" ] +} + +@test "The new command should create a new public gist with gist command" { + hint=false run ./gist new --file gist --desc 'Manage gist like a pro' gist + [ "$status" -eq 0 ] + [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]] +} + +@test "The fetch command should fetch user gists" { + hint=false run ./gist fetch + [ "$status" -eq 0 ] + [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]] +} + +@test "The fetch command should fetch starred gists" { + hint=false run ./gist fetch star + [ "$status" -eq 0 ] + echo ${lines[-1]} + [[ "${lines[-1]}" =~ (Not a single valid gist|^ *s[0-9]+ +https://gist.github.com/[0-9a-z]+) ]] +} + +@test "No arguments prints the list of gists" { + hint=false run ./gist + [ "$status" -eq 0 ] + [[ "${lines[-1]}" =~ ([0-9]+ +https://gist.github.com/[0-9a-z]+) ]] +} + +@test "Specify an index to return the path of cloned repo" { + run ./gist 1 --no-action + [ "$status" -eq 0 ] + [[ "${lines[-1]}" =~ (${HOME}/gist/[0-9a-z]+) ]] +} + +@test "The edit command should modify the description of a gist" { + ./gist edit 1 "Modified description" + run ./gist detail 1 + [ "$status" -eq 0 ] + [[ "${lines[0]}" =~ (Modified description$) ]] +} + +@test "The delete command should delete specified gists" { + run ./gist delete 1 --force + [ "$status" -eq 0 ] + [ "${lines[0]}" = '1 deleted' ] +} + +@test "The user command should get the list of public gists from a user" { + run ./gist user defunkt + [ "$status" -eq 0 ] + [[ "${lines[0]}" =~ (https://gist.github.com/[0-9a-z]+ defunkt) ]] +} -- cgit v1.2.3-70-g09d2