chef-boneyard/minitest-chef-handler

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

Closed this issue · 5 comments

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.

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.

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

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.

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.

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