Skip to content

Commit

Permalink
Fix / work around test errors on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
smurawski committed Jul 30, 2015
1 parent aa3127a commit 23c7f52
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 33 deletions.
14 changes: 8 additions & 6 deletions spec/kitchen/configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,27 @@ class SubclassDefaults < StaticDefaults
end

it "expands a default value" do
subject[:success_path].must_equal "/tmp/yo/self/success"
subject[:success_path].must_equal os_safe_root_path("/tmp/yo/self/success")
end

it "uses provided config over default_config" do
config[:success_path] = "mine"

subject[:success_path].must_equal "/tmp/yo/self/mine"
subject[:success_path].must_equal os_safe_root_path("/tmp/yo/self/mine")
end

it "leaves a full path expanded" do
config[:success_path] = "/the/other/one"

subject[:success_path].must_equal "/the/other/one"
subject[:success_path].must_equal os_safe_root_path("/the/other/one")
end

it "expands all items if path is an array" do
subject[:bunch_of_paths].must_equal %W[
paths = %W[
/tmp/yo/self/a /tmp/yo/self/b /tmp/yo/self/c
]
os_safe_paths = paths.collect {|path| os_safe_root_path(path)}
subject[:bunch_of_paths].must_equal os_safe_paths
end

it "doesn't expand path with a falsy expand_path_for value" do
Expand All @@ -342,7 +344,7 @@ class SubclassDefaults < StaticDefaults
config[:something_else] = "is_set"
config[:complex_path] = "./complex"

subject[:complex_path].must_equal "/tmp/yo/self/complex"
subject[:complex_path].must_equal os_safe_root_path("/tmp/yo/self/complex")
end

it "leaves a nil config value as nil" do
Expand All @@ -369,7 +371,7 @@ class SubclassDefaults < StaticDefaults
end

it "contains expand_path_for from superclass" do
subject[:success_path].must_equal "/rooty/success"
subject[:success_path].must_equal os_safe_root_path("/rooty/success")
end

it "uses its own expand_path_for over inherited expand_path_for" do
Expand Down
2 changes: 1 addition & 1 deletion spec/kitchen/loader/yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ class Yamled

it "global config contains a filename" do
loader.diagnose[:global_config][:filename].
must_equal File.join(ENV["HOME"], ".kitchen/config.yml")
must_equal File.join(ENV["HOME"].gsub('\\','/'), ".kitchen/config.yml")
end

it "global config contains raw data" do
Expand Down
19 changes: 12 additions & 7 deletions spec/kitchen/provisioner/chef_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,38 @@ def calculate_path(path, _opts = {})
end

it ":data_path uses calculate_path and is expanded" do
provisioner[:data_path].must_equal "/rooty/<calculated>/data"
provisioner[:data_path].
must_equal os_safe_root_path("/rooty/<calculated>/data")
end

it ":data_bags_path uses calculate_path and is expanded" do
provisioner[:data_bags_path].must_equal "/rooty/<calculated>/data_bags"
provisioner[:data_bags_path].
must_equal os_safe_root_path("/rooty/<calculated>/data_bags")
end

it ":environments_path uses calculate_path and is expanded" do
provisioner[:environments_path].
must_equal "/rooty/<calculated>/environments"
must_equal os_safe_root_path("/rooty/<calculated>/environments")
end

it ":nodes_path uses calculate_path and is expanded" do
provisioner[:nodes_path].must_equal "/rooty/<calculated>/nodes"
provisioner[:nodes_path].
must_equal os_safe_root_path("/rooty/<calculated>/nodes")
end

it ":roles_path uses calculate_path and is expanded" do
provisioner[:roles_path].must_equal "/rooty/<calculated>/roles"
provisioner[:roles_path].
must_equal os_safe_root_path("/rooty/<calculated>/roles")
end

it ":clients_path uses calculate_path and is expanded" do
provisioner[:clients_path].must_equal "/rooty/<calculated>/clients"
provisioner[:clients_path].
must_equal os_safe_root_path("/rooty/<calculated>/clients")
end

it "...secret_key_path uses calculate_path and is expanded" do
provisioner[:encrypted_data_bag_secret_key_path].
must_equal "/rooty/<calculated>/encrypted_data_bag_secret_key"
must_equal os_safe_root_path("/rooty/<calculated>/encrypted_data_bag_secret_key")
end
end

Expand Down
21 changes: 15 additions & 6 deletions spec/kitchen/provisioner/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def calculate_path(path, _opts = {})
before { platform.stubs(:shell_type).returns("bourne") }

it ":script uses calculate_path and is expanded" do
provisioner[:script].must_equal "/rooty/<calculated>/bootstrap.sh"
provisioner[:script].must_equal os_safe_root_path("/rooty/<calculated>/bootstrap.sh")
end
end

Expand All @@ -75,12 +75,12 @@ def calculate_path(path, _opts = {})
before { platform.stubs(:shell_type).returns("powershell") }

it ":script uses calculate_path and is expanded" do
provisioner[:script].must_equal "/rooty/<calculated>/bootstrap.ps1"
provisioner[:script].must_equal os_safe_root_path("/rooty/<calculated>/bootstrap.ps1")
end
end

it ":data_path uses calculate_path and is expanded" do
provisioner[:data_path].must_equal "/rooty/<calculated>/data"
provisioner[:data_path].must_equal os_safe_root_path("/rooty/<calculated>/data")
end
end

Expand Down Expand Up @@ -398,7 +398,10 @@ def calculate_path(path, _opts = {})
provisioner.create_sandbox

sandbox_path("my_script").file?.must_equal true
sandbox_path("my_script").executable?.must_equal true
unless running_tests_on_windows?
# Windows doesn't have the concept of executable
sandbox_path("my_script").executable?.must_equal true
end
IO.read(sandbox_path("my_script")).must_equal "gonuts"
end

Expand Down Expand Up @@ -442,7 +445,10 @@ def calculate_path(path, _opts = {})
provisioner.create_sandbox

sandbox_path("bootstrap.sh").file?.must_equal true
sandbox_path("bootstrap.sh").executable?.must_equal true
unless running_tests_on_windows?
# Windows doesn't have the concept of executable
sandbox_path("bootstrap.sh").executable?.must_equal true
end
IO.read(sandbox_path("bootstrap.sh")).
must_match(/NO BOOTSTRAP SCRIPT PRESENT/)
end
Expand Down Expand Up @@ -470,7 +476,10 @@ def calculate_path(path, _opts = {})
provisioner.create_sandbox

sandbox_path("bootstrap.ps1").file?.must_equal true
sandbox_path("bootstrap.ps1").executable?.must_equal true
unless running_tests_on_windows?
# Windows doesn't have the concept of executable
sandbox_path("bootstrap.ps1").executable?.must_equal true
end
IO.read(sandbox_path("bootstrap.ps1")).
must_match(/Write-Host "NO BOOTSTRAP SCRIPT PRESENT`n"/)
end
Expand Down
15 changes: 11 additions & 4 deletions spec/kitchen/ssh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ def types # rubocop:disable Lint/NestedMethodDefinition

before do
expect_scp_session("-t /tmp/remote") do |channel|
file_mode = running_tests_on_windows? ? 0644 : 0755
channel.gets_data("\0")
channel.sends_data("C0755 1234 #{File.basename(src.path)}\n")
channel.sends_data("C#{padded_octal_string(file_mode)} 1234 #{File.basename(src.path)}\n")
channel.gets_data("\0")
channel.sends_data("a" * 1234)
channel.sends_data("\0")
Expand Down Expand Up @@ -357,6 +358,12 @@ def types # rubocop:disable Lint/NestedMethodDefinition

before do
@dir = Dir.mktmpdir("local")

#Since File.chmod is a NOOP on Windows
@tmp_dir_mode = running_tests_on_windows? ? 0755 : 0700
@alpha_file_mode = running_tests_on_windows? ? 0644 : 0644
@beta_file_mode = running_tests_on_windows? ? 0444 : 0555

FileUtils.chmod(0700, @dir)
File.open("#{@dir}/alpha", "wb") { |f| f.write("alpha-contents\n") }
FileUtils.chmod(0644, "#{@dir}/alpha")
Expand All @@ -369,16 +376,16 @@ def types # rubocop:disable Lint/NestedMethodDefinition

expect_scp_session("-t -r /tmp/remote") do |channel|
channel.gets_data("\0")
channel.sends_data("D0700 0 #{File.basename(@dir)}\n")
channel.sends_data("D#{padded_octal_string(@tmp_dir_mode)} 0 #{File.basename(@dir)}\n")
channel.gets_data("\0")
channel.sends_data("C0644 15 alpha\n")
channel.sends_data("C#{padded_octal_string(@alpha_file_mode)} 15 alpha\n")
channel.gets_data("\0")
channel.sends_data("alpha-contents\n")
channel.sends_data("\0")
channel.gets_data("\0")
channel.sends_data("D0755 0 subdir\n")
channel.gets_data("\0")
channel.sends_data("C0555 14 beta\n")
channel.sends_data("C#{padded_octal_string(@beta_file_mode)} 14 beta\n")
channel.gets_data("\0")
channel.sends_data("beta-contents\n")
channel.sends_data("\0")
Expand Down
19 changes: 13 additions & 6 deletions spec/kitchen/transport/ssh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def types # rubocop:disable Lint/NestedMethodDefinition
config[:kitchen_root] = "/rooty"
config[:ssh_key] = "my_key"

transport[:ssh_key].must_equal "/rooty/my_key"
transport[:ssh_key].must_equal os_safe_root_path("/rooty/my_key")
end
end

Expand Down Expand Up @@ -509,7 +509,7 @@ def self.common_connection_specs
config[:ssh_key] = "ssh_key_from_config"

klass.expects(:new).with do |hash|
hash[:keys] == ["/r/ssh_key_from_config"]
hash[:keys] == [os_safe_root_path("/r/ssh_key_from_config")]
end

make_connection
Expand Down Expand Up @@ -1018,8 +1018,9 @@ def debug_line_with(msg)

before do
expect_scp_session("-t /tmp/remote") do |channel|
file_mode = running_tests_on_windows? ? 0644 : 0755
channel.gets_data("\0")
channel.sends_data("C0755 1234 #{File.basename(src.path)}\n")
channel.sends_data("C#{padded_octal_string(file_mode)} 1234 #{File.basename(src.path)}\n")
channel.gets_data("\0")
channel.sends_data("a" * 1234)
channel.sends_data("\0")
Expand Down Expand Up @@ -1054,6 +1055,12 @@ def debug_line_with(msg)
describe "for a path" do
before do
@dir = Dir.mktmpdir("local")

#Since File.chmod is a NOOP on Windows
@tmp_dir_mode = running_tests_on_windows? ? 0755 : 0700
@alpha_file_mode = running_tests_on_windows? ? 0644 : 0644
@beta_file_mode = running_tests_on_windows? ? 0444 : 0555

FileUtils.chmod(0700, @dir)
File.open("#{@dir}/alpha", "wb") { |f| f.write("alpha-contents\n") }
FileUtils.chmod(0644, "#{@dir}/alpha")
Expand All @@ -1066,16 +1073,16 @@ def debug_line_with(msg)

expect_scp_session("-t -r /tmp/remote") do |channel|
channel.gets_data("\0")
channel.sends_data("D0700 0 #{File.basename(@dir)}\n")
channel.sends_data("D#{padded_octal_string(@tmp_dir_mode)} 0 #{File.basename(@dir)}\n")
channel.gets_data("\0")
channel.sends_data("C0644 15 alpha\n")
channel.sends_data("C#{padded_octal_string(@alpha_file_mode)} 15 alpha\n")
channel.gets_data("\0")
channel.sends_data("alpha-contents\n")
channel.sends_data("\0")
channel.gets_data("\0")
channel.sends_data("D0755 0 subdir\n")
channel.gets_data("\0")
channel.sends_data("C0555 14 beta\n")
channel.sends_data("C#{padded_octal_string(@beta_file_mode)} 14 beta\n")
channel.gets_data("\0")
channel.sends_data("beta-contents\n")
channel.sends_data("\0")
Expand Down
6 changes: 3 additions & 3 deletions spec/kitchen/verifier/busser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
{
"mondospec/charlie" => {
:content => "charlie",
:perms => "0764"
:perms => (running_tests_on_windows? ? "0644" : "0764")
},
"minispec/beta" => {
:content => "beta",
:perms => "0644"
},
"abba/alpha" => {
:content => "alpha",
:perms => "0440"
:perms => (running_tests_on_windows? ? "0444" : "0440")
}
}
end
Expand All @@ -68,7 +68,7 @@
},
"abba/common" => {
:content => "yeppers",
:perms => "0664"
:perms => (running_tests_on_windows? ? "0644" : "0664")
}
}
end
Expand Down
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,19 @@ def with_fake_fs
FakeFS.deactivate!
FakeFS::FileSystem.clear
end

def running_tests_on_windows?
ENV['OS'] == 'Windows_NT'
end

def os_safe_root_path(root_path)
if running_tests_on_windows?
"#{File.join(ENV['SystemDrive'], root_path)}"
else
root_path
end
end

def padded_octal_string(integer)
integer.to_s(8).rjust(4,'0')
end

0 comments on commit 23c7f52

Please sign in to comment.