Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Various changes to get specs to pass on windows #225

Merged
merged 6 commits into from
Nov 13, 2014

Conversation

jaym
Copy link
Contributor

@jaym jaym commented Nov 11, 2014

  • Fixed up cli_specs (there were some system dependent function calls that needed to be stubbed)
  • Cookbook profiler git_specs needed some modifications to get them to work with cmd.exe (' -> ")
  • Policy store_config_specs used File.expand_path, which is system dependent
  • Comparing their SHAs was broken because windows decides to do magic unless you give it the b mode when writing files

cc @btm @danielsdeleo @adamedx

@@ -93,7 +93,7 @@ def generate_lock_and_install

lock_data = policyfile_compiler.lock.to_lock

File.open(policyfile_lock_expanded_path, "w+") do |f|
File.open(policyfile_lock_expanded_path, "wb+") do |f|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the encoding to ASCII-8BIT doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure about it becoming ASCII.
I do know that on windows, it will do a bunch of things if you don't specify binary mode.
In text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://www.ruby-doc.org/core-2.1.4/IO.html#method-c-new

Check out the "b" flag description there. We may already be specifying UTF8 encoding somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this will matter for writing. I'll try some things out.

@tyler-ball
Copy link
Contributor

LGTM

@@ -93,7 +93,7 @@ def edit_repo
edit_repo
system_command('git config --local user.name "Alice"', cwd: cookbook_path).error!
system_command('git config --local user.email "alice@example.com"', cwd: cookbook_path).error!
system_command("git commit -a -m 'update readme' --author 'Alice <alice@example.com>'", cwd: cookbook_path).error!
system_command('git commit -a -m "update readme" --author "Alice <alice@example.com>"', cwd: cookbook_path).error!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this all about? Also, looks like this adds two extra spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces: I had to create a fresh vm to develop on. And vim with default
settings is stupid.
Quotes: cmd.exe is stupid. It freaks out when using single quotes

On Tue, Nov 11, 2014 at 1:18 PM, Dan DeLeo notifications@github.com wrote:

In spec/unit/cookbook_profiler/git_spec.rb:

@@ -93,7 +93,7 @@ def edit_repo
edit_repo
system_command('git config --local user.name "Alice"', cwd: cookbook_path).error!
system_command('git config --local user.email "alice@example.com"', cwd: cookbook_path).error!

  •    system_command("git commit -a -m 'update readme' --author 'Alice alice@example.com'", cwd: cookbook_path).error!
    
  •      system_command('git commit -a -m "update readme" --author "Alice alice@example.com"', cwd: cookbook_path).error!
    

What's this all about? Also, looks like this adds two extra spaces?


Reply to this email directly or view it on GitHub
/~https://github.com/opscode/chef-dk/pull/225/files#r20181106.

@danielsdeleo
Copy link
Contributor

Fix the spaces and then :shipit:

@jaym jaym force-pushed the jdmundrawala/unit-tests-windows branch from 1afa88f to 24690bf Compare November 11, 2014 23:01
@@ -89,7 +89,7 @@ def upload_policy
end

def write_updated_lockfile
File.open(policyfile_lock_expanded_path, "w+") do |f|
File.open(policyfile_lock_expanded_path, "wb+") do |f|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is what we need, we can have a helper with_file and make sure we don't break when we call File.open() somewhere else later on.

@jaym
Copy link
Contributor Author

jaym commented Nov 12, 2014

@sersut factored out the File.open stuff

@bwmeier
Copy link

bwmeier commented Nov 12, 2014

FYI - there's an impact of #180 on this fix - the scope of this should be limited to cli_spec.rb. The code change I made is below, but this did not include the fixes in this PR.

diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb
index 8144602..b91ebb5 100644
--- a/spec/unit/cli_spec.rb
+++ b/spec/unit/cli_spec.rb
@@ -167,6 +167,12 @@ E

   context "sanity_check!" do
     context "on unix" do
+      before do
+        allow(Chef::Platform).to receive(:windows?).and_return(false)
+        stub_const("File::PATH_SEPARATOR", ':')
+        allow(cli).to receive(:path_key).and_return('PATH')
+      end
+
       it "complains if embedded is first" do
         expect(cli).to receive(:env).and_return({'PATH' => '/opt/chefdk/embedded/bin:/opt/chefdk/bin' })
         allow(cli).to receive(:omnibus_embedded_bin_dir).and_return("/opt/chefdk/embedded/bin")
@@ -208,6 +214,7 @@ E
       before do
         allow(Chef::Platform).to receive(:windows?).and_return(true)
         stub_const("File::PATH_SEPARATOR", ';')
+        allow(cli).to receive(:path_key).and_return('PATH')
       end

       it "complains if embedded is first" do

@jaym
Copy link
Contributor Author

jaym commented Nov 12, 2014

@bwmeier I did something slightly different, it should have the same end result.

@bwmeier
Copy link

bwmeier commented Nov 12, 2014

Oh, after applying the #180 fix, I also had to include a change to exec_spec.rb to explicitly set the File::PATH_SEPARATOR:

diff --git a/spec/unit/command/exec_spec.rb b/spec/unit/command/exec_spec.rb
index ba14724..6af639d 100644
--- a/spec/unit/command/exec_spec.rb
+++ b/spec/unit/command/exec_spec.rb
@@ -80,6 +80,7 @@ describe ChefDK::Command::Exec do
       before do
         allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
         allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
+        stub_const("File::PATH_SEPARATOR", ':')
       end

       it "should call exec to fire off the command with the correct environment" do
@@ -115,6 +116,7 @@ describe ChefDK::Command::Exec do
       before do
         allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
         allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
+        stub_const("File::PATH_SEPARATOR", ':')
       end

       it "should raise Errno::ENOENT" do

@jaym
Copy link
Contributor Author

jaym commented Nov 12, 2014

That makes sense.

@@ -103,5 +103,8 @@ def omnibus_env
end
end

def with_file(path, mode='wb+', &block)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some comments here for why choosing this mode by default.

@sersut
Copy link

sersut commented Nov 12, 2014

Overall 👍

jaym added a commit that referenced this pull request Nov 13, 2014
Various changes to get specs to pass on windows
@jaym jaym merged commit f3dd803 into master Nov 13, 2014
@jaym jaym deleted the jdmundrawala/unit-tests-windows branch November 13, 2014 04:53
ksubrama pushed a commit that referenced this pull request Jan 11, 2016
@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants