1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00
mpw/test/test_config.rb

82 lines
1.9 KiB
Ruby
Raw Normal View History

2016-11-10 22:57:16 +00:00
#!/usr/bin/ruby
require 'mpw/config'
require 'test/unit'
require 'locale'
require 'i18n'
class TestConfig < Test::Unit::TestCase
def setup
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
2016-11-10 22:57:16 +00:00
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
2016-11-10 22:57:16 +00:00
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = Dir["#{File.expand_path('../../i18n', __FILE__)}/*.yml"]
I18n.default_locale = :en
I18n.locale = lang.to_sym
end
2016-11-10 22:57:16 +00:00
def test_00_config
2017-05-11 20:24:05 +00:00
data = {
gpg_key: 'test@example.com',
lang: 'en',
wallet_dir: '/tmp/test',
gpg_exe: ''
}
2016-11-10 22:57:16 +00:00
@config = MPW::Config.new
@config.setup(data)
@config.load_config
2017-02-26 08:45:19 +00:00
2017-05-11 20:24:05 +00:00
data.each do |k, v|
assert_equal(v, @config.send(k))
end
2017-02-26 08:45:19 +00:00
@config.setup_gpg_key('password', 'test@example.com', 2048)
assert(@config.check_gpg_key?)
end
2017-02-26 08:45:19 +00:00
def test_01_password
2017-05-11 20:24:05 +00:00
data = {
pwd_alpha: false,
pwd_numeric: false,
pwd_special: true,
pwd_length: 32
}
2017-02-26 08:45:19 +00:00
@config = MPW::Config.new
@config.load_config
2017-02-26 08:45:19 +00:00
assert_equal(@config.password[:length], 16)
assert(@config.password[:alpha])
assert(@config.password[:numeric])
assert(!@config.password[:special])
@config.setup(data)
@config.load_config
assert_equal(@config.password[:length], data[:pwd_length])
assert(!@config.password[:alpha])
assert(!@config.password[:numeric])
assert(@config.password[:special])
end
2017-04-08 15:27:56 +00:00
def test_02_wallet_paths
new_path = '/tmp/mpw-test'
@config = MPW::Config.new
@config.load_config
assert(!@config.wallet_paths['default'])
@config.set_wallet_path(new_path, 'default')
assert_equal(@config.wallet_paths['default'], new_path)
@config.set_wallet_path('default', 'default')
assert(!@config.wallet_paths['default'])
end
2016-11-10 22:57:16 +00:00
end