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

Read Chef attributes within the tests ? #813

Closed
spuranam opened this issue Jul 5, 2016 · 4 comments
Closed

Read Chef attributes within the tests ? #813

spuranam opened this issue Jul 5, 2016 · 4 comments
Labels
Type: Bug Feature not working as expected

Comments

@spuranam
Copy link
Contributor

spuranam commented Jul 5, 2016

Description

Issue 541 provided a way to consume chef attributes in the Inspec tests. But this workaround was broken by ChefDK 0.15.15.

InSpec and Platform Version

ChefDK 0.15.15
OS: Windows 10
VirtualBox: 5.0.22
Vagrant: 1.8.4

Replication Case

I have posted a reproduce able minimal project at https://github.com/spuranam/hello.

Stacktrace

-----> Starting Kitchen (v1.10.0)
-----> Verifying <default-leap>...
       Use `C:/Users/spuranam/chef-repo/cookbooks/hello/test/integration/default` for testing
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [undefined method `[]' for nil:NilClass] on default-leap
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration
@jeremymv2
Copy link
Contributor

This can be accomplished with an inspec profile, which is how I've been achieving this for a while.

https://github.com/jeremymv2/test-inspec/blob/master/test/integration/profile/libraries/node.rb

It seems to be that node = json('/tmp/kitchen_chef_node.json').params when run in a non-inspec-profile is trying to open /tmp/kitchen_chef_node.json on the host machine, not in the TK instance and therefore you are getting the nil:NilClass error.

When using an inspec profile, this is not the case.

class NodeAttributes < Inspec::Resources::JsonConfig
  name 'node'
  def initialize
    super('/tmp/node.json')
  end
end
describe package('vim-minimal') do
  it { should be_installed }
  its('version') { should eq node.value(['vim','version']) }
end

@xTNTx
Copy link

xTNTx commented Jul 11, 2016

@spuranam The core bug is described in issue above. It was present earlier but came up once default formatter was changed to cli. As temporary fix, change it back to progress, e.g. in your .kitchen.yml:

verifier:
  name: inspec
  format: progress

@chris-rock chris-rock added the Type: Bug Feature not working as expected label Jul 11, 2016
@xTNTx
Copy link

xTNTx commented Jul 17, 2016

Fixed by #828

@chris-rock
Copy link
Contributor

Please reopen, if the problem still occurs. Thanks for the additional testing @xTNTx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

No branches or pull requests

4 participants