Skip to content

Commit

Permalink
Merge pull request test-kitchen#801 from codranger:compression
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-ball committed Aug 3, 2015
2 parents 9ac7ac0 + 25cb733 commit 5b54062
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
26 changes: 18 additions & 8 deletions lib/kitchen/transport/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,26 @@ class Ssh < Kitchen::Transport::Base
default_config :ssh_key, nil
expand_path_for :ssh_key

default_config :compression, "zlib"
required_config :compression do |attr, value, transport|
if !%W[zlib none].include?(value)
raise UserError, "#{transport} :#{attr} value may only " \
"be set to `none' or `zlib'."
end
end
default_config :compression, true
required_config :compression

default_config :compression_level do |transport|
transport[:compression] == "none" ? 0 : 6
transport[:compression] == false ? 0 : 6
end

def finalize_config!(instance)
super

# zlib was never a valid value and breaks in net-ssh >= 2.10
# TODO: remove these backwards compatiable casts in 2.0
case config[:compression]
when "zlib"
config[:compression] = "[email protected]"
when "none"
config[:compression] = false
end

self
end

# (see Base#connection)
Expand Down
17 changes: 8 additions & 9 deletions spec/kitchen/transport/ssh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,20 @@ def types # rubocop:disable Lint/NestedMethodDefinition
transport[:username].must_equal "root"
end

it "sets :compression to zlib by default" do
transport[:compression].must_equal "zlib"
it "sets :compression to true by default" do
transport[:compression].must_equal true
end

it "sets :compression to none if set to none" do
it "sets :compression to false if set to none" do
config[:compression] = "none"

transport[:compression].must_equal "none"
transport[:compression].must_equal false
end

it "raises a UserError if :compression is set to a bogus value" do
config[:compression] = "boom"
it "sets :compression to [email protected] if set to zlib" do
config[:compression] = "zlib"

err = proc { transport }.must_raise Kitchen::UserError
err.message.must_match(%r{value may only be set to `none' or `zlib'})
transport[:compression].must_equal "[email protected]"
end

it "sets :compression_level to 6 by default" do
Expand Down Expand Up @@ -309,7 +308,7 @@ def self.common_connection_specs
config[:compression] = "none"

klass.expects(:new).with do |hash|
hash[:compression] == "none"
hash[:compression] == false
end

make_connection
Expand Down

0 comments on commit 5b54062

Please sign in to comment.