Commit ba5643d0 authored by Volker Hilsheimer's avatar Volker Hilsheimer

Redesign testing to run actual load codepaths

Just overwrite location of config files to load, and move them around
accordingly. Create some dummy roles to silence warnings.

Store aggregated result in global variable that we can use in tests.

Fix bug in loader - de-duplicate arrays after merging.
parent ceece2f7
......@@ -21,6 +21,7 @@ def merge_yaml(first, second)
result = first.clone
result << second
end
result = result.uniq
return result
end
......@@ -76,21 +77,19 @@ def load_urls(yaml, user_yaml)
yaml["urls"] = $urls
end
def load_boxes(yaml, user_yaml, include_defaults)
def load_boxes(yaml, user_yaml)
machines = yaml["machines"]
if include_defaults
defaults = yaml["settings"]["defaults"]
unless defaults.nil?
defaults.each do |setting, value|
# make deep copies
default_value = value.dup
machines.each do |machine|
if machine[setting].nil?
machine[setting] = default_value
else
machine[setting] = merge_yaml(default_value, machine[setting])
end
defaults = $settings["defaults"]
unless defaults.nil?
defaults.each do |setting, value|
# make deep copies
default_value = value.dup
machines.each do |machine|
if machine[setting].nil?
machine[setting] = default_value
else
machine[setting] = merge_yaml(default_value, machine[setting])
end
end
end
......@@ -167,11 +166,12 @@ end
def load_minicoin()
begin # see tests/autotest.rb
return load_testmachines()["machines"]
load_testmachines()
rescue NoMethodError => error # Not running autotest, continue
rescue => error
raise
end
global_file = File.join($PWD, 'minicoin.yml')
yaml = YAML.load_file(global_file)
......@@ -193,16 +193,17 @@ def load_minicoin()
yaml = load_includes(yaml, $PWD)
user_yaml = load_includes(user_yaml, $HOME)
local_yaml = load_includes(local_yaml, project_dir)
load_settings(yaml, user_yaml)
load_settings(yaml, local_yaml)
machines = load_boxes(yaml, user_yaml, true)
machines = load_boxes(yaml, local_yaml, false)
machines = load_boxes(yaml, user_yaml)
machines = load_boxes(yaml, local_yaml)
merge_roles(machines)
load_urls(yaml, user_yaml)
load_urls(yaml, local_yaml)
$TEST_OUTPUT=yaml
return machines
end
\ No newline at end of file
end
......@@ -3,30 +3,9 @@ require_relative "../lib/mock.rb"
Vagrant = MockVagrant.new
def load_testmachines()
root = File.join($PWD, "tests")
test_file = File.join(root, "test.yml")
user_file = File.join(root, "user.yml")
test_output = YAML.load_file(test_file)
user_output = YAML.load_file(user_file)
if !test_output
test_output = nil
end
if !user_output
user_output = nil
end
test_output = load_includes(test_output, root)
user_output = load_includes(user_output, root)
load_settings(test_output, user_output)
machines = load_boxes(test_output, user_output, true)
merge_roles(machines)
load_urls(test_output, user_output)
return test_output
$PWD = File.join($PWD, "tests")
$HOME = File.join($PWD, "user")
ENV['MINICOIN_PROJECT_DIR'] = File.join($PWD, "local")
end
class Tester
......@@ -95,7 +74,7 @@ class Tester
end
def test_loading()
test_output = load_testmachines()
test_output = $TEST_OUTPUT
test_data = {
"settings" => {
"single" => "subsub",
......@@ -103,8 +82,8 @@ class Tester
"global" => "user",
"list" => ["user1", "user2"],
"home_share" => "$HOME",
"defaults" => { "shared_folders" => [{ "Host" => "Guest" }]},
"newvalue" => "local_option",
"defaults" => {}
},
"urls" => {
"domain" => ["domain1", "domain2", "subdomain1", "subdomain2", "leaf1", "leaf2", "userserver"],
......@@ -112,20 +91,23 @@ class Tester
},
"includes" => ["include/sub.yml"],
"machines" => [
{"name" => "machine1", "box" => "generic", "gui" => false },
{"name" => "machine2", "box" => "generic2"},
{"name" => "override", "gui" => true},
{"name" => "environment1", "box" => "$USER"},
{"name" => "environment2", "box" => "private/$minicoin_key/box"},
{"name" => "machine1", "box" => "generic", "gui" => false, "shared_folders"=>[{"Host"=>"Guest"}], "index" => 0, "os" => "macos", "nictype1" => "82545EM", "nictype2" => "82545EM", "actual_shared_folders"=>[] },
{"name" => "machine2", "box" => "generic2", "shared_folders"=>[{"Host"=>"Guest"}], "index" => 1, "os" => "macos", "nictype1" => "82545EM", "nictype2" => "82545EM", "actual_shared_folders"=>[] },
{"name" => "override", "gui" => true, "shared_folders"=>[{"Host"=>"Guest"}], "index"=>2},
{"name" => "environment1", "box" => "$USER", "shared_folders"=>[{"Host"=>"Guest"}], "index"=>3, "os"=>"linux", "nictype2"=>nil, "actual_shared_folders"=>[{"Host"=>"Guest"}]},
{"name" => "environment2", "box" => "private/$minicoin_key/box", "shared_folders"=>[{"Host"=>"Guest"}], "index"=>4, "os"=>"linux", "nictype2"=>nil, "actual_shared_folders"=>[{"Host"=>"Guest"}]},
{"name" => "base", "box" => "generic",
"roles" => [{"role" => "hello-world"}, {"role" => "script", "script" => "hello"}],
"private_net" => "1.1.1.1"
"shared_folders"=>[{"Host"=>"Guest"}],
"private_net" => "1.1.1.1", "index"=>5, "os"=>"linux", "nictype2"=>nil, "actual_shared_folders"=>[{"Host"=>"Guest"}]
},
{"name" => "merged_role", "box" => "generic",
"roles" => [{"role" => "mutagen", "paths" => ["path2", "path1"]}]
"roles" => [{"role" => "mutagen", "paths" => ["path2", "path1"]}],
"shared_folders"=>[{"Host"=>"Guest"}],
"index"=>6, "os"=>"linux", "nictype2"=>nil, "actual_shared_folders"=>[{"Host"=>"Guest"}]
},
{"name" => "submachine", "box" => "subgeneric"},
{"name" => "machine1", "box" => "duplicate", "gui" => true }
{"name" => "submachine", "box" => "subgeneric", "shared_folders"=>[{"Host"=>"Guest"}], "index"=>7, "os"=>"macos", "nictype1"=>"82545EM", "nictype2"=>"82545EM", "actual_shared_folders"=>[] },
{"name" => "machine1", "box" => "duplicate", "gui" => true, "shared_folders"=>[{"Host"=>"Guest"}], "index"=>8, "os"=>"macos", "nictype1"=>"82545EM", "nictype2"=>"82545EM", "actual_shared_folders"=>[] }
]
}
......@@ -216,10 +198,14 @@ class Tester
end
def run()
puts "=== Testing merge_yaml"
test_merge_yaml()
test_loading()
puts "=== Testing vagrantfile"
test_vagrantfile()
puts "=== Testing expand_env"
test_expand_env()
puts "=== Testing loading"
test_loading()
end
end
......
......@@ -6,6 +6,9 @@ settings:
global: global1
list: [global2, global3]
home_share: $HOME
defaults:
shared_folders:
- "Host": "Guest"
urls:
domain:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment