ridley 0.11.0.rc1 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -2
- data/Gemfile +1 -0
- data/Guardfile +2 -2
- data/Thorfile +2 -2
- data/lib/ridley/chef.rb +1 -0
- data/lib/ridley/chef/chefignore.rb +76 -0
- data/lib/ridley/chef/cookbook.rb +17 -7
- data/lib/ridley/chef/cookbook/metadata.rb +8 -0
- data/lib/ridley/chef_objects/cookbook_object.rb +21 -37
- data/lib/ridley/chef_objects/data_bag_item_obect.rb +9 -0
- data/lib/ridley/client.rb +2 -2
- data/lib/ridley/connection.rb +12 -6
- data/lib/ridley/errors.rb +14 -0
- data/lib/ridley/host_connector.rb +10 -3
- data/lib/ridley/resource.rb +25 -5
- data/lib/ridley/resources/cookbook_resource.rb +19 -9
- data/lib/ridley/resources/data_bag_item_resource.rb +8 -4
- data/lib/ridley/resources/search_resource.rb +5 -5
- data/lib/ridley/sandbox_uploader.rb +6 -0
- data/lib/ridley/version.rb +1 -1
- data/ridley.gemspec +1 -1
- data/spec/acceptance/client_resource_spec.rb +44 -62
- data/spec/acceptance/cookbook_resource_spec.rb +27 -0
- data/spec/acceptance/data_bag_item_resource_spec.rb +36 -54
- data/spec/acceptance/data_bag_resource_spec.rb +9 -21
- data/spec/acceptance/environment_resource_spec.rb +34 -63
- data/spec/acceptance/node_resource_spec.rb +27 -47
- data/spec/acceptance/role_resource_spec.rb +27 -67
- data/spec/acceptance/sandbox_resource_spec.rb +3 -13
- data/spec/acceptance/search_resource_spec.rb +5 -15
- data/spec/fixtures/chefignore +8 -0
- data/spec/spec_helper.rb +15 -1
- data/spec/support/chef_server.rb +77 -0
- data/spec/unit/ridley/chef/chefignore_spec.rb +40 -0
- data/spec/unit/ridley/chef/cookbook_spec.rb +30 -2
- data/spec/unit/ridley/chef_objects/cookbook_object_spec.rb +3 -3
- data/spec/unit/ridley/connection_spec.rb +1 -2
- data/spec/unit/ridley/resources/cookbook_resource_spec.rb +85 -48
- data/spec/unit/ridley/resources/data_bag_resource_spec.rb +1 -1
- data/spec/unit/ridley/resources/search_resource_spec.rb +39 -2
- data/spec/unit/ridley/sandbox_uploader_spec.rb +25 -0
- metadata +19 -7
data/lib/ridley/resource.rb
CHANGED
@@ -45,7 +45,7 @@ module Ridley
|
|
45
45
|
#
|
46
46
|
# @return [Array<Object>]
|
47
47
|
def all
|
48
|
-
|
48
|
+
request(:get, self.class.resource_path).collect do |identity, location|
|
49
49
|
new(self.class.representation.chef_id => identity)
|
50
50
|
end
|
51
51
|
end
|
@@ -55,7 +55,7 @@ module Ridley
|
|
55
55
|
# @return [nil, Object]
|
56
56
|
def find(object)
|
57
57
|
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
|
58
|
-
new(
|
58
|
+
new(request(:get, "#{self.class.resource_path}/#{chef_id}"))
|
59
59
|
rescue Errors::HTTPNotFound => ex
|
60
60
|
nil
|
61
61
|
end
|
@@ -65,9 +65,11 @@ module Ridley
|
|
65
65
|
# @return [Object]
|
66
66
|
def create(object)
|
67
67
|
resource = new(object.to_hash)
|
68
|
-
new_attributes =
|
68
|
+
new_attributes = request(:post, self.class.resource_path, resource.to_json)
|
69
69
|
resource.mass_assign(resource._attributes_.deep_merge(new_attributes))
|
70
70
|
resource
|
71
|
+
rescue Errors::HTTPConflict => ex
|
72
|
+
abort(ex)
|
71
73
|
end
|
72
74
|
|
73
75
|
# @param [String, #chef_id] object
|
@@ -75,7 +77,7 @@ module Ridley
|
|
75
77
|
# @return [Object]
|
76
78
|
def delete(object)
|
77
79
|
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
|
78
|
-
new(
|
80
|
+
new(request(:delete, "#{self.class.resource_path}/#{chef_id}"))
|
79
81
|
end
|
80
82
|
|
81
83
|
# @return [Array<Object>]
|
@@ -90,7 +92,25 @@ module Ridley
|
|
90
92
|
# @return [Object]
|
91
93
|
def update(object)
|
92
94
|
resource = new(object.to_hash)
|
93
|
-
new(
|
95
|
+
new(request(:put, "#{self.class.resource_path}/#{resource.chef_id}", resource.to_json))
|
96
|
+
rescue Errors::HTTPConflict => ex
|
97
|
+
abort(ex)
|
94
98
|
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
# @param [Symbol] method
|
103
|
+
def request(method, *args)
|
104
|
+
raw_request(method, *args).body
|
105
|
+
end
|
106
|
+
|
107
|
+
# @param [Symbol] method
|
108
|
+
def raw_request(method, *args)
|
109
|
+
unless Connection::METHODS.include?(method)
|
110
|
+
raise
|
111
|
+
end
|
112
|
+
|
113
|
+
defer { connection.send(method, *args) }
|
114
|
+
end
|
95
115
|
end
|
96
116
|
end
|
@@ -6,7 +6,7 @@ module Ridley
|
|
6
6
|
|
7
7
|
def initialize(connection_registry, client_name, client_key, options = {})
|
8
8
|
super(connection_registry)
|
9
|
-
|
9
|
+
@sandbox_resource = SandboxResource.new_link(connection_registry, client_name, client_key, options)
|
10
10
|
end
|
11
11
|
|
12
12
|
# List all of the cookbooks and their versions present on the remote
|
@@ -25,7 +25,7 @@ module Ridley
|
|
25
25
|
# a hash containing keys which represent cookbook names and values which contain
|
26
26
|
# an array of strings representing the available versions
|
27
27
|
def all
|
28
|
-
response =
|
28
|
+
response = request(:get, self.class.resource_path)
|
29
29
|
|
30
30
|
{}.tap do |cookbooks|
|
31
31
|
response.each do |name, details|
|
@@ -47,7 +47,7 @@ module Ridley
|
|
47
47
|
url = "#{self.class.resource_path}/#{name}/#{version}"
|
48
48
|
url += "?purge=true" if options[:purge]
|
49
49
|
|
50
|
-
|
50
|
+
request(:delete, url)
|
51
51
|
true
|
52
52
|
rescue Errors::HTTPNotFound
|
53
53
|
true
|
@@ -73,13 +73,15 @@ module Ridley
|
|
73
73
|
# the place to download the cookbook too. If no value is provided the cookbook
|
74
74
|
# will be downloaded to a temporary location
|
75
75
|
#
|
76
|
+
# @raise [Errors::ResourceNotFound] if the target cookbook is not found
|
77
|
+
#
|
76
78
|
# @return [String]
|
77
79
|
# the path to the directory the cookbook was downloaded to
|
78
80
|
def download(name, version, destination = Dir.mktmpdir)
|
79
|
-
cookbook = find(name, version)
|
80
|
-
|
81
|
-
unless cookbook.nil?
|
81
|
+
if cookbook = find(name, version)
|
82
82
|
cookbook.download(destination)
|
83
|
+
else
|
84
|
+
abort Errors::ResourceNotFound.new("cookbook #{name} (#{version}) was not found")
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
@@ -89,7 +91,7 @@ module Ridley
|
|
89
91
|
# @return [nil, CookbookResource]
|
90
92
|
def find(object, version)
|
91
93
|
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
|
92
|
-
new(
|
94
|
+
new(request(:get, "#{self.class.resource_path}/#{chef_id}/#{version}"))
|
93
95
|
rescue Errors::HTTPNotFound
|
94
96
|
nil
|
95
97
|
end
|
@@ -98,6 +100,8 @@ module Ridley
|
|
98
100
|
#
|
99
101
|
# @param [String] name
|
100
102
|
#
|
103
|
+
# @raise [Errors::ResourceNotFound] if the target cookbook has no versions
|
104
|
+
#
|
101
105
|
# @return [String, nil]
|
102
106
|
def latest_version(name)
|
103
107
|
ver = versions(name).collect do |version|
|
@@ -114,6 +118,8 @@ module Ridley
|
|
114
118
|
# @param [String, Solve::Constraint] constraint
|
115
119
|
# constraint to solve for
|
116
120
|
#
|
121
|
+
# @raise [Errors::ResourceNotFound] if the target cookbook has no versions
|
122
|
+
#
|
117
123
|
# @return [CookbookResource, nil]
|
118
124
|
# returns the cookbook resource for the best solution or nil if no solution exists
|
119
125
|
def satisfy(name, constraint)
|
@@ -150,7 +156,7 @@ module Ridley
|
|
150
156
|
url = "cookbooks/#{cookbook.cookbook_name}/#{cookbook.version}"
|
151
157
|
url << "?force=true" if options[:force]
|
152
158
|
|
153
|
-
|
159
|
+
request(:put, url, cookbook.to_json)
|
154
160
|
rescue Ridley::Errors::HTTPConflict => ex
|
155
161
|
abort Ridley::Errors::FrozenCookbook.new(ex)
|
156
162
|
end
|
@@ -206,13 +212,17 @@ module Ridley
|
|
206
212
|
# @example
|
207
213
|
# versions("nginx") => [ "1.0.0", "1.2.0" ]
|
208
214
|
#
|
215
|
+
# @raise [Errors::ResourceNotFound] if the target cookbook has no versions
|
216
|
+
#
|
209
217
|
# @return [Array<String>]
|
210
218
|
def versions(name)
|
211
|
-
response =
|
219
|
+
response = request(:get, "#{self.class.resource_path}/#{name}")
|
212
220
|
|
213
221
|
response[name]["versions"].collect do |cb_ver|
|
214
222
|
cb_ver["version"]
|
215
223
|
end
|
224
|
+
rescue Errors::HTTPNotFound => ex
|
225
|
+
abort(Errors::ResourceNotFound.new(ex))
|
216
226
|
end
|
217
227
|
|
218
228
|
private
|
@@ -3,13 +3,13 @@ module Ridley
|
|
3
3
|
class DataBagItemResource < Ridley::Resource
|
4
4
|
represented_by Ridley::DataBagItemObject
|
5
5
|
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :encrypted_data_bag_secret
|
7
7
|
|
8
8
|
# @param [Celluloid::Registry] connection_registry
|
9
|
-
# @param [String]
|
10
|
-
def initialize(connection_registry,
|
9
|
+
# @param [String] encrypted_data_bag_secret
|
10
|
+
def initialize(connection_registry, encrypted_data_bag_secret)
|
11
11
|
super(connection_registry)
|
12
|
-
@
|
12
|
+
@encrypted_data_bag_secret = encrypted_data_bag_secret
|
13
13
|
end
|
14
14
|
|
15
15
|
# @param [Ridley::DataBagObject] data_bag
|
@@ -45,6 +45,8 @@ module Ridley
|
|
45
45
|
new_attributes = connection.post("#{DataBagResource.resource_path}/#{data_bag.name}", resource.to_json).body
|
46
46
|
resource.mass_assign(new_attributes)
|
47
47
|
resource
|
48
|
+
rescue Errors::HTTPConflict => ex
|
49
|
+
abort(ex)
|
48
50
|
end
|
49
51
|
|
50
52
|
# @param [Ridley::DataBagObject] data_bag
|
@@ -77,6 +79,8 @@ module Ridley
|
|
77
79
|
new(data_bag).from_hash(
|
78
80
|
connection.put("#{DataBagResource.resource_path}/#{data_bag.name}/#{resource.chef_id}", resource.to_json).body
|
79
81
|
)
|
82
|
+
rescue Errors::HTTPConflict => ex
|
83
|
+
abort(ex)
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
@@ -77,20 +77,20 @@ module Ridley
|
|
77
77
|
# }
|
78
78
|
#
|
79
79
|
# @return [Array<ChefObject>, Hash]
|
80
|
-
def run(index, query_string, options = {})
|
80
|
+
def run(index, query_string, resources_registry, options = {})
|
81
81
|
query_uri = self.class.query_uri(index)
|
82
82
|
query = self.class.build_query(query_string, options)
|
83
83
|
response = connection.get(query_uri, query).body
|
84
84
|
|
85
85
|
case index.to_sym
|
86
86
|
when :node
|
87
|
-
response[:rows].collect { |row| Ridley::NodeObject.new(row) }
|
87
|
+
response[:rows].collect { |row| Ridley::NodeObject.new(resources_registry[:node_resource], row) }
|
88
88
|
when :role
|
89
|
-
response[:rows].collect { |row| Ridley::RoleObject.new(row) }
|
89
|
+
response[:rows].collect { |row| Ridley::RoleObject.new(resources_registry[:role_resource], row) }
|
90
90
|
when :client
|
91
|
-
response[:rows].collect { |row| Ridley::ClientObject.new(row) }
|
91
|
+
response[:rows].collect { |row| Ridley::ClientObject.new(resources_registry[:client_resource], row) }
|
92
92
|
when :environment
|
93
|
-
response[:rows].collect { |row| Ridley::EnvironmentObject.new(row) }
|
93
|
+
response[:rows].collect { |row| Ridley::EnvironmentObject.new(resources_registry[:environment_resource], row) }
|
94
94
|
else
|
95
95
|
response[:rows]
|
96
96
|
end
|
@@ -75,6 +75,12 @@ module Ridley
|
|
75
75
|
upload_path = url.path
|
76
76
|
url.path = ""
|
77
77
|
|
78
|
+
# versions prior to OSS Chef 11 will strip the port to upload the file to in the checksum
|
79
|
+
# url returned. This will ensure we are uploading to the proper location.
|
80
|
+
if sandbox.send(:resource).connection.foss?
|
81
|
+
url.port = URI(sandbox.send(:resource).connection.server_url).port
|
82
|
+
end
|
83
|
+
|
78
84
|
begin
|
79
85
|
Faraday.new(url, self.options) do |c|
|
80
86
|
c.response :chef_response
|
data/lib/ridley/version.rb
CHANGED
data/ridley.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_runtime_dependency 'addressable'
|
28
28
|
s.add_runtime_dependency 'faraday', '>= 0.8.4'
|
29
29
|
s.add_runtime_dependency 'activesupport', '>= 3.2.0'
|
30
|
-
s.add_runtime_dependency 'solve', '>= 0.4.
|
30
|
+
s.add_runtime_dependency 'solve', '>= 0.4.3'
|
31
31
|
s.add_runtime_dependency 'celluloid', '~> 0.13.0'
|
32
32
|
s.add_runtime_dependency 'net-ssh'
|
33
33
|
s.add_runtime_dependency 'erubis'
|
@@ -1,111 +1,93 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Client API operations", type: "acceptance" do
|
4
|
-
let(:server_url)
|
4
|
+
let(:server_url) { Ridley::RSpec::ChefServer.server_url }
|
5
5
|
let(:client_name) { "reset" }
|
6
|
-
let(:client_key)
|
7
|
-
let(:
|
8
|
-
|
9
|
-
let(:connection) do
|
10
|
-
Ridley.new(
|
11
|
-
server_url: server_url,
|
12
|
-
client_name: client_name,
|
13
|
-
client_key: client_key
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
before(:all) { WebMock.allow_net_connect! }
|
18
|
-
after(:all) { WebMock.disable_net_connect! }
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
connection.client.delete_all
|
22
|
-
end
|
6
|
+
let(:client_key) { fixtures_path.join('reset.pem').to_s }
|
7
|
+
let(:connection) { Ridley.new(server_url: server_url, client_name: client_name, client_key: client_key) }
|
23
8
|
|
24
9
|
describe "finding a client" do
|
25
|
-
|
10
|
+
context "when the server has a client of the given name" do
|
11
|
+
before { chef_client("reset", admin: false) }
|
26
12
|
|
27
|
-
|
28
|
-
|
13
|
+
it "returns a ClientObject" do
|
14
|
+
connection.client.find("reset").should be_a(Ridley::ClientObject)
|
15
|
+
end
|
29
16
|
end
|
30
17
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
obj.should be_a(Ridley::ClientObject)
|
36
|
-
obj.should be_valid
|
18
|
+
context "when the server does not have the client" do
|
19
|
+
it "returns a nil value" do
|
20
|
+
connection.client.find("not_there").should be_nil
|
37
21
|
end
|
38
22
|
end
|
39
23
|
end
|
40
24
|
|
41
25
|
describe "creating a client" do
|
42
|
-
|
26
|
+
it "returns a Ridley::ClientObject" do
|
27
|
+
connection.client.create(name: "reset").should be_a(Ridley::ClientObject)
|
28
|
+
end
|
43
29
|
|
44
|
-
it "
|
45
|
-
connection.
|
46
|
-
|
47
|
-
|
30
|
+
it "adds a client to the chef server" do
|
31
|
+
old = connection.client.all.length
|
32
|
+
connection.client.create(name: "reset")
|
33
|
+
connection.client.all.should have(old + 1).items
|
48
34
|
end
|
49
35
|
|
50
|
-
it "has a value for
|
51
|
-
connection.
|
52
|
-
client.create(target).private_key.should_not be_nil
|
53
|
-
end
|
36
|
+
it "has a value for #private_key" do
|
37
|
+
connection.client.create(name: "reset").private_key.should_not be_nil
|
54
38
|
end
|
55
39
|
end
|
56
40
|
|
57
41
|
describe "deleting a client" do
|
58
|
-
|
42
|
+
before { chef_client("reset", admin: false) }
|
59
43
|
|
60
|
-
|
61
|
-
connection.client.
|
44
|
+
it "returns a Ridley::ClientObject object" do
|
45
|
+
connection.client.delete("reset").should be_a(Ridley::ClientObject)
|
62
46
|
end
|
63
47
|
|
64
|
-
it "
|
65
|
-
connection.client.delete(
|
48
|
+
it "removes the client from the server" do
|
49
|
+
connection.client.delete("reset")
|
50
|
+
|
51
|
+
connection.client.find("reset").should be_nil
|
66
52
|
end
|
67
53
|
end
|
68
54
|
|
69
55
|
describe "deleting all clients" do
|
70
56
|
before(:each) do
|
71
|
-
|
72
|
-
|
73
|
-
client.create(name: "ridley-two")
|
74
|
-
end
|
57
|
+
chef_client("reset", admin: false)
|
58
|
+
chef_client("jwinsor", admin: false)
|
75
59
|
end
|
76
60
|
|
77
|
-
it "returns an array of Ridley::
|
61
|
+
it "returns an array of Ridley::ClientObject objects" do
|
78
62
|
connection.client.delete_all.should each be_a(Ridley::ClientObject)
|
79
63
|
end
|
80
64
|
|
81
65
|
it "deletes all clients from the remote" do
|
82
|
-
connection.
|
83
|
-
|
84
|
-
|
85
|
-
client.all.should have(0).clients
|
86
|
-
end
|
66
|
+
connection.client.delete_all
|
67
|
+
connection.client.all.should have(0).clients
|
87
68
|
end
|
88
69
|
end
|
89
70
|
|
90
71
|
describe "listing all clients" do
|
72
|
+
before(:each) do
|
73
|
+
chef_client("reset", admin: false)
|
74
|
+
chef_client("jwinsor", admin: false)
|
75
|
+
end
|
76
|
+
|
91
77
|
it "returns an array of Ridley::ClientObject objects" do
|
92
78
|
connection.client.all.should each be_a(Ridley::ClientObject)
|
93
79
|
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "regenerating a client's private key" do
|
97
|
-
let(:target) { Ridley::ClientObject.new(resource, name: "motherbrain-test", admin: false) }
|
98
80
|
|
99
|
-
|
100
|
-
connection.client.
|
81
|
+
it "returns all of the clients on the server" do
|
82
|
+
connection.client.all.should have(4).items
|
101
83
|
end
|
84
|
+
end
|
102
85
|
|
103
|
-
|
104
|
-
|
105
|
-
obj = client.regenerate_key(target)
|
86
|
+
describe "regenerating a client's private key" do
|
87
|
+
before { chef_client("reset", admin: false) }
|
106
88
|
|
107
|
-
|
108
|
-
|
89
|
+
it "returns a Ridley::ClientObject object with a value for #private_key" do
|
90
|
+
connection.client.regenerate_key("reset").private_key.should match(/^-----BEGIN RSA PRIVATE KEY-----/)
|
109
91
|
end
|
110
92
|
end
|
111
93
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Client API operations", type: "acceptance" do
|
4
|
+
let(:server_url) { Ridley::RSpec::ChefServer.server_url }
|
5
|
+
let(:client_name) { "reset" }
|
6
|
+
let(:client_key) { fixtures_path.join('reset.pem').to_s }
|
7
|
+
let(:connection) { Ridley.new(server_url: server_url, client_name: client_name, client_key: client_key) }
|
8
|
+
|
9
|
+
describe "uploading a cookbook" do
|
10
|
+
let(:path) { fixtures_path.join("example_cookbook") }
|
11
|
+
|
12
|
+
it "uploads the entire contents of the cookbook in the given path" do
|
13
|
+
connection.cookbook.upload(path)
|
14
|
+
cookbook = connection.cookbook.find("example_cookbook", "0.1.0")
|
15
|
+
|
16
|
+
cookbook.attributes.should have(1).item
|
17
|
+
cookbook.definitions.should have(1).item
|
18
|
+
cookbook.files.should have(2).items
|
19
|
+
cookbook.libraries.should have(1).item
|
20
|
+
cookbook.providers.should have(1).item
|
21
|
+
cookbook.recipes.should have(1).item
|
22
|
+
cookbook.resources.should have(1).item
|
23
|
+
cookbook.templates.should have(1).item
|
24
|
+
cookbook.root_files.should have(2).items
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,58 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "DataBag API operations", type: "acceptance" do
|
4
|
-
let(:server_url)
|
4
|
+
let(:server_url) { Ridley::RSpec::ChefServer.server_url }
|
5
5
|
let(:client_name) { "reset" }
|
6
|
-
let(:client_key)
|
7
|
-
|
8
|
-
let(:client) do
|
9
|
-
Ridley.new(
|
10
|
-
server_url: server_url,
|
11
|
-
client_name: client_name,
|
12
|
-
client_key: client_key
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
before(:all) { WebMock.allow_net_connect! }
|
17
|
-
after(:all) { WebMock.disable_net_connect! }
|
6
|
+
let(:client_key) { fixtures_path.join('reset.pem').to_s }
|
7
|
+
let(:connection) { Ridley.new(server_url: server_url, client_name: client_name, client_key: client_key) }
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
let(:data_bag) do
|
10
|
+
chef_data_bag("ridley-test")
|
11
|
+
connection.data_bag.find("ridley-test")
|
22
12
|
end
|
23
13
|
|
24
|
-
before { @databag.item.delete_all }
|
25
|
-
|
26
14
|
describe "listing data bag items" do
|
27
15
|
context "when the data bag has no items" do
|
28
16
|
it "returns an empty array" do
|
29
|
-
|
17
|
+
data_bag.item.all.should have(0).items
|
30
18
|
end
|
31
19
|
end
|
32
20
|
|
33
21
|
context "when the data bag has items" do
|
34
22
|
before(:each) do
|
35
|
-
|
36
|
-
|
23
|
+
data_bag.item.create(id: "one")
|
24
|
+
data_bag.item.create(id: "two")
|
37
25
|
end
|
38
26
|
|
39
27
|
it "returns an array with each item" do
|
40
|
-
|
28
|
+
data_bag.item.all.should have(2).items
|
41
29
|
end
|
42
30
|
end
|
43
31
|
end
|
44
32
|
|
45
33
|
describe "creating a data bag item" do
|
46
34
|
it "adds a data bag item to the collection of data bag items" do
|
47
|
-
|
35
|
+
data_bag.item.create(id: "appconfig", host: "host.local", port: 80, admin: false, servers: ["one"])
|
48
36
|
|
49
|
-
|
37
|
+
data_bag.item.all.should have(1).item
|
50
38
|
end
|
51
39
|
|
52
40
|
context "when an 'id' field is missing" do
|
53
41
|
it "raises an Ridley::Errors::InvalidResource error" do
|
54
42
|
expect {
|
55
|
-
|
43
|
+
data_bag.item.create(name: "jamie")
|
56
44
|
}.to raise_error(Ridley::Errors::InvalidResource)
|
57
45
|
end
|
58
46
|
end
|
@@ -69,9 +57,9 @@ describe "DataBag API operations", type: "acceptance" do
|
|
69
57
|
"one"
|
70
58
|
]
|
71
59
|
}
|
72
|
-
|
60
|
+
data_bag.item.create(attributes)
|
73
61
|
|
74
|
-
|
62
|
+
data_bag.item.find("appconfig").to_hash.should eql(attributes)
|
75
63
|
end
|
76
64
|
end
|
77
65
|
|
@@ -83,48 +71,44 @@ describe "DataBag API operations", type: "acceptance" do
|
|
83
71
|
}
|
84
72
|
end
|
85
73
|
|
86
|
-
before(
|
87
|
-
@databag.item.create(attributes)
|
88
|
-
end
|
74
|
+
before { data_bag.item.create(attributes) }
|
89
75
|
|
90
76
|
it "returns the deleted data bag item" do
|
91
|
-
dbi =
|
77
|
+
dbi = data_bag.item.delete(attributes["id"])
|
92
78
|
|
93
79
|
dbi.should be_a(Ridley::DataBagItemObject)
|
94
80
|
dbi.attributes.should eql(attributes)
|
95
81
|
end
|
96
82
|
|
97
83
|
it "deletes the data bag item from the server" do
|
98
|
-
|
84
|
+
data_bag.item.delete(attributes["id"])
|
99
85
|
|
100
|
-
|
86
|
+
data_bag.item.find(attributes["id"]).should be_nil
|
101
87
|
end
|
102
88
|
end
|
103
89
|
|
104
90
|
describe "deleting all data bag items in a data bag" do
|
105
|
-
before
|
106
|
-
|
107
|
-
|
91
|
+
before do
|
92
|
+
data_bag.item.create(id: "one")
|
93
|
+
data_bag.item.create(id: "two")
|
108
94
|
end
|
109
95
|
|
110
96
|
it "returns the array of deleted data bag items" do
|
111
|
-
|
97
|
+
data_bag.item.delete_all.should each be_a(Ridley::DataBagItemObject)
|
112
98
|
end
|
113
99
|
|
114
100
|
it "removes all data bag items from the data bag" do
|
115
|
-
|
101
|
+
data_bag.item.delete_all
|
116
102
|
|
117
|
-
|
103
|
+
data_bag.item.all.should have(0).items
|
118
104
|
end
|
119
105
|
end
|
120
106
|
|
121
107
|
describe "updating a data bag item" do
|
122
|
-
before(:
|
123
|
-
@databag.item.create(id: "one")
|
124
|
-
end
|
108
|
+
before { data_bag.item.create(id: "one") }
|
125
109
|
|
126
110
|
it "returns the updated data bag item" do
|
127
|
-
dbi =
|
111
|
+
dbi = data_bag.item.update(id: "one", name: "brooke")
|
128
112
|
|
129
113
|
dbi[:name].should eql("brooke")
|
130
114
|
end
|
@@ -132,37 +116,35 @@ describe "DataBag API operations", type: "acceptance" do
|
|
132
116
|
|
133
117
|
describe "saving a data bag item" do
|
134
118
|
context "when the data bag item exists" do
|
135
|
-
|
136
|
-
@dbi = @databag.item.create(id: "ridley-test")
|
137
|
-
end
|
119
|
+
let(:dbi) { data_bag.item.create(id: "ridley-test") }
|
138
120
|
|
139
121
|
it "returns true if successful" do
|
140
|
-
|
141
|
-
|
122
|
+
dbi[:name] = "brooke"
|
123
|
+
dbi.save.should be_true
|
142
124
|
end
|
143
125
|
|
144
126
|
it "creates a new data bag item on the remote" do
|
145
|
-
|
146
|
-
|
127
|
+
dbi[:name] = "brooke"
|
128
|
+
dbi.save
|
147
129
|
|
148
|
-
|
130
|
+
data_bag.item.all.should have(1).item
|
149
131
|
end
|
150
132
|
end
|
151
133
|
|
152
134
|
context "when the data bag item does not exist" do
|
153
135
|
it "returns true if successful" do
|
154
|
-
dbi =
|
136
|
+
dbi = data_bag.item.new
|
155
137
|
|
156
138
|
dbi.attributes = { id: "not-there", name: "brooke" }
|
157
139
|
dbi.save.should be_true
|
158
140
|
end
|
159
141
|
|
160
142
|
it "creates a new data bag item on the remote" do
|
161
|
-
dbi =
|
143
|
+
dbi = data_bag.item.new
|
162
144
|
dbi.attributes = { id: "not-there", name: "brooke" }
|
163
145
|
dbi.save
|
164
146
|
|
165
|
-
|
147
|
+
data_bag.item.all.should have(1).item
|
166
148
|
end
|
167
149
|
end
|
168
150
|
end
|