test/subutai_config_test.rb in vagrant-subutai-7.0.2 vs test/subutai_config_test.rb in vagrant-subutai-7.0.3
- old
+ new
@@ -1,10 +1,11 @@
require 'rubygems'
require 'test/unit'
require 'fileutils'
-require_relative '../lib/subutai_cli/packer/subutai_config'
+require_relative '../lib/vagrant-subutai/packer/subutai_config'
+require_relative '../lib/vagrant-subutai/put'
# Tests the SubutaiConfig module
class SubutaiConfigTest < Test::Unit::TestCase
# Called before every test method runs. Can be used
# to set up fixture information.
@@ -73,11 +74,11 @@
assert_path_exist(SubutaiConfig::GENERATED_FILE, 'generated.yaml')
SubutaiConfig.load_config('destroy', :virtualbox)
assert_path_exist(SubutaiConfig::GENERATED_FILE, 'generated.yaml')
- SubutaiConfig.cleanup
+ SubutaiConfig.cleanup!
assert_path_not_exist(SubutaiConfig::GENERATED_FILE, 'generated.yaml')
end
def test_get_put_up
SubutaiConfig.load_config('up', :virtualbox)
@@ -255,47 +256,56 @@
SubutaiConfig.load_config('up', :virtualbox)
SubutaiConfig.put('foo', 'bar', true)
end
end
+ def test_not_raise
+ assert_nothing_raised do
+ SubutaiConfig.override_conf_file('./test/subutai-validation-0.yml')
+ SubutaiConfig.load_config('up', :virtualbox)
+ end
+ end
+
def test_bad_env_subutai_yaml_0
- SubutaiConfig.override_conf_file('./ruby/tests/subutai0.yaml')
assert_raise do
+ SubutaiConfig.override_conf_file('./test/subutai0.yaml')
SubutaiConfig.load_config('up', :virtualbox)
end
end
def test_bad_key_subutai_yaml_1
- SubutaiConfig.override_conf_file('./ruby/tests/subutai1.yaml')
assert_raise do
+ SubutaiConfig.override_conf_file('./test/subutai1.yaml')
SubutaiConfig.load_config('up', :virtualbox)
end
end
def test_subutai_yaml_2
- SubutaiConfig.override_conf_file('./ruby/tests/subutai2.yaml')
+ SubutaiConfig.override_conf_file('./test/subutai2.yaml')
SubutaiConfig.load_config('up', :virtualbox)
SubutaiConfig.logging!(:debug)
SubutaiConfig.print
SubutaiConfig.log('up', 'dummy message')
SubutaiConfig.log_mode([:debug], ['up'], 'dummy message')
+ SubutaiConfig.print
assert_equal(:master, SubutaiConfig.get(:SUBUTAI_ENV))
assert_equal(9191, SubutaiConfig.get(:DESIRED_CONSOLE_PORT))
assert_equal(2000, SubutaiConfig.get(:SUBUTAI_RAM))
assert_equal(6, SubutaiConfig.get(:SUBUTAI_CPU))
assert_false(SubutaiConfig.get(:SUBUTAI_PEER))
assert_true(SubutaiConfig.get(:SUBUTAI_DESKTOP))
assert_true(SubutaiConfig.get(:ALLOW_INSECURE))
- assert_equal('./bar/foo/bogus/path/to/deb/pkg/management.deb', SubutaiConfig.get(:SUBUTAI_MAN_TMPL))
+ assert_equal('./test/management_test_file.deb', SubutaiConfig.get(:SUBUTAI_MAN_TMPL))
if ENV['APT_PROXY_URL'].nil?
assert_equal('http://some_server:4444', SubutaiConfig.get(:APT_PROXY_URL))
else
assert_equal(ENV['APT_PROXY_URL'], SubutaiConfig.get(:APT_PROXY_URL))
end
end
+
def test_boolean?
SubutaiConfig.load_config('up', :virtualbox)
assert_true(SubutaiConfig.boolean?(:SUBUTAI_PEER))
assert_false(SubutaiConfig.boolean?(:SUBUTAI_DESKTOP))
assert_raise do
@@ -325,55 +335,146 @@
configs = SubutaiConfig.config
# Make it all negative for provisioning conditions
configs.store(:PROVISION, false)
configs.store(:_ALT_MANAGEMENT, nil)
- configs.store(:_ALT_MANAGEMENT_MD5, '6fc87ffd922973f8c88fd939fc091885')
- configs.store(:_ALT_MANAGEMENT_MD5_LAST, '6fc87ffd922973f8c88fd939fc091885')
+ configs.store(:_ALT_MANAGEMENT_MD5, 'd41d8cd98f00b204e9800998ecf8427e')
+ configs.store(:_ALT_MANAGEMENT_MD5_LAST, 'd41d8cd98f00b204e9800998ecf8427e')
assert_false(SubutaiConfig.provision_management?)
configs.store(:PROVISION, true)
configs.store(:_ALT_MANAGEMENT, nil)
- configs.store(:_ALT_MANAGEMENT_MD5, '6fc87ffd922973f8c88fd939fc091885')
- configs.store(:_ALT_MANAGEMENT_MD5_LAST, '6fc87ffd922973f8c88fd939fc091885')
+ configs.store(:_ALT_MANAGEMENT_MD5, 'd41d8cd98f00b204e9800998ecf8427e')
+ configs.store(:_ALT_MANAGEMENT_MD5_LAST, 'd41d8cd98f00b204e9800998ecf8427e')
assert_false(SubutaiConfig.provision_management?)
configs.store(:PROVISION, true)
- configs.store(:_ALT_MANAGEMENT, './ruby/tests/snap_script.sh')
- configs.store(:_ALT_MANAGEMENT_MD5, '6fc87ffd922973f8c88fd939fc091885')
- configs.store(:_ALT_MANAGEMENT_MD5_LAST, '6fc87ffd922973f8c88fd939fc091885')
+ configs.store(:_ALT_MANAGEMENT, './snap_script.sh')
+ configs.store(:_ALT_MANAGEMENT_MD5, 'd41d8cd98f00b204e9800998ecf8427e')
+ configs.store(:_ALT_MANAGEMENT_MD5_LAST, 'd41d8cd98f00b204e9800998ecf8427e')
assert_false(SubutaiConfig.provision_management?)
configs.store(:PROVISION, true)
- configs.store(:_ALT_MANAGEMENT, './ruby/tests/snap_script.sh')
- configs.store(:_ALT_MANAGEMENT_MD5, '6fc87ffd922973f8c88fd939fc091885')
+ configs.store(:_ALT_MANAGEMENT, './snap_script.sh')
+ configs.store(:_ALT_MANAGEMENT_MD5, 'd41d8cd98f00b204e9800998ecf8427e')
configs.store(:_ALT_MANAGEMENT_MD5_LAST, nil)
assert_false(SubutaiConfig.provision_management?)
SubutaiConfig.load_config('ssh', :virtualbox)
puts configs
configs.store(:PROVISION, true)
puts configs
- configs.store(:_ALT_MANAGEMENT, './ruby/tests/snap_script.sh')
- configs.store(:_ALT_MANAGEMENT_MD5, '6fc87ffd922973f8c88fd939fc091885')
+ configs.store(:_ALT_MANAGEMENT, './test/snap_script.sh')
+ configs.store(:_ALT_MANAGEMENT_MD5, 'd41d8cd98f00b204e9800998ecf8427e')
configs.store(:_ALT_MANAGEMENT_MD5_LAST, nil)
- assert_true(SubutaiConfig.provision_management?)
+ assert_false(SubutaiConfig.provision_management?)
SubutaiConfig.management_provisioned!
end
def test_do_handlers
SubutaiConfig.load_config('ssh', :virtualbox)
configs = SubutaiConfig.config
assert_false(SubutaiConfig.do_handlers)
SubutaiConfig.load_config('up', :virtualbox)
- configs.store(:SUBUTAI_MAN_TMPL, './ruby/tests/snap_script.sh')
+ configs.store(:SUBUTAI_MAN_TMPL, './test/snap_script.sh')
assert_true(SubutaiConfig.do_handlers)
- configs.store(:SUBUTAI_MAN_TMPL, './ruby/tests/bad_snap_script.sh')
+ configs.store(:SUBUTAI_MAN_TMPL, './test/bad_snap_script.sh')
assert_raise do
SubutaiConfig.do_handlers
end
+ end
+
+ def test_get_latest_artifact
+ assert_equal('https://cdn.subutai.io:8338/kurjun/rest', SubutaiConfig.url_of_cdn)
+
+ SubutaiConfig.load_config("up", :libvirt)
+ assert_equal("", SubutaiConfig.get_latest_id_artifact("invalid", "vagrant-subutai-stretch-libvirt.box"))
+
+ SubutaiConfig.cleanup!
+
+ SubutaiConfig.load_config("destroy", :hyper_v)
+ assert_equal("", SubutaiConfig.get_latest_id_artifact("subutai", "vagrant-subutai-stretch-hyperv.box"))
+
+ SubutaiConfig.cleanup!
+
+ SubutaiConfig.url_of_cdn = 'https://cdn.subutai.io:8338/kurjun/rest/invalid'
+ assert_equal('https://cdn.subutai.io:8338/kurjun/rest/invalid', SubutaiConfig.url_of_cdn)
+
+ SubutaiConfig.load_config("up", :virtualbox)
+ SubutaiConfig.url_of_cdn = 'https://cdn.subutai.io:8338/kurjun/rest/invalid'
+ assert_equal("", SubutaiConfig.get_latest_id_artifact("subutai", "vagrant-subutai-stretch-virtualbox-master.box"))
+ end
+
+ def test_get
+ SubutaiConfig.load_config("up", :virtualbox)
+
+ assert_equal(nil, SubutaiConfig.get(:INVALID_KEY))
+ end
+
+ def test_set_scope
+ assert_raise do
+ SubutaiConfig.set_scope(:SUBUTAI_SCOPE, "public_incorrect")
+ end
+
+ assert_nothing_raised do
+ SubutaiConfig.set_scope(:SUBUTAI_SCOPE, 'PubLiC'.to_sym)
+ SubutaiConfig.set_scope(:SUBUTAI_SCOPE, 'PriVate'.to_sym)
+ end
+ end
+
+ def test_write
+ SubutaiConfig.load_config("up", :libvirt)
+ assert_true(SubutaiConfig.write?)
+ SubutaiConfig.cleanup!
+
+ SubutaiConfig.load_config("destroy", :virtualbox)
+ assert_false(SubutaiConfig.write?)
+ end
+
+ def test_reload
+ SubutaiConfig.load_config("reload", :virtualbox)
+ assert_true(SubutaiConfig.reload?)
+
+ SubutaiConfig.cleanup!
+ SubutaiConfig.load_config("up", :libvirt)
+ assert_false(SubutaiConfig.reload?)
+ end
+
+ def test_delete
+ SubutaiConfig.load_config("destroy", :vmware)
+ assert_true(SubutaiConfig.delete?)
+
+ SubutaiConfig.cleanup!
+
+ SubutaiConfig.load_config("up", :vmware)
+ assert_false(SubutaiConfig.delete?)
+ end
+
+ def test_read
+ SubutaiConfig.load_config("up", :vmware)
+ assert_false(SubutaiConfig.read?)
+
+ SubutaiConfig.cleanup!
+
+ SubutaiConfig.load_config("provision", :vmware)
+ assert_true(SubutaiConfig.read?)
+ end
+
+ def test_conf_file
+ puts "conf file: #{SubutaiConfig::CONF_FILE}"
+ assert_equal(SubutaiConfig::CONF_FILE, SubutaiConfig.conf_file)
+ SubutaiConfig.override_conf_file "./test/vagrant-subutai-disk-withoutpath.yml"
+ assert_equal("./test/vagrant-subutai-disk-withoutpath.yml", SubutaiConfig.conf_file)
+ end
+
+ def test_provider
+ SubutaiConfig.load_config('up', :hyper_v)
+ assert_equal(:hyper_v, SubutaiConfig.provider)
+
+ SubutaiConfig.reset
+ assert_equal(nil, SubutaiConfig.provider)
end
end