1

I have written a cookbook to download tomcat (cookbook name = 'my_tomcat'). Resource does everything (resource name 'default.rb') and there is no recipe to it. Other cookbooks will call this resource to download the tomcat.

To test this tomcat cookbook, I have written a test cookbook in test/cookbooks/test/recipes/default.rb and added the dependency in berksfile of my cookbook. When I run kitchen test, it gives me below error-

================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/test/recipes/default.rb
================================================================================

   NoMethodError
   -------------
   No resource or method named `my_tomcat' for `Chef::Recipe "default"'

   Cookbook Trace:
   ---------------
     /tmp/kitchen/cache/cookbooks/test/recipes/default.rb:3:in `from_file'

   Relevant File Content:
   ----------------------
   /tmp/kitchen/cache/cookbooks/test/recipes/default.rb:

     1:  package 'java-1.7.0-openjdk'
     2:  
     3>> my_tomcat '/apps/tools/apache' do
     4:    version '7.0.32'
     5:  end
     6:  

Please let me know what I am doing wrong here. Do I need to do some more changes anywhere?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
user6378152
  • 257
  • 2
  • 6
  • 11

2 Answers2

1

Your cookbook test has to specify a dependency on your my_tomcat cookbook, so that its resources are loaded in advance.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
  • So I added this in my test cookbooks metadata.rb- depends 'my_tomcat' Do I need to add somewhere else as well? – user6378152 Dec 12 '16 at 20:19
  • I don't know, what you've put elsewhere. You have a `cookbook` line in `Berksfile` pointing to your _test_ cookbook, that's already a good start. Please provide more portions of your code. – StephenKing Dec 13 '16 at 07:25
  • My berksfile line- source 'somesource' metadata cookbook 'test', path: 'test/cookbooks/test' – user6378152 Dec 13 '16 at 15:25
  • And the metadata of your test cookbook? Are you as "newbie" already able to edit your post above? If yes, please do so. – StephenKing Dec 13 '16 at 17:01
0

No resource or method could mean one of a couple things. The very first thing you need to do is make sure that, along with declaring the dependency on your cookbook in the test cookbook's Berksfile, you also add depends 'cookbook' to the test cookbook's metadata.rb file.

Once that's done, if the error persists, the next thing to check is that you're naming your custom resource correctly in the main cookbook.

If doing the first thing doesn't fix the problem, please add the content of your test cookbook's Berksfile and metadata.rb to the original question, along with the content of your custom resource file in the main cookbook.

sixty4bit
  • 7,422
  • 7
  • 33
  • 57