chef-boneyard / minitest-chef-handler

Run minitest suites after your Chef recipes to check the status of your system.
Other
163 stars 44 forks source link

assert_directory returns 'nil' instead of the owner/group of the directory #74

Closed scarolan closed 10 years ago

scarolan commented 11 years ago

This can be reproduced on Chef 11.8, with the latest version of minitest-chef-handler from the git repo.

[#] The file /local/apps/mobile does not have the expected owner. [#] Expected: "appuser" [#] Actual: nil

I logged onto the machine and verified that this directory is indeed owned by appuser:appuser.

calavera commented 11 years ago

This is probably dup of several issues that have been reported with similar behavior.

minitest-chef-handler uses Chef internals to load Chef resources, at https://github.com/calavera/minitest-chef-handler/blob/master/lib/minitest-chef-handler/resources.rb. Something has changed in the way that the resources are loaded to make some assertions and resource loaders to stop working with recent versions of Chef.

scarolan commented 11 years ago

Thank you. I'll mention this to some of the folks at Opscode and see what they say.

haidangwa commented 10 years ago

Any progress on this?

I found that if I use the directory method instead of assert_directory, it works fine.

it "assert /tmp" do
    directory("/tmp").must_exist.with(:owner, 'root').with(:group,'root').with(:mode, "770")
end

This is rather verbose compared to assert_directory, but at least it works.

calavera commented 10 years ago

Oh that's interesting. I checked the code and it looks like we're not calling directory but file. I guess at some point they behaved similarly and that changed in newer versions of chef:

https://github.com/calavera/minitest-chef-handler/blob/master/lib/minitest-chef-handler/assertions.rb#L131

def assert_directory(dir, *args)
  assert File.directory?(dir), "Expected #{dir} to be a directory"
  assert_acl(dir, *args)
end

def assert_acl(file, owner, group, mode)
  file(file).
    must_have(:owner, owner).
    must_have(:group, group).
    must_have(:mode, mode)
end

So, fixing that it should work properly. I'd really appreciate if you could test this theory and open a PR with the change. I can release a new version of the gem as soon as it's verified.

calavera commented 10 years ago

I've released 1.0.2 with the fix for this issue. Closing this, thanks for reporting it.