spec/kitchen/data_munger_spec.rb in test-kitchen-1.3.1 vs spec/kitchen/data_munger_spec.rb in test-kitchen-1.4.0.beta.1

- old
+ new

@@ -87,11 +87,12 @@ end DATA_KEYS = { :driver => :name, :provisioner => :name, - :busser => :version + :transport => :name, + :verifier => :name } DATA_KEYS.each_pair do |key, default_key| describe "##{key}" do @@ -125,10 +126,23 @@ ).public_send("#{key}_data_for", "suite", "platform").must_equal( default_key => "thenoseknows" ) end + it "returns kitchen config #{key} name from callable" do + DataMunger.new( + {}, + { + :defaults => { + key => ->(suite, platform) { "#{suite}++#{platform}" } + } + } + ).public_send("#{key}_data_for", "suite", "platform").must_equal( + default_key => "suite++platform" + ) + end + it "returns common #{key} name" do DataMunger.new( { key => "starship" }, @@ -1047,80 +1061,80 @@ :name => "chefy" ) end end - describe "for #busser_data_for" do + describe "for #verifier_data_for" do it "is returned when provided" do DataMunger.new( { - :busser => "chefy", + :verifier => "chefy", :platforms => [ { :name => "plat" } ], :suites => [ { :name => "sweet" } ] }, { key => "datvalue" } - ).busser_data_for("sweet", "plat").must_equal( - :version => "chefy", + ).verifier_data_for("sweet", "plat").must_equal( + :name => "chefy", key => "datvalue" ) end it "is returned when provided in user data" do DataMunger.new( { :kitchen => { key => "datvalue" }, - :busser => "chefy", + :verifier => "chefy", :platforms => [ { :name => "plat" } ], :suites => [ { :name => "sweet" } ] }, {} - ).busser_data_for("sweet", "plat").must_equal( - :version => "chefy", + ).verifier_data_for("sweet", "plat").must_equal( + :name => "chefy", key => "datvalue" ) end it "user data value beats provided value" do DataMunger.new( { :kitchen => { key => "datvalue" }, - :busser => "chefy", + :verifier => "chefy", :platforms => [ { :name => "plat" } ], :suites => [ { :name => "sweet" } ] }, { key => "ilose" } - ).busser_data_for("sweet", "plat").must_equal( - :version => "chefy", + ).verifier_data_for("sweet", "plat").must_equal( + :name => "chefy", key => "datvalue" ) end - it "rejects any value in busser data" do + it "rejects any value in verifier data" do DataMunger.new( { - :busser => { + :verifier => { :version => "chefy", key => "imevil" }, :platforms => [ { :name => "plat" } @@ -1128,15 +1142,102 @@ :suites => [ { :name => "sweet" } ] }, {} - ).busser_data_for("sweet", "plat").must_equal( + ).verifier_data_for("sweet", "plat").must_equal( :version => "chefy" ) end end + + describe "for #transport_data_for" do + + it "is returned when provided" do + DataMunger.new( + { + :transport => "pipes", + :platforms => [ + { :name => "plat" } + ], + :suites => [ + { :name => "sweet" } + ] + }, + { + key => "datvalue" + } + ).transport_data_for("sweet", "plat").must_equal( + :name => "pipes", + key => "datvalue" + ) + end + + it "is returned when provided in user data" do + DataMunger.new( + { + :kitchen => { + key => "datvalue" + }, + :transport => "pipes", + :platforms => [ + { :name => "plat" } + ], + :suites => [ + { :name => "sweet" } + ] + }, + {} + ).transport_data_for("sweet", "plat").must_equal( + :name => "pipes", + key => "datvalue" + ) + end + + it "user data value beats provided value" do + DataMunger.new( + { + :kitchen => { + key => "datvalue" + }, + :transport => "pipes", + :platforms => [ + { :name => "plat" } + ], + :suites => [ + { :name => "sweet" } + ] + }, + { + key => "ilose" + } + ).transport_data_for("sweet", "plat").must_equal( + :name => "pipes", + key => "datvalue" + ) + end + + it "rejects any value in transport data" do + DataMunger.new( + { + :transport => { + :name => "pipes", + key => "imevil" + }, + :platforms => [ + { :name => "plat" } + ], + :suites => [ + { :name => "sweet" } + ] + }, + {} + ).transport_data_for("sweet", "plat").must_equal( + :name => "pipes" + ) + end + end end end end describe "legacy driver_config and driver_plugin" do @@ -1610,9 +1711,671 @@ }, {} ).provisioner_data_for("suite", "plat").must_equal( :name => "chefy", :require_chef_omnibus => "it's probably fine" + ) + end + end + end + + describe "legacy http_proxy & https_proxy from driver" do + + describe "from a single source" do + + it "common driver value remains in driver" do + DataMunger.new( + { + :provisioner => "chefy", + :driver => { + :name => "starship", + :http_proxy => "http://proxy", + :https_proxy => "https://proxy" + } + }, + {} + ).driver_data_for("suite", "platform").must_equal( + :name => "starship", + :http_proxy => "http://proxy", + :https_proxy => "https://proxy" + ) + end + + it "common driver value copies into provisioner" do + DataMunger.new( + { + :provisioner => "chefy", + :driver => { + :name => "starship", + :http_proxy => "http://proxy", + :https_proxy => "https://proxy" + } + }, + {} + ).provisioner_data_for("suite", "platform").must_equal( + :name => "chefy", + :http_proxy => "http://proxy", + :https_proxy => "https://proxy" + ) + end + + it "common driver value copies into verifier" do + DataMunger.new( + { + :verifier => "bussy", + :driver => { + :name => "starship", + :http_proxy => "http://proxy", + :https_proxy => "https://proxy" + } + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "bussy", + :http_proxy => "http://proxy", + :https_proxy => "https://proxy" + ) + end + + it "common driver value loses to existing provisioner value" do + DataMunger.new( + { + :provisioner => { + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + }, + :driver => { + :name => "starship", + :http_proxy => "dragons", + :https_proxy => "cats" + } + }, + {} + ).provisioner_data_for("suite", "platform").must_equal( + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "common driver value loses to existing verifier value" do + DataMunger.new( + { + :verifier => { + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + }, + :driver => { + :name => "starship", + :http_proxy => "dragons", + :https_proxy => "cats" + } + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "suite driver value remains in driver" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :provisioner => "chefy", + :driver => { + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + } + } + ] + }, + {} + ).driver_data_for("sweet", "platform").must_equal( + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "suite driver value copies into provisioner" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :provisioner => "chefy", + :driver => { + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + } + } + ] + }, + {} + ).provisioner_data_for("sweet", "platform").must_equal( + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "suite driver value copies into verifier" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :verifier => "bussy", + :driver => { + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + } + } + ] + }, + {} + ).verifier_data_for("sweet", "platform").must_equal( + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "suite driver value loses to existing provisioner value" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :provisioner => { + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + }, + :driver => { + :name => "starship", + :http_proxy => "dragons", + :https_proxy => "cats" + } + } + ] + }, + {} + ).provisioner_data_for("sweet", "platform").must_equal( + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "suite driver value loses to existing verifier value" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :verifier => { + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + }, + :driver => { + :name => "starship", + :http_proxy => "dragons", + :https_proxy => "cats" + } + } + ] + }, + {} + ).verifier_data_for("sweet", "platform").must_equal( + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "platform driver value remains in driver" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :provisioner => "chefy", + :driver => { + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + } + } + ] + }, + {} + ).driver_data_for("suite", "plat").must_equal( + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "platform driver value copies into provisioner" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :provisioner => "chefy", + :driver => { + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + } + } + ] + }, + {} + ).provisioner_data_for("suite", "plat").must_equal( + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "platform driver value copies into verifier" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :verifier => "bussy", + :driver => { + :name => "starship", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + } + } + ] + }, + {} + ).verifier_data_for("suite", "plat").must_equal( + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "platform driver value loses to existing provisioner value" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :provisioner => { + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + }, + :driver => { + :name => "starship", + :http_proxy => "dragons", + :https_proxy => "cats" + } + } + ] + }, + {} + ).provisioner_data_for("suite", "plat").must_equal( + :name => "chefy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + + it "platform driver value loses to existing verifier value" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :verifier => { + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + }, + :driver => { + :name => "starship", + :http_proxy => "dragons", + :https_proxy => "cats" + } + } + ] + }, + {} + ).verifier_data_for("suite", "plat").must_equal( + :name => "bussy", + :http_proxy => "it's probably fine", + :https_proxy => "la quinta" + ) + end + end + end + + describe "legacy busser blocks to verifier" do + + describe "from a single source" do + + it "merges old common busser name to version into verifier" do + DataMunger.new( + { + :busser => "starship" + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "busser", + :version => "starship" + ) + end + + it "merges old common busser name to version with exising verifier" do + DataMunger.new( + { + :busser => "starship", + :verifier => { + :a => "b" + } + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "busser", + :version => "starship", + :a => "b" + ) + end + + it "merges old common busser name to version into verifier with name" do + DataMunger.new( + { + :busser => "starship", + :verifier => "stellar" + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "stellar", + :version => "starship" + ) + end + + it "merges old busser data into verifier with name" do + DataMunger.new( + { + :busser => { + :a => "b" + }, + :verifier => "stellar" + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "stellar", + :a => "b" + ) + end + + it "merges old busser data into verifier data" do + DataMunger.new( + { + :busser => { + :a => "b", + :both => "legacy" + }, + :verifier => { + :name => "stellar", + :c => "d", + :both => "modern" + } + }, + {} + ).verifier_data_for("suite", "platform").must_equal( + :name => "stellar", + :a => "b", + :c => "d", + :both => "modern" + ) + end + + it "returns platform verifier name" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :busser => "flip" + } + ] + }, + {} + ).verifier_data_for("suite", "plat").must_equal( + :name => "busser", + :version => "flip" + ) + end + + it "return platform config containing verifier hash" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :busser => "flip", + :verifier => { + :flop => "yep" + } + } + ] + }, + {} + ).verifier_data_for("suite", "plat").must_equal( + :name => "busser", + :version => "flip", + :flop => "yep" + ) + end + + it "returns suite driver name" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :busser => "waz" + } + ] + }, + {} + ).verifier_data_for("sweet", "platform").must_equal( + :name => "busser", + :version => "waz" + ) + end + + it "returns suite config containing verifier hash" do + DataMunger.new( + { + :suites => [ + { + :name => "sweet", + :busser => "waz", + :verifier => { + :up => "nope" + } + } + ] + }, + {} + ).verifier_data_for("sweet", "platform").must_equal( + :name => "busser", + :version => "waz", + :up => "nope" + ) + end + end + + describe "from multiple sources" do + + it "suite into platform into common" do + DataMunger.new( + { + :busser => { + :version => "commony", + :color => "purple", + :fruit => %w[apple pear], + :deep => { :common => "junk" } + }, + :platforms => [ + { + :name => "plat", + :busser => { + :version => "platformy", + :fruit => ["banana"], + :deep => { :platform => "stuff" } + } + } + ], + :suites => [ + { + :name => "sweet", + :busser => { + :version => "suitey", + :vehicle => "car", + :deep => { :suite => "things" } + } + } + ] + }, + {} + ).verifier_data_for("sweet", "plat").must_equal( + :name => "busser", + :version => "suitey", + :color => "purple", + :fruit => ["banana"], + :vehicle => "car", + :deep => { + :common => "junk", + :platform => "stuff", + :suite => "things" + } + ) + end + + it "platform into common" do + DataMunger.new( + { + :busser => { + :version => "commony", + :color => "purple", + :fruit => %w[apple pear], + :deep => { :common => "junk" } + }, + :platforms => [ + { + :name => "plat", + :busser => { + :version => "platformy", + :fruit => ["banana"], + :deep => { :platform => "stuff" } + } + } + ] + }, + {} + ).verifier_data_for("sweet", "plat").must_equal( + :name => "busser", + :version => "platformy", + :color => "purple", + :fruit => ["banana"], + :deep => { + :common => "junk", + :platform => "stuff" + } + ) + end + + it "suite into common" do + DataMunger.new( + { + :busser => { + :version => "commony", + :color => "purple", + :fruit => %w[apple pear], + :deep => { :common => "junk" } + }, + :suites => [ + { + :name => "sweet", + :busser => { + :version => "suitey", + :vehicle => "car", + :deep => { :suite => "things" } + } + } + ] + }, + {} + ).verifier_data_for("sweet", "plat").must_equal( + :name => "busser", + :version => "suitey", + :color => "purple", + :fruit => %w[apple pear], + :vehicle => "car", + :deep => { + :common => "junk", + :suite => "things" + } + ) + end + + it "suite into platform" do + DataMunger.new( + { + :platforms => [ + { + :name => "plat", + :busser => { + :version => "platformy", + :fruit => ["banana"], + :deep => { :platform => "stuff" } + } + } + ], + :suites => [ + { + :name => "sweet", + :busser => { + :version => "suitey", + :vehicle => "car", + :deep => { :suite => "things" } + } + } + ] + }, + {} + ).verifier_data_for("sweet", "plat").must_equal( + :name => "busser", + :version => "suitey", + :fruit => ["banana"], + :vehicle => "car", + :deep => { + :platform => "stuff", + :suite => "things" + } ) end end end end