ridley 0.10.2 → 0.11.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +147 -216
- data/lib/ridley.rb +2 -0
- data/lib/ridley/bootstrap_bindings/unix_template_binding.rb +21 -25
- data/lib/ridley/bootstrap_bindings/windows_template_binding.rb +29 -34
- data/lib/ridley/bootstrapper.rb +2 -2
- data/lib/ridley/bootstrapper/context.rb +5 -5
- data/lib/ridley/chef.rb +0 -1
- data/lib/ridley/chef/cookbook.rb +0 -9
- data/lib/ridley/chef_object.rb +128 -0
- data/lib/ridley/chef_objects.rb +3 -0
- data/lib/ridley/chef_objects/client_object.rb +55 -0
- data/lib/ridley/chef_objects/cookbook_object.rb +190 -0
- data/lib/ridley/chef_objects/data_bag_item_obect.rb +104 -0
- data/lib/ridley/chef_objects/data_bag_object.rb +31 -0
- data/lib/ridley/chef_objects/environment_object.rb +59 -0
- data/lib/ridley/chef_objects/node_object.rb +161 -0
- data/lib/ridley/chef_objects/role_object.rb +62 -0
- data/lib/ridley/chef_objects/sandbox_object.rb +58 -0
- data/lib/ridley/client.rb +76 -45
- data/lib/ridley/connection.rb +1 -1
- data/lib/ridley/errors.rb +8 -1
- data/lib/ridley/host_connector.rb +26 -6
- data/lib/ridley/host_connector/ssh.rb +3 -3
- data/lib/ridley/host_connector/ssh/worker.rb +7 -9
- data/lib/ridley/host_connector/winrm/worker.rb +4 -5
- data/lib/ridley/mixin/bootstrap_binding.rb +1 -12
- data/lib/ridley/resource.rb +51 -171
- data/lib/ridley/resources/client_resource.rb +18 -68
- data/lib/ridley/resources/cookbook_resource.rb +181 -381
- data/lib/ridley/resources/data_bag_item_resource.rb +55 -161
- data/lib/ridley/resources/data_bag_resource.rb +20 -61
- data/lib/ridley/resources/environment_resource.rb +9 -64
- data/lib/ridley/resources/node_resource.rb +135 -311
- data/lib/ridley/resources/role_resource.rb +1 -57
- data/lib/ridley/resources/sandbox_resource.rb +80 -65
- data/lib/ridley/resources/search_resource.rb +99 -0
- data/lib/ridley/sandbox_uploader.rb +12 -52
- data/lib/ridley/version.rb +1 -1
- data/spec/acceptance/bootstrapping_spec.rb +1 -1
- data/spec/acceptance/client_resource_spec.rb +15 -37
- data/spec/acceptance/data_bag_item_resource_spec.rb +8 -14
- data/spec/acceptance/data_bag_resource_spec.rb +1 -1
- data/spec/acceptance/environment_resource_spec.rb +13 -22
- data/spec/acceptance/node_resource_spec.rb +10 -29
- data/spec/acceptance/role_resource_spec.rb +14 -13
- data/spec/acceptance/sandbox_resource_spec.rb +2 -2
- data/spec/support/shared_examples/ridley_resource.rb +2 -23
- data/spec/unit/ridley/bootstrap_bindings/unix_template_binding_spec.rb +3 -4
- data/spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb +3 -5
- data/spec/unit/ridley/bootstrapper/context_spec.rb +2 -3
- data/spec/unit/ridley/bootstrapper_spec.rb +1 -1
- data/spec/unit/ridley/chef_object_spec.rb +240 -0
- data/spec/unit/ridley/chef_objects/client_object_spec.rb +11 -0
- data/spec/unit/ridley/chef_objects/cookbook_object_spec.rb +93 -0
- data/spec/unit/ridley/chef_objects/data_bag_item_object_spec.rb +74 -0
- data/spec/unit/ridley/chef_objects/data_bag_object_spec.rb +9 -0
- data/spec/unit/ridley/chef_objects/environment_object_spec.rb +57 -0
- data/spec/unit/ridley/chef_objects/node_object_spec.rb +252 -0
- data/spec/unit/ridley/chef_objects/role_object_spec.rb +57 -0
- data/spec/unit/ridley/chef_objects/sandbox_object_spec.rb +66 -0
- data/spec/unit/ridley/client_spec.rb +51 -51
- data/spec/unit/ridley/host_connector/ssh/worker_spec.rb +4 -4
- data/spec/unit/ridley/host_connector/ssh_spec.rb +26 -24
- data/spec/unit/ridley/host_connector/winrm/worker_spec.rb +3 -4
- data/spec/unit/ridley/host_connector/winrm_spec.rb +4 -4
- data/spec/unit/ridley/host_connector_spec.rb +40 -3
- data/spec/unit/ridley/mixin/bootstrap_binding_spec.rb +1 -1
- data/spec/unit/ridley/resource_spec.rb +81 -109
- data/spec/unit/ridley/resources/client_resource_spec.rb +18 -33
- data/spec/unit/ridley/resources/cookbook_resource_spec.rb +56 -230
- data/spec/unit/ridley/resources/data_bag_item_resource_spec.rb +2 -57
- data/spec/unit/ridley/resources/data_bag_resource_spec.rb +12 -7
- data/spec/unit/ridley/resources/environment_resource_spec.rb +10 -118
- data/spec/unit/ridley/resources/node_resource_spec.rb +83 -394
- data/spec/unit/ridley/resources/role_resource_spec.rb +2 -56
- data/spec/unit/ridley/resources/sandbox_resource_spec.rb +139 -136
- data/spec/unit/ridley/resources/search_resource_spec.rb +234 -0
- data/spec/unit/ridley/sandbox_uploader_spec.rb +13 -58
- metadata +36 -17
- data/lib/ridley/chef/chefignore.rb +0 -76
- data/lib/ridley/resources/encrypted_data_bag_item_resource.rb +0 -55
- data/lib/ridley/resources/search.rb +0 -101
- data/spec/fixtures/chefignore +0 -8
- data/spec/unit/ridley/chef/chefignore_spec.rb +0 -40
- data/spec/unit/ridley/resources/search_spec.rb +0 -221
@@ -1,61 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ridley::RoleResource do
|
4
|
-
|
4
|
+
subject { described_class.new(double) }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
subject { Ridley::RoleResource.new(connection) }
|
9
|
-
|
10
|
-
describe "#set_override_attribute" do
|
11
|
-
it "sets an override node attribute at the nested path" do
|
12
|
-
subject.set_override_attribute('deep.nested.item', true)
|
13
|
-
|
14
|
-
subject.override_attributes.should have_key("deep")
|
15
|
-
subject.override_attributes["deep"].should have_key("nested")
|
16
|
-
subject.override_attributes["deep"]["nested"].should have_key("item")
|
17
|
-
subject.override_attributes["deep"]["nested"]["item"].should be_true
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when the override attribute is already set" do
|
21
|
-
it "test" do
|
22
|
-
subject.override_attributes = {
|
23
|
-
deep: {
|
24
|
-
nested: {
|
25
|
-
item: false
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
subject.set_override_attribute('deep.nested.item', true)
|
30
|
-
|
31
|
-
subject.override_attributes["deep"]["nested"]["item"].should be_true
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#set_default_attribute" do
|
37
|
-
it "sets an override node attribute at the nested path" do
|
38
|
-
subject.set_default_attribute('deep.nested.item', true)
|
39
|
-
|
40
|
-
subject.default_attributes.should have_key("deep")
|
41
|
-
subject.default_attributes["deep"].should have_key("nested")
|
42
|
-
subject.default_attributes["deep"]["nested"].should have_key("item")
|
43
|
-
subject.default_attributes["deep"]["nested"]["item"].should be_true
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when the override attribute is already set" do
|
47
|
-
it "test" do
|
48
|
-
subject.default_attributes = {
|
49
|
-
deep: {
|
50
|
-
nested: {
|
51
|
-
item: false
|
52
|
-
}
|
53
|
-
}
|
54
|
-
}
|
55
|
-
subject.set_default_attribute('deep.nested.item', true)
|
56
|
-
|
57
|
-
subject.default_attributes["deep"]["nested"]["item"].should be_true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
6
|
+
pending
|
61
7
|
end
|
@@ -1,172 +1,175 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ridley::SandboxResource do
|
4
|
-
let(:server_url) { "https://api.opscode.com/organizations/vialstudios" }
|
5
4
|
let(:client_name) { "reset" }
|
6
|
-
let(:client_key) { fixtures_path.join(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
).
|
14
|
-
|
5
|
+
let(:client_key) { fixtures_path.join('reset.pem') }
|
6
|
+
let(:connection) { double('chef-connection') }
|
7
|
+
subject { described_class.new(double, client_name, client_key) }
|
8
|
+
before { subject.stub(connection: connection) }
|
9
|
+
|
10
|
+
describe "#create" do
|
11
|
+
let(:sandbox_id) { "bd091b150b0a4578b97771af6abf3e05" }
|
12
|
+
let(:sandbox_uri) { "https://api.opscode.com/organizations/vialstudios/sandboxes/bd091b150b0a4578b97771af6abf3e05" }
|
13
|
+
let(:checksums) { Hash.new }
|
14
|
+
let(:response) do
|
15
|
+
double(body: { uri: sandbox_uri, checksums: checksums, sandbox_id: sandbox_id })
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
checksums: {},
|
26
|
-
sandbox_id: "bd091b150b0a4578b97771af6abf3e05"
|
27
|
-
})
|
28
|
-
end
|
18
|
+
before(:each) do
|
19
|
+
connection.stub(:post).
|
20
|
+
with(subject.class.resource_path, MultiJson.encode(checksums: checksums)).
|
21
|
+
and_return(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a Ridley::SandboxObject" do
|
25
|
+
subject.create.should be_a(Ridley::SandboxObject)
|
26
|
+
end
|
29
27
|
|
30
|
-
|
28
|
+
it "has a value of 'false' for :is_completed" do
|
29
|
+
subject.create.is_completed.should be_false
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
it "has an empty Hash of checksums" do
|
33
|
+
subject.create.checksums.should be_a(Hash)
|
34
|
+
subject.create.checksums.should be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a value for :uri" do
|
38
|
+
subject.create.uri.should eql(sandbox_uri)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has a value for :sandbox_id" do
|
42
|
+
subject.create.sandbox_id.should eql(sandbox_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when given an array of checksums" do
|
46
|
+
let(:checksums) do
|
47
|
+
{
|
48
|
+
"385ea5490c86570c7de71070bce9384a" => nil,
|
49
|
+
"f6f73175e979bd90af6184ec277f760c" => nil,
|
50
|
+
"2e03dd7e5b2e6c8eab1cf41ac61396d5" => nil
|
51
|
+
}
|
34
52
|
end
|
35
53
|
|
36
|
-
|
37
|
-
|
54
|
+
let(:checksum_array) { checksums.keys }
|
55
|
+
|
56
|
+
it "has a Hash of checksums with each of the given checksum ids" do
|
57
|
+
subject.create(checksum_array).checksums.should have(checksum_array.length).checksums
|
38
58
|
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#commit" do
|
63
|
+
let(:sandbox_id) { "bd091b150b0a4578b97771af6abf3e05" }
|
64
|
+
let(:sandbox_path) { "#{described_class.resource_path}/#{sandbox_id}" }
|
65
|
+
|
66
|
+
let(:response) do
|
67
|
+
double(body: {
|
68
|
+
is_completed: true,
|
69
|
+
_rev: "1-bbc8a96f7486aeba2b562d382142fd68",
|
70
|
+
create_time: "2013-01-16T01:43:43+00:00",
|
71
|
+
guid: "bd091b150b0a4578b97771af6abf3e05",
|
72
|
+
json_class: "Chef::Sandbox",
|
73
|
+
name: "bd091b150b0a4578b97771af6abf3e05",
|
74
|
+
checksums: [],
|
75
|
+
chef_type: "sandbox"
|
76
|
+
})
|
77
|
+
end
|
39
78
|
|
40
|
-
|
41
|
-
|
42
|
-
|
79
|
+
it "sends a /PUT to the sandbox resource with is_complete set to true" do
|
80
|
+
connection.should_receive(:put).with(sandbox_path, MultiJson.encode(is_completed: true)).and_return(response)
|
81
|
+
|
82
|
+
subject.commit(sandbox_id)
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when a sandbox of the given ID is not found" do
|
86
|
+
before do
|
87
|
+
connection.should_receive(:put).and_raise(Ridley::Errors::HTTPNotFound.new({}))
|
43
88
|
end
|
44
89
|
|
45
|
-
it "
|
46
|
-
|
90
|
+
it "raises a ResourceNotFound error" do
|
91
|
+
expect {
|
92
|
+
subject.commit(sandbox_id)
|
93
|
+
}.to raise_error(Ridley::Errors::ResourceNotFound)
|
47
94
|
end
|
95
|
+
end
|
48
96
|
|
49
|
-
|
50
|
-
|
97
|
+
context "when the given sandbox contents are malformed" do
|
98
|
+
before do
|
99
|
+
connection.should_receive(:put).and_raise(Ridley::Errors::HTTPBadRequest.new({}))
|
51
100
|
end
|
52
101
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"f6f73175e979bd90af6184ec277f760c" => nil,
|
58
|
-
"2e03dd7e5b2e6c8eab1cf41ac61396d5" => nil
|
59
|
-
}
|
60
|
-
end
|
61
|
-
let(:checksum_array) { checksums.keys }
|
62
|
-
|
63
|
-
before(:each) do
|
64
|
-
stub_request(:post, File.join(server_url, "sandboxes")).
|
65
|
-
with(body: MultiJson.encode(checksums: checksums)).
|
66
|
-
to_return(status: 200, body: {
|
67
|
-
"uri" => "https://api.opscode.com/organizations/vialstudios/sandboxes/bd091b150b0a4578b97771af6abf3e05",
|
68
|
-
"checksums" => {
|
69
|
-
"385ea5490c86570c7de71070bce9384a" => {
|
70
|
-
"url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
|
71
|
-
"needs_upload" => true
|
72
|
-
},
|
73
|
-
"f6f73175e979bd90af6184ec277f760c" => {
|
74
|
-
"url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
|
75
|
-
"needs_upload" => true
|
76
|
-
},
|
77
|
-
"2e03dd7e5b2e6c8eab1cf41ac61396d5" => {
|
78
|
-
"url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
|
79
|
-
"needs_upload" => true
|
80
|
-
},
|
81
|
-
},
|
82
|
-
"sandbox_id" => "bd091b150b0a4578b97771af6abf3e05"
|
83
|
-
})
|
84
|
-
end
|
85
|
-
|
86
|
-
subject { sandbox.create(checksum_array) }
|
87
|
-
|
88
|
-
it "has a Hash of checksums with each of the given checksum ids" do
|
89
|
-
subject.checksums.should have(checksum_array.length).checksums
|
90
|
-
end
|
102
|
+
it "raises a SandboxCommitError error" do
|
103
|
+
expect {
|
104
|
+
subject.commit(sandbox_id)
|
105
|
+
}.to raise_error(Ridley::Errors::SandboxCommitError)
|
91
106
|
end
|
92
107
|
end
|
93
|
-
end
|
94
108
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
"checksums" => {
|
99
|
-
"385ea5490c86570c7de71070bce9384a" => {
|
100
|
-
"url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
|
101
|
-
"needs_upload" => true
|
102
|
-
},
|
103
|
-
"f6f73175e979bd90af6184ec277f760c" => {
|
104
|
-
"url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
|
105
|
-
"needs_upload" => true
|
106
|
-
},
|
107
|
-
"2e03dd7e5b2e6c8eab1cf41ac61396d5" => {
|
108
|
-
"url" => "https://s3.amazonaws.com/opscode-platform-production-data/organization",
|
109
|
-
"needs_upload" => true
|
110
|
-
},
|
111
|
-
},
|
112
|
-
"sandbox_id" => "bd091b150b0a4578b97771af6abf3e05"
|
113
|
-
)
|
114
|
-
end
|
109
|
+
context "when the user who made the request is not authorized" do
|
110
|
+
it "raises a PermissionDenied error on unauthorized" do
|
111
|
+
connection.should_receive(:put).and_raise(Ridley::Errors::HTTPUnauthorized.new({}))
|
115
112
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
stub_request(:put, File.join(server_url, "sandboxes", "bd091b150b0a4578b97771af6abf3e05")).
|
120
|
-
with(body: MultiJson.encode(is_completed: true)).
|
121
|
-
to_return(status: 200, body: {
|
122
|
-
is_completed: true,
|
123
|
-
_rev: "1-bbc8a96f7486aeba2b562d382142fd68",
|
124
|
-
create_time: "2013-01-16T01:43:43+00:00",
|
125
|
-
guid: "bd091b150b0a4578b97771af6abf3e05",
|
126
|
-
json_class: "Chef::Sandbox",
|
127
|
-
name: "bd091b150b0a4578b97771af6abf3e05",
|
128
|
-
checksums: [],
|
129
|
-
chef_type: "sandbox"
|
130
|
-
})
|
113
|
+
expect {
|
114
|
+
subject.commit(sandbox_id)
|
115
|
+
}.to raise_error(Ridley::Errors::PermissionDenied)
|
131
116
|
end
|
132
117
|
|
133
|
-
it "
|
134
|
-
|
118
|
+
it "raises a PermissionDenied error on forbidden" do
|
119
|
+
connection.should_receive(:put).and_raise(Ridley::Errors::HTTPForbidden.new({}))
|
135
120
|
|
136
|
-
|
121
|
+
expect {
|
122
|
+
subject.commit(sandbox_id)
|
123
|
+
}.to raise_error(Ridley::Errors::PermissionDenied)
|
137
124
|
end
|
138
125
|
end
|
126
|
+
end
|
139
127
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
create_time: "2013-01-16T01:43:43+00:00",
|
148
|
-
guid: "bd091b150b0a4578b97771af6abf3e05",
|
149
|
-
json_class: "Chef::Sandbox",
|
150
|
-
name: "bd091b150b0a4578b97771af6abf3e05",
|
151
|
-
checksums: [],
|
152
|
-
chef_type: "sandbox"
|
153
|
-
})
|
154
|
-
end
|
128
|
+
describe "#update" do
|
129
|
+
it "is not a supported action" do
|
130
|
+
expect {
|
131
|
+
subject.update(anything)
|
132
|
+
}.to raise_error(RuntimeError, "action not supported")
|
133
|
+
end
|
134
|
+
end
|
155
135
|
|
156
|
-
|
157
|
-
|
136
|
+
describe "#update" do
|
137
|
+
it "is not a supported action" do
|
138
|
+
expect {
|
139
|
+
subject.update
|
140
|
+
}.to raise_error(RuntimeError, "action not supported")
|
141
|
+
end
|
142
|
+
end
|
158
143
|
|
159
|
-
|
160
|
-
|
144
|
+
describe "#all" do
|
145
|
+
it "is not a supported action" do
|
146
|
+
expect {
|
147
|
+
subject.all
|
148
|
+
}.to raise_error(RuntimeError, "action not supported")
|
161
149
|
end
|
162
150
|
end
|
163
151
|
|
164
|
-
describe "#
|
165
|
-
it "
|
166
|
-
|
167
|
-
|
152
|
+
describe "#find" do
|
153
|
+
it "is not a supported action" do
|
154
|
+
expect {
|
155
|
+
subject.find
|
156
|
+
}.to raise_error(RuntimeError, "action not supported")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#delete" do
|
161
|
+
it "is not a supported action" do
|
162
|
+
expect {
|
163
|
+
subject.delete
|
164
|
+
}.to raise_error(RuntimeError, "action not supported")
|
165
|
+
end
|
166
|
+
end
|
168
167
|
|
169
|
-
|
168
|
+
describe "#delete_all" do
|
169
|
+
it "is not a supported action" do
|
170
|
+
expect {
|
171
|
+
subject.delete_all
|
172
|
+
}.to raise_error(RuntimeError, "action not supported")
|
170
173
|
end
|
171
174
|
end
|
172
175
|
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ridley::SearchResource do
|
4
|
+
describe "ClassMethods" do
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
describe "::build_query" do
|
8
|
+
let(:query_string) { "*:*" }
|
9
|
+
let(:options) { Hash.new }
|
10
|
+
|
11
|
+
it "contains a 'q' key/value" do
|
12
|
+
result = subject.build_query(query_string, options)
|
13
|
+
|
14
|
+
result.should have_key(:q)
|
15
|
+
result[:q].should eql(query_string)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when :sort option is set" do
|
19
|
+
before { options[:sort] = "DESC" }
|
20
|
+
|
21
|
+
it "contains a 'sort' key/value" do
|
22
|
+
result = subject.build_query(query_string, options)
|
23
|
+
|
24
|
+
result.should have_key(:sort)
|
25
|
+
result[:sort].should eql("DESC")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when :start option is set" do
|
30
|
+
before { options[:start] = 1 }
|
31
|
+
|
32
|
+
it "contains a 'start' key/value" do
|
33
|
+
result = subject.build_query(query_string, options)
|
34
|
+
|
35
|
+
result.should have_key(:start)
|
36
|
+
result[:start].should eql(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when :rows option is set" do
|
41
|
+
before { options[:rows] = 1 }
|
42
|
+
|
43
|
+
it "contains a 'rows' key/value" do
|
44
|
+
result = subject.build_query(query_string, options)
|
45
|
+
|
46
|
+
result.should have_key(:rows)
|
47
|
+
result[:rows].should eql(1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "::query_uri" do
|
53
|
+
it "returns a URI path containing the search resource path and index" do
|
54
|
+
subject.query_uri(:nodes).should eql("search/nodes")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:connection) { double('chef-connection') }
|
60
|
+
subject { described_class.new(double('registry')) }
|
61
|
+
before { subject.stub(connection: connection) }
|
62
|
+
|
63
|
+
describe "#indexes" do
|
64
|
+
let(:response) do
|
65
|
+
double(body: {
|
66
|
+
node: "http://localhost:4000/search/node",
|
67
|
+
role: "http://localhost:4000/search/role",
|
68
|
+
client: "http://localhost:4000/search/client",
|
69
|
+
users: "http://localhost:4000/search/users"
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
before do
|
74
|
+
connection.stub(:get).with(described_class.resource_path).and_return(response)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "performs a GET to the search resource_path" do
|
78
|
+
connection.should_receive(:get).with(described_class.resource_path).and_return(response)
|
79
|
+
subject.indexes
|
80
|
+
end
|
81
|
+
|
82
|
+
it "contains a key for each index" do
|
83
|
+
subject.indexes.should have(4).items
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#run" do
|
88
|
+
let(:index) { :role }
|
89
|
+
let(:query_string) { "*:*" }
|
90
|
+
let(:options) { Hash.new }
|
91
|
+
let(:response) do
|
92
|
+
double(body: {
|
93
|
+
rows: Array.new,
|
94
|
+
total: 0,
|
95
|
+
start: 0
|
96
|
+
})
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:run) { subject.run(index, query_string) }
|
100
|
+
|
101
|
+
before do
|
102
|
+
connection.stub(:get).and_return(response)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "builds a query and runs it against the index's resource path" do
|
106
|
+
query = double('query')
|
107
|
+
query_uri = double('query-uri')
|
108
|
+
described_class.should_receive(:build_query).with(query_string, options).and_return(query)
|
109
|
+
described_class.should_receive(:query_uri).with(index).and_return(query_uri)
|
110
|
+
connection.should_receive(:get).with(query_uri, query).and_return(response)
|
111
|
+
|
112
|
+
subject.run(index, query_string, options)
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when :node is the given index" do
|
116
|
+
let(:index) { :node }
|
117
|
+
let(:response) do
|
118
|
+
double(body: {
|
119
|
+
rows: [
|
120
|
+
{
|
121
|
+
chef_type: "node",
|
122
|
+
json_class: "Chef::Node",
|
123
|
+
name: "ridley-one",
|
124
|
+
chef_environment: "_default",
|
125
|
+
automatic: {},
|
126
|
+
normal: {},
|
127
|
+
default: {},
|
128
|
+
override: {},
|
129
|
+
run_list: [
|
130
|
+
"recipe[one]",
|
131
|
+
"recipe[two]"
|
132
|
+
]
|
133
|
+
}
|
134
|
+
],
|
135
|
+
total: 1,
|
136
|
+
start: 0
|
137
|
+
})
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns an array of Ridley::NodeObject" do
|
141
|
+
result = run
|
142
|
+
|
143
|
+
result.should be_a(Array)
|
144
|
+
result.should each be_a(Ridley::NodeObject)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when :role is the given index" do
|
149
|
+
let(:index) { :role }
|
150
|
+
let(:response) do
|
151
|
+
double(body: {
|
152
|
+
rows: [
|
153
|
+
{
|
154
|
+
chef_type: "role",
|
155
|
+
json_class: "Chef::Role",
|
156
|
+
name: "ridley-role-one",
|
157
|
+
description: "",
|
158
|
+
default_attributes: {},
|
159
|
+
override_attributes: {},
|
160
|
+
run_list: [],
|
161
|
+
env_run_lists: {}
|
162
|
+
}
|
163
|
+
],
|
164
|
+
total: 1,
|
165
|
+
start: 0
|
166
|
+
})
|
167
|
+
end
|
168
|
+
|
169
|
+
it "returns an array of Ridley::RoleObject" do
|
170
|
+
result = run
|
171
|
+
|
172
|
+
result.should be_a(Array)
|
173
|
+
result.should each be_a(Ridley::RoleObject)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when :environment is the given index" do
|
178
|
+
let(:index) { :environment }
|
179
|
+
let(:response) do
|
180
|
+
double(body: {
|
181
|
+
rows: [
|
182
|
+
{
|
183
|
+
chef_type: "environment",
|
184
|
+
json_class: "Chef::Environment",
|
185
|
+
name: "ridley-env-test",
|
186
|
+
description: "ridley testing environment",
|
187
|
+
default_attributes: {},
|
188
|
+
override_attributes: {},
|
189
|
+
cookbook_versions: {}
|
190
|
+
}
|
191
|
+
],
|
192
|
+
total: 1,
|
193
|
+
start: 0
|
194
|
+
})
|
195
|
+
end
|
196
|
+
|
197
|
+
it "returns an array of Ridley::EnvironmentObject" do
|
198
|
+
result = run
|
199
|
+
|
200
|
+
result.should be_a(Array)
|
201
|
+
result.should each be_a(Ridley::EnvironmentObject)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when :client is the given index" do
|
206
|
+
let(:index) { :client }
|
207
|
+
let(:response) do
|
208
|
+
double(body: {
|
209
|
+
rows: [
|
210
|
+
{
|
211
|
+
chef_type: "client",
|
212
|
+
name: nil,
|
213
|
+
admin: false,
|
214
|
+
validator: false,
|
215
|
+
certificate: "-----BEGIN CERTIFICATE-----\nMIIDOjCCAqOgAwIBAgIE47eOmDANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMC\nVVMxEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxFjAUBgNV\nBAoMDU9wc2NvZGUsIEluYy4xHDAaBgNVBAsME0NlcnRpZmljYXRlIFNlcnZpY2Ux\nMjAwBgNVBAMMKW9wc2NvZGUuY29tL2VtYWlsQWRkcmVzcz1hdXRoQG9wc2NvZGUu\nY29tMCAXDTEyMTAwOTAwMTUxNVoYDzIxMDExMTA0MDAxNTE1WjCBnTEQMA4GA1UE\nBxMHU2VhdHRsZTETMBEGA1UECBMKV2FzaGluZ3RvbjELMAkGA1UEBhMCVVMxHDAa\nBgNVBAsTE0NlcnRpZmljYXRlIFNlcnZpY2UxFjAUBgNVBAoTDU9wc2NvZGUsIElu\nYy4xMTAvBgNVBAMUKFVSSTpodHRwOi8vb3BzY29kZS5jb20vR1VJRFMvY2xpZW50\nX2d1aWQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCqB9KEGzl7Wcm/\nwz/x8HByZANCn6WQC+R12qQso5I6nLbTNkRP668jXG3j0R5/F5i/KearAB9ePzL/\nQe3iHtwW6u1qLI1hVNFNB+I1fGu1p6fZyIOjnLn3bqsbOkBplHOIqHsp4GVSsHKb\nD32UXZDa9S9ZFXnR4iT6hUGm5895ReZG9TDiHvBpi9NJFDZXz+AQ6JuQY8UgYMMA\nm80KbO8/NJlXbRW+siRuvr+LIsi9Mx4i63pBWAN46my291rQU31PF3IB+btfGtR/\nyDWDgMSB37bTzZeOf1Dg9fpl2vIXyu3PoHER0oYmrMQbrdwAt7qCHZNuNWn51WPb\n1PHxXL1rAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAGnJUVAv951fUhGyPOrl+LbQG\nqgchMwIn7oDLE863e66BYTDj7koK3jjhx3EBkrT2vt/xS4yW0ZRV1BNqfnNKWbBq\nMNQiKkYdTr+oq2O3plOg/q/M1eG1B5pxGXqvH0O76DVWQcV/svO+HQEi1n8y5UQd\n+pBJCygpuv78wPCM+c4=\n-----END CERTIFICATE-----\n",
|
216
|
+
public_key: nil,
|
217
|
+
private_key: nil,
|
218
|
+
orgname: "ridley"
|
219
|
+
}
|
220
|
+
],
|
221
|
+
total: 1,
|
222
|
+
start: 0
|
223
|
+
})
|
224
|
+
end
|
225
|
+
|
226
|
+
it "returns an array of Ridley::ClientObject" do
|
227
|
+
result = run
|
228
|
+
|
229
|
+
result.should be_a(Array)
|
230
|
+
result.should each be_a(Ridley::ClientObject)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|