oh-my-fish/plugins/dpaste/tests/test_dpaste.fish

110 lines
2.4 KiB
Fish
Raw Normal View History

2014-06-11 19:08:51 +00:00
#!/usr/bin/env fish
2014-11-25 20:47:58 +00:00
# vim: ai ts=2 sw=2 et sts=2
function echo_text
set -g __test_text 'Hello, tests! I am just testing suite for oh-my-fish plugin: https://github.com/bpinto/oh-my-fish/pull/170'
echo -e $__test_text
end
function curl
command curl --silent $argv
end
function curl_and_check
assert_equal $argv[2..-1] (curl $argv[1])
end
function curl_and_fail
assert_match '.*404 Not found.*' (curl $argv[1])
end
function test_dpaste_system
set url (eval $argv[1])/raw
curl_and_check $url (echo_text)
# now it shouldn't be available
curl_and_fail $url
end
function dpaste_setup
set -g test_dir /tmp/dpaste_test
set -g test_file $test_dir/file
mkdir -p $test_dir
pushd
cd $test_dir
echo_text > $test_file
end
function dpaste_teardown
rm -rf $test_dir
popd
end
2014-06-11 19:08:51 +00:00
function suite_dpaste
2014-06-11 19:08:51 +00:00
function setup
set dpaste_site 'dpaste.de'
2014-06-11 19:08:51 +00:00
__dpaste_set_defaults
end
function test_dpaste_parse_expires
assert_equal text (__dpaste_parse_expires text)
assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
end
function test_dpaste_parse_expires_1
assert_equal text (__dpaste_parse_expires -t 1 text)
assert_equal "https://dpaste.de/api/?format=url&expires=onetime" $__dpaste_send_url
end
function test_dpaste_parse_expires_hour
2014-06-11 19:50:29 +00:00
assert_equal text (__dpaste_parse_expires -t hour text)
assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
end
function test_dpaste_parse_expires_never
assert_equal text (__dpaste_parse_expires -t never text)
assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
2014-06-11 19:08:51 +00:00
end
2014-11-25 20:47:58 +00:00
function test_dpaste_system_file_redirect
function dpaste_file_redirect
dpaste -t onetime < /tmp/dpaste_test/file
end
test_dpaste_system dpaste_file_redirect
end
function test_dpaste_system_file
function dpaste_file
dpaste -t onetime /tmp/dpaste_test/file
end
test_dpaste_system dpaste_file
end
function test_dpaste_system_stdin
function dpaste_stdin
echo_text | dpaste -t onetime
end
test_dpaste_system dpaste_stdin
end
function test_dpaste_system_text
function dpaste_text
dpaste -t onetime "$__test_text"
end
test_dpaste_system dpaste_text
end
2014-06-11 19:08:51 +00:00
end
2014-11-25 20:47:58 +00:00
2014-06-11 19:08:51 +00:00
if not set -q tank_running
source (dirname (status -f))/helper.fish
set -g __dpaste_expires_choises
source (dirname (status -f))/../dpaste.fish
2014-11-25 20:47:58 +00:00
dpaste_setup
2014-06-11 19:08:51 +00:00
tank_run
2014-11-25 20:47:58 +00:00
dpaste_teardown
2014-06-11 19:08:51 +00:00
end