Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add regexp to cmp matcher #667

Merged
merged 5 commits into from
Apr 20, 2016
Merged

add regexp to cmp matcher #667

merged 5 commits into from
Apr 20, 2016

Conversation

arlimus
Copy link
Contributor

@arlimus arlimus commented Apr 20, 2016

i.e. 123 should { cmp /2+/ }

@alexpop
Copy link
Contributor

alexpop commented Apr 20, 2016

I made a small change to support the Integer example in the PR request. It will also provide the cmp matching capabilities for this use-case: #666 👿

Like:

describe file('/etc/shadow') do
  its('mode') { should cmp /0(0|4)00/ }
end

UPDATE:
^ because mode returns Integer at the moment, the regex will have to be adapted for Integers, like:

describe file('/etc/shadow') do
  its('mode') { should cmp /^(256|0)$/ }
end

or converted to octal string:

describe file('/etc/shadow').mode.to_s(8) do
  it { should cmp /(0|4)00/ }
end

or for a way to get the file mode in octal.

@alexpop
Copy link
Contributor

alexpop commented Apr 20, 2016

While updating the integration tests for cmp, I've noticed that there were a bunch of other tests failing:

For example:

bundle exec kitchen verify default-centos-67
...
Finished in 1.43 seconds (files took 1.22 seconds to load)
200 examples, 20 failures, 11 pending

Failed examples:

rspec  # Apache Config /etc/httpd/conf/httpd.conf LogLevel should eq "warn"
rspec  # Apache Config /etc/httpd/conf/httpd.conf MaxKeepAliveRequests should eq "100"
rspec  #  should cmp 0
rspec  # SSH Configuration Port should eq "22"
rspec  # SSH Configuration Port should cmp "22"
rspec  # SSH Configuration Port should cmp 22
rspec  # SSH Configuration Port should cmp 22.0
rspec  # SSH Configuration Port should not cmp 22.1
rspec  # SSH Configuration LogLevel should eq "INFO"
rspec  # SSH Configuration LogLevel should cmp "INFO"
rspec  # SSH Configuration LogLevel should cmp "info"
rspec  # SSH Configuration LogLevel should cmp "InfO"
rspec  # /etc/group users should include "root"
rspec  # #<Inspec::Resources::EtcGroupView:0x007f90a621f6b8> users should include "root"
rspec  # File /tmp/file mode should cmp "0765"
rspec  # File /mnt/iso-disk should be mounted
rspec  # File /mnt/iso-disk should be mounted
rspec  # Mount /mnt/iso-disk options should eq ["ro"]
rspec  # PostgreSQL query: show ssl; output should eq "on"
rspec  # User root groups should include ["root"]

Are integration tests not run on PRs?

@srenatus
Copy link
Contributor

@alexpop: currently, they require vagrant and are not run automatically at all. Improvements needed! 👍

@arlimus
Copy link
Contributor Author

arlimus commented Apr 20, 2016

@alexpop let's address the missing tests separately, we might need a workaround with travis here...

Everything else looks great 👍 Thank you for the improvements

@arlimus arlimus merged commit 979d65a into master Apr 20, 2016
@arlimus arlimus deleted the dr/cmp-regex branch April 20, 2016 16:02
@arlimus arlimus mentioned this pull request Apr 20, 2016
@fcaviggia
Copy link

Awesome work! These are great improvements!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants