1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 13:57:52 +00:00
mpw/test/test_config.rb

65 lines
1.5 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]
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
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
def test_00_config
2017-02-26 20:26:23 +00:00
data = { gpg_key: 'test@example.com',
2016-11-10 22:57:16 +00:00
lang: 'en',
wallet_dir: '/tmp/test',
gpg_exe: '',
}
@config = MPW::Config.new
2017-02-26 08:45:19 +00:00
@config.setup(data)
2016-11-10 22:57:16 +00:00
@config.load_config
data.each do |k,v|
assert_equal(v, @config.send(k))
end
@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
data = { password: { alpha: false,
numeric: false,
special: true,
length: 32,
}
}
@config.load_config
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], 32)
assert(!@config.password[:alpha])
assert(!@config.password[:numeric])
assert(@config.password[:special])
end
2016-11-10 22:57:16 +00:00
end