2016-02-06 13:54:19 -05:00
|
|
|
test_description='plugin loading works'
|
|
|
|
. '../test-lib.bash'
|
|
|
|
|
2020-12-02 18:49:36 -05:00
|
|
|
test_expect_success 'setup 1' '
|
2016-02-06 13:54:19 -05:00
|
|
|
cat > ${DOTFILES}/test.py <<EOF
|
|
|
|
import dotbot
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
class Test(dotbot.Plugin):
|
|
|
|
def can_handle(self, directive):
|
|
|
|
return directive == "test"
|
|
|
|
|
|
|
|
def handle(self, directive, data):
|
|
|
|
with open(os.path.expanduser("~/flag"), "w") as f:
|
|
|
|
f.write("it works")
|
|
|
|
return True
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
2020-12-02 18:49:36 -05:00
|
|
|
test_expect_success 'run 1' '
|
2018-05-24 12:00:13 -04:00
|
|
|
run_dotbot --plugin ${DOTFILES}/test.py <<EOF
|
2016-02-06 13:54:19 -05:00
|
|
|
- test: ~
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
2020-12-02 18:49:36 -05:00
|
|
|
test_expect_success 'test 1' '
|
|
|
|
grep "it works" ~/flag
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup 2' '
|
|
|
|
rm ${DOTFILES}/test.py;
|
|
|
|
cat > ${DOTFILES}/test.py <<EOF
|
|
|
|
import dotbot
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
class Test(dotbot.Plugin):
|
|
|
|
def can_handle(self, directive):
|
|
|
|
return directive == "test"
|
|
|
|
|
|
|
|
def handle(self, directive, data):
|
|
|
|
self._log.debug("Attempting to get options from Context")
|
|
|
|
options = self._context.options()
|
|
|
|
if len(options.plugins) != 1:
|
|
|
|
self._log.debug("Context.options.plugins length is %i, expected 1" % len(options.plugins))
|
|
|
|
return False
|
|
|
|
if not options.plugins[0].endswith("test.py"):
|
|
|
|
self._log.debug("Context.options.plugins[0] is %s, expected end with test.py" % options.plugins[0])
|
|
|
|
return False
|
|
|
|
|
|
|
|
with open(os.path.expanduser("~/flag"), "w") as f:
|
|
|
|
f.write("it works")
|
|
|
|
return True
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'run 2' '
|
|
|
|
run_dotbot --plugin ${DOTFILES}/test.py <<EOF
|
|
|
|
- test: ~
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test 2' '
|
2016-02-06 13:54:19 -05:00
|
|
|
grep "it works" ~/flag
|
|
|
|
'
|