Open jaypipes opened 12 years ago
Hi Jay-
I'm not an expert on this, but I have written a bit of library code and corresponding specs. I'll show you what I've done that works.
Here's a snippet from a cookbook library that I extended to support NUMA nodes:
class Chef::ResourceDefinitionList::MongoDB
def self.numa_node
return false unless File.exist?("/sys/devices/system/node/node1")
first_line = File.open("/proc/self/numa_maps", "r").gets
first_line !~ /interleave/
end
Here's an example that tests it:
it 'numa_node returns true on NUMA node' do
File.stub(:exist?).with("/sys/devices/system/node/node1").and_return(true)
fake = File.open(FAKE_NUMA_MAPS_NO_INTERLEAVING, "w+")
fake.puts("default")
fake.close
File.stub(:open).with("/proc/self/numa_maps", "r").and_return(File.new(FAKE_NUMA_MAPS_NO_INTERLEAVING, "r"))
Chef::ResourceDefinitionList::MongoDB.numa_node.should be_true
end
There are some node references in the library, but the node is passed in as a parameter.
According to http://wiki.opscode.com/display/chef/Libraries, you need to reference node as an instance member (@node).
Hope this helps. And glad my little repo was helpful.
Hi Jim, thanks for putting this together. Very helpful.
I'm wondering if you have information as to how to test Chef libraries? I've been struggling to figure out how to do it...
Here's something I put together that I thought might work for my little library. The library routine is dirt simple:
and here is the spec I put together:
Unfortunately, this is what I get:
Any help or pointers would be REALLY appreciated!
-jay