ThoughtWorksInc/go-cookbook — pull request #15 by keymon (2014-05-30 13:36:48+00:00)
Title: Fixing search to search for the go server in the expanded run_list

If you enable agent "autoregistration" without the go server attribute, the current search query will fail with this error:

```
Net::HTTPServerException: 400 "Bad Request"
from /opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:2633:in `error!'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/http.rb:140:in `request'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/rest.rb:106:in `get'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/search/query.rb:42:in `search'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/dsl/data_query.rb:40:in `search'
from (irb):1
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/shell.rb:74:in `block in start'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/shell.rb:73:in `catch'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/shell.rb:73:in `start'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/bin/chef-shell:37:in `'
from /usr/bin/chef-shell:23:in `load'
from /usr/bin/chef-shell:23:in `

'
```

Actually the problem is that the problem is that the search query should be escaped twice because uses double quotes:

```
search(:node, "chef_environment:#{node.chef_environment} AND run_list:recipe\[go\:\:server\]")
```
vs
```
search(:node, "chef_environment:#{node.chef_environment} AND run_list:recipe\\[go\\:\\:server\\]")
```
But a second problem is that `run_list:recipe\\[go\\:\\:server\\]` will only search in the original run_list, so you can not use roles or wrapper cookbooks. The right syntax should be:

```
search(:node, "chef_environment:#{node.environment} AND recipes:go\\:\\:server")
```

I fixed it and this is the PR. I bumped the version because I need it right now, hope is OK with you.

I am adding a test now using chef-zero, adding a new suite. Lets see if it works and I will send a second PR.