1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 10:43:20 +00:00
mpw/test/test_cli.rb

89 lines
2.5 KiB
Ruby
Raw Normal View History

2017-05-07 15:11:42 +00:00
#!/usr/bin/ruby
require 'fileutils'
2017-05-12 23:04:56 +00:00
require 'i18n'
2017-05-07 15:11:42 +00:00
require 'test/unit'
class TestConfig < Test::Unit::TestCase
def setup
2017-05-12 23:04:56 +00:00
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = ["#{File.expand_path('../../i18n', __FILE__)}/en.yml"]
I18n.locale = :en
2017-05-07 15:11:42 +00:00
@password = 'password'
2017-05-13 10:28:42 +00:00
@fixtures = YAML.load_file(fixture_file)
2017-05-07 15:11:42 +00:00
end
def test_00_init_config
FileUtils.rm_rf("#{Dir.home}/.config/mpw")
FileUtils.rm_rf("#{Dir.home}/.gnupg")
2017-05-10 20:38:35 +00:00
output = %x(echo "#{@password}\n#{@password}" | mpw config --init test@example.com)
2017-05-12 23:04:56 +00:00
assert_match(I18n.t('form.setup_config.valid'), output)
assert_match(I18n.t('form.setup_gpg_key.valid'), output)
2017-05-07 15:11:42 +00:00
end
def test_01_add_item
2017-05-13 10:28:42 +00:00
data = @fixtures['add']
2017-05-07 15:11:42 +00:00
2017-05-10 20:38:35 +00:00
output = %x(
echo #{@password} | mpw add \
2017-05-13 10:28:42 +00:00
--host #{data['host']} \
--port #{data['port']} \
--protocol #{data['protocol']} \
--user #{data['user']} \
--comment '#{data['comment']}' \
--group #{data['group']} \
2017-05-10 20:38:35 +00:00
--random)
puts output
2017-05-12 23:04:56 +00:00
assert_match(I18n.t('form.add_item.valid'), output)
2017-05-10 20:38:35 +00:00
output = %x(echo #{@password} | mpw list)
puts output
2017-05-13 10:28:42 +00:00
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
assert_match(data['user'], output)
assert_match(data['comment'], output)
assert_match(data['group'], output)
2017-05-07 15:11:42 +00:00
end
def test_02_update_item
2017-05-13 10:28:42 +00:00
data = @fixtures['update']
2017-05-07 15:11:42 +00:00
2017-05-10 20:38:35 +00:00
output = %x(
echo #{@password} | mpw update \
2017-05-13 10:28:42 +00:00
-p #{@fixtures['add']['host']} \
--host #{data['host']} \
--port #{data['port']} \
--protocol #{data['protocol']} \
--user #{data['user']} \
--comment '#{data['comment']}' \
--new-group #{data['group']}
2017-05-10 20:38:35 +00:00
)
puts output
2017-05-12 23:04:56 +00:00
assert_match(I18n.t('form.update_item.valid'), output)
2017-05-10 20:38:35 +00:00
output = %x(echo #{@password} | mpw list)
puts output
2017-05-13 10:28:42 +00:00
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
assert_match(data['user'], output)
assert_match(data['comment'], output)
assert_match(data['group'], output)
2017-05-07 15:11:42 +00:00
end
def test_03_delete_item
2017-05-13 10:28:42 +00:00
host = @fixtures['update']['host']
2017-05-07 15:11:42 +00:00
2017-05-10 20:38:35 +00:00
output = %x(echo "#{@password}\ny" | mpw delete -p #{host})
puts output
2017-05-12 23:04:56 +00:00
assert_match(I18n.t('form.delete_item.valid'), output)
2017-05-10 20:38:35 +00:00
output = %x(echo #{@password} | mpw list)
puts output
2017-05-07 15:11:42 +00:00
assert_no_match(/#{host}/, output)
end
end