spec/kitchen/config_spec.rb in test-kitchen-1.0.0.beta.4 vs spec/kitchen/config_spec.rb in test-kitchen-1.0.0.rc.1
- old
+ new
@@ -23,10 +23,11 @@
require 'kitchen/collection'
require 'kitchen/config'
require 'kitchen/driver'
require 'kitchen/instance'
require 'kitchen/platform'
+require 'kitchen/provisioner'
require 'kitchen/suite'
require 'kitchen/util'
module Kitchen
@@ -43,191 +44,151 @@
end
describe Kitchen::Config do
let(:loader) { Kitchen::DummyLoader.new }
- let(:config) { Kitchen::Config.new(:loader => loader) }
+ let(:config) { Kitchen::Config.new(opts) }
- before do
- FakeFS.activate!
- FileUtils.mkdir_p("/tmp")
+ let(:opts) do
+ { :loader => loader, :kitchen_root => "/tmp/that/place",
+ :log_root => "/tmp/logs", :test_base_path => "/testing/yo",
+ :log_level => :debug }
end
- after do
- FakeFS.deactivate!
- FakeFS::FileSystem.clear
- end
+ describe "#loader" do
- describe "#platforms" do
-
- it "returns platforms loaded from a kitchen.yml" do
- stub_data!({ :platforms => [{ :name => 'one' }, { :name => 'two' }] })
-
- config.platforms.size.must_equal 2
- config.platforms[0].name.must_equal 'one'
- config.platforms[1].name.must_equal 'two'
+ it "returns its loader" do
+ config.loader.must_equal loader
end
- it "returns an empty Array if no platforms are given" do
- stub_data!({})
+ it "creates a Kitchen::Loader::YAML loader by default" do
+ opts.delete(:loader)
- config.platforms.must_equal []
+ config.loader.must_be_kind_of Kitchen::Loader::YAML
end
end
- describe "#suites" do
+ describe "#kitchen_root" do
- it "returns suites loaded from a kitchen.yml" do
- stub_data!({ :suites => [
- { :name => 'one', :run_list => [] },
- { :name => 'two', :run_list => [] },
- ] })
-
- config.suites.size.must_equal 2
- config.suites[0].name.must_equal 'one'
- config.suites[1].name.must_equal 'two'
+ it "returns its kitchen root" do
+ config.kitchen_root.must_equal "/tmp/that/place"
end
- it "returns an empty Array if no suites are given" do
- stub_data!({})
+ it "uses Dir.pwd by default" do
+ opts.delete(:kitchen_root)
- config.suites.must_equal []
+ config.kitchen_root.must_equal Dir.pwd
end
+ end
- def cheflike_suite(suite)
- suite.extend(Kitchen::Suite::Cheflike)
- end
+ describe "#log_root" do
- it "returns a suite with nil for data_bags_path by default" do
- stub_data!({ :suites => [{ :name => 'one', :run_list => [] }] })
- cheflike_suite(config.suites.first).data_bags_path.must_be_nil
+ it "returns its log root" do
+ config.log_root.must_equal "/tmp/logs"
end
- it "returns a suite with a common data_bags_path set" do
- stub_data!({ :suites => [{ :name => 'one', :run_list => [] }] })
- config.test_base_path = "/tmp/base"
- FileUtils.mkdir_p "/tmp/base/data_bags"
+ it "calculates a default log root using kitchen_root" do
+ opts.delete(:log_root)
- cheflike_suite(config.suites.first).data_bags_path.
- must_equal "/tmp/base/data_bags"
+ config.log_root.must_equal "/tmp/that/place/.kitchen/logs"
end
+ end
- it "returns a suite with a suite-specific data_bags_path set" do
- stub_data!({ :suites => [{ :name => 'cool', :run_list => [] }] })
- config.test_base_path = "/tmp/base"
- FileUtils.mkdir_p "/tmp/base/cool/data_bags"
+ describe "#test_base_path" do
- cheflike_suite(config.suites.first).data_bags_path.
- must_equal "/tmp/base/cool/data_bags"
+ it "returns its base test path" do
+ config.test_base_path.must_equal "/testing/yo"
end
- it "returns a suite with a custom data_bags_path set" do
- stub_data!({ :suites => [{ :name => 'one', :run_list => [],
- :data_bags_path => 'shared/data_bags' }] })
- config.kitchen_root = "/tmp/base"
- FileUtils.mkdir_p "/tmp/base/shared/data_bags"
+ it "calculates a default base using kitchen_root" do
+ opts.delete(:test_base_path)
- cheflike_suite(config.suites.first).data_bags_path.
- must_equal "/tmp/base/shared/data_bags"
+ config.test_base_path.must_equal "/tmp/that/place/test/integration"
end
+ end
- it "returns a suite with nil for roles_path by default" do
- stub_data!({ :suites => [{ :name => 'one', :run_list => [] }] })
+ describe "#log_level" do
- cheflike_suite(config.suites.first).roles_path.must_be_nil
+ it "returns its log level" do
+ config.log_level.must_equal :debug
end
- it "returns a suite with a common roles_path set" do
- stub_data!({ :suites => [{ :name => 'one', :run_list => [] }] })
- config.test_base_path = "/tmp/base"
- FileUtils.mkdir_p "/tmp/base/roles"
+ it "uses :info by default" do
+ opts.delete(:log_level)
- cheflike_suite(config.suites.first).roles_path.
- must_equal "/tmp/base/roles"
+ config.log_level.must_equal :info
end
+ end
- it "returns a suite with a suite-specific roles_path set" do
- stub_data!({ :suites => [{ :name => 'mysuite', :run_list => [] }] })
- config.test_base_path = "/tmp/base"
- FileUtils.mkdir_p "/tmp/base/mysuite/roles"
+ describe "#platforms" do
- cheflike_suite(config.suites.first).roles_path.
- must_equal "/tmp/base/mysuite/roles"
+ it "returns an array of platforms" do
+ stub_data!({
+ :platforms => [
+ { :name => 'one' },
+ { :name => 'two' }
+ ]
+ })
+
+ config.platforms.size.must_equal 2
+ config.platforms[0].name.must_equal 'one'
+ config.platforms[1].name.must_equal 'two'
end
- it "returns a suite with a custom roles_path set" do
- stub_data!({ :suites => [{ :name => 'one', :run_list => [],
- :roles_path => 'shared/roles' }] })
- config.kitchen_root = "/tmp/base"
- FileUtils.mkdir_p "/tmp/base/shared/roles"
+ it "returns an empty Array if no platforms are given" do
+ stub_data!({})
- cheflike_suite(config.suites.first).roles_path.
- must_equal "/tmp/base/shared/roles"
+ config.platforms.must_equal []
end
end
- describe "#instances" do
+ describe "#suites" do
- it "returns instances loaded from a kitchen.yml" do
+ it "returns an array of suites" do
stub_data!({
- :platforms => [
- { :name => 'p1' },
- { :name => 'p2' },
- ],
:suites => [
- { :name => 's1', :run_list => [] },
- { :name => 's2', :run_list => [] },
- { :name => 's3', :run_list => [], :excludes => ['p1'] }
+ { :name => 'one' },
+ { :name => 'two' }
]
})
- config.instances.size.must_equal 5
- instance_names = config.instances.map { |i| i.name }
- instance_names.must_equal %w{s1-p1 s1-p2 s2-p1 s2-p2 s3-p2}
+
+ config.suites.size.must_equal 2
+ config.suites[0].name.must_equal 'one'
+ config.suites[1].name.must_equal 'two'
end
- it "returns an instance containing a driver instance" do
- stub_data!({
- :platforms => [{ :name => 'platform', :driver_plugin => 'dummy' }],
- :suites => [{ :name => 'suite', :run_list => [] }]
- })
- config.instances.first.driver.must_be_instance_of Kitchen::Driver::Dummy
+ it "returns an empty Array if no suites are given" do
+ stub_data!({})
+
+ config.suites.must_equal []
end
+ end
- it "returns an instance with a driver initialized with kitchen_root" do
- config.kitchen_root = "/tmp"
- stub_data!({
- :platforms => [{ :name => 'platform', :driver_plugin => 'dummy' }],
- :suites => [{ :name => 'suite', :run_list => [] }]
- })
- config.instances.first.driver[:kitchen_root].must_equal "/tmp"
+ describe "#instances" do
+
+ it "returns an empty Array if no suites and platforms are given" do
+ stub_data!({})
+
+ config.instances.must_equal []
end
- it "returns an instance with a driver initialized with passed in config" do
+ it "returns an array of instances" do
+ skip "much more needed here"
+
stub_data!({
:platforms => [
- { :name => 'platform', :driver_plugin => 'dummy',
- :driver_config => { :foo => 'bar' }
- }
+ { :name => "p1" },
+ { :name => "p2" }
],
- :suites => [{ :name => 'suite', :run_list => [] }]
+ :suites => [
+ { :name => 's1' },
+ { :name => 's2' }
+ ]
})
- config.instances.first.driver[:foo].must_equal "bar"
- end
- end
- describe "#log_level" do
-
- it "returns a default log_level of info" do
- config.log_level.must_equal :info
+ config.instances
end
-
- it "returns an overridden log_level" do
- config.log_level = :error
- config.log_level.must_equal :error
- end
end
-
- private
def stub_data!(hash)
loader.data = hash
end
end