Skip to content

Commit

Permalink
Add Platform's :os_type info to kitchen diagnose data.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnichol committed Mar 5, 2015
1 parent 34fbffc commit 2513182
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/kitchen/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def remote_exec(command)
# @return [Hash] a diagnostic hash
def diagnose
result = Hash.new
[:state_file, :driver, :provisioner, :transport, :busser].each do |sym|
[
:platform, :state_file, :driver, :provisioner, :transport, :busser
].each do |sym|
obj = send(sym)
result[sym] = obj.respond_to?(:diagnose) ? obj.diagnose : :unknown
end
Expand Down
7 changes: 7 additions & 0 deletions lib/kitchen/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@ def initialize(options = {})
end
@os_type = options[:os_type]
end

# Returns a Hash of configuration and other useful diagnostic information.
#
# @return [Hash] a diagnostic hash
def diagnose
{ :os_type => os_type }
end
end
end
14 changes: 14 additions & 0 deletions spec/kitchen/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ def platform(name = "platform")
instance.diagnose.must_be_instance_of Hash
end

it "sets :platform key to platform's diagnose info" do
platform.stubs(:diagnose).returns(:a => "b")

instance.diagnose[:platform].must_equal(:a => "b")
end

it "sets :platform key to :unknown if obj can't respond to #diagnose" do
opts[:platform] = Class.new(platform.class) {
undef_method :diagnose
}.new(:name => "whoop")

instance.diagnose[:platform].must_equal :unknown
end

it "sets :state_file key to state_file's diganose info" do
state_file.stubs(:diagnose).returns(:a => "b")

Expand Down
6 changes: 6 additions & 0 deletions spec/kitchen/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@
klass.new(:name => "p", :os_type => "unicorn").os_type.must_equal "unicorn"
klass.new(:name => "p", :os_type => nil).os_type.must_equal nil
end

it "#diagnose returns a hash with sorted keys" do
opts[:os_type] = "unikitty"

klass.new(opts).diagnose.must_equal(:os_type => "unikitty")
end
end

0 comments on commit 2513182

Please sign in to comment.