spice 0.4.2 → 0.5.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.watchr +22 -0
- data/Gemfile +14 -1
- data/Rakefile +5 -0
- data/lib/spice.rb +1 -1
- data/lib/spice/client.rb +4 -4
- data/lib/spice/connection.rb +9 -4
- data/lib/spice/node.rb +7 -0
- data/lib/spice/version.rb +1 -1
- data/spec/spec_helper.rb +29 -19
- data/spec/spice/chef_spec.rb +31 -83
- data/spec/spice/client_spec.rb +42 -85
- data/spec/spice/cookbook_spec.rb +42 -81
- data/spec/spice/data_bag_spec.rb +84 -85
- data/spec/spice/node_spec.rb +75 -0
- data/spec/spice/role_spec.rb +61 -0
- data/spec/spice/search_spec.rb +2 -0
- data/{file.txt → spec/support/chef_requests.rb} +0 -0
- data/spec/support/client_requests.rb +52 -54
- data/spec/support/cookbook_requests.rb +53 -130
- data/spec/support/node_requests.rb +138 -0
- data/spec/support/requests.rb +97 -97
- data/spec/support/role_requests.rb +95 -0
- data/spice.gemspec +2 -3
- metadata +17 -22
- data/spec/support/vcr.rb +0 -8
data/spec/spice/cookbook_spec.rb
CHANGED
@@ -3,105 +3,66 @@ require 'spec_helper'
|
|
3
3
|
module Spice
|
4
4
|
describe Cookbook do
|
5
5
|
describe ".all" do
|
6
|
+
before { stub_cookbook_list }
|
7
|
+
subject { Cookbook.all }
|
6
8
|
|
7
|
-
it
|
8
|
-
|
9
|
-
Cookbook.all.length.should == 1
|
10
|
-
end
|
9
|
+
it { should have_body(cookbook_list_response) }
|
10
|
+
it { should respond_with(200) }
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe ".show" do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
cookbook["admin"].should == true
|
21
|
-
end
|
14
|
+
context "if the cookbook is found" do
|
15
|
+
before { stub_cookbook_show }
|
16
|
+
subject { Cookbook.show(:name => "testcookbook") }
|
17
|
+
|
18
|
+
it { should have_body(cookbook_show_response) }
|
19
|
+
it { should respond_with(200) }
|
22
20
|
end
|
23
21
|
|
24
|
-
context "
|
25
|
-
|
26
|
-
|
27
|
-
lambda { Cookbook.show(:name => "applesauce") }.
|
28
|
-
should raise_error(RestCookbook::ResourceNotFound)
|
29
|
-
end
|
22
|
+
context "if the cookbook is not found" do
|
23
|
+
before { stub_cookbook_show(404) }
|
24
|
+
subject { Cookbook.show(:name => "testcookbook") }
|
30
25
|
|
31
|
-
it
|
32
|
-
|
33
|
-
lambda {Cookbook.show() }.should raise_error ArgumentError
|
34
|
-
end
|
26
|
+
it { should_not have_body(cookbook_show_response) }
|
27
|
+
it { should respond_with(404) }
|
35
28
|
end
|
36
29
|
end
|
37
|
-
|
30
|
+
|
38
31
|
describe ".create" do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
stub_cookbook_create("spork")
|
43
|
-
cookbook = Cookbook.create(:name => "spork", :admin => false)
|
44
|
-
cookbook["private_key"].should == "RSA PRIVATE KEY"
|
45
|
-
cookbook["uri"].should == "http://http://localhost:4000/cookbooks/spork"
|
46
|
-
end
|
32
|
+
context "if the cookbook can be created" do
|
33
|
+
before { stub_cookbook_create }
|
34
|
+
subject { Cookbook.create(:name => "testcookbook") }
|
47
35
|
|
48
|
-
it
|
49
|
-
|
50
|
-
response = Cookbook.create(:name => "pants", :admin => true)
|
51
|
-
response["private_key"].should == "RSA PRIVATE KEY"
|
52
|
-
response["uri"].should == "http://http://localhost:4000/cookbooks/pants"
|
53
|
-
|
54
|
-
stub_cookbook_show("pants")
|
55
|
-
cookbook = Cookbook.show(:name => "pants")
|
56
|
-
cookbook["admin"].should == true
|
57
|
-
end
|
36
|
+
it { should have_body(cookbook_create_response) }
|
37
|
+
it { should respond_with(201) }
|
58
38
|
end
|
59
39
|
|
60
|
-
context "
|
61
|
-
|
62
|
-
|
63
|
-
lambda { Cookbook.create(:name => "pants", :admin => false) }.
|
64
|
-
should raise_error(RestCookbook::Conflict)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe ".update" do
|
70
|
-
|
71
|
-
context "valid" do
|
72
|
-
it "makes a cookbook an admin" do
|
73
|
-
stub_cookbook_update("awesome", true, false, 200)
|
74
|
-
Cookbook.update(:name => "awesome", :admin => true, :private_key => false)
|
75
|
-
end
|
40
|
+
context "if the cookbook already exists" do
|
41
|
+
before { stub_cookbook_create(409) }
|
42
|
+
subject { Cookbook.create(:name => "testcookbook") }
|
76
43
|
|
77
|
-
it
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
44
|
+
it { should have_body(cookbook_conflict) }
|
45
|
+
it { should respond_with(409) }
|
46
|
+
end
|
82
47
|
end
|
83
|
-
|
48
|
+
|
84
49
|
describe ".delete" do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
50
|
+
context "if the cookbook can be deleted" do
|
51
|
+
before { stub_cookbook_delete }
|
52
|
+
subject { Cookbook.delete(:name => "testcookbook") }
|
53
|
+
|
54
|
+
it { should have_body(cookbook_delete_response) }
|
55
|
+
it { should respond_with(200) }
|
91
56
|
end
|
92
|
-
|
93
|
-
context "
|
94
|
-
|
95
|
-
|
96
|
-
lambda {Cookbook.delete }.should raise_error ArgumentError
|
97
|
-
end
|
57
|
+
|
58
|
+
context "if the cookbook cannot be deleted" do
|
59
|
+
before { stub_cookbook_delete(404) }
|
60
|
+
subject { Cookbook.delete(:name => "testcookbook") }
|
98
61
|
|
99
|
-
it
|
100
|
-
|
101
|
-
lambda { Cookbook.delete(:name => "spork") }.
|
102
|
-
should raise_error(RestCookbook::ResourceNotFound)
|
103
|
-
end
|
62
|
+
it { should have_body(cookbook_not_found) }
|
63
|
+
it { should respond_with(404) }
|
104
64
|
end
|
105
65
|
end
|
66
|
+
|
106
67
|
end
|
107
68
|
end
|
data/spec/spice/data_bag_spec.rb
CHANGED
@@ -9,12 +9,12 @@ module Spice
|
|
9
9
|
it { should have_body(data_bag_list_response) }
|
10
10
|
it { should respond_with(200) }
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe ".show" do
|
14
14
|
context "if the data bag is found" do
|
15
15
|
before { stub_data_bag_show }
|
16
16
|
subject { DataBag.show(:name => "users") }
|
17
|
-
|
17
|
+
|
18
18
|
it { should have_body(data_bag_show_response) }
|
19
19
|
it { should respond_with(200) }
|
20
20
|
end
|
@@ -45,7 +45,7 @@ module Spice
|
|
45
45
|
it { should respond_with(409) }
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
describe ".delete" do
|
50
50
|
context "if the data bag can be deleted" do
|
51
51
|
before { stub_data_bag_delete }
|
@@ -82,87 +82,86 @@ module Spice
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
end
|
85
|
+
describe ".create_item" do
|
86
|
+
context "if the data bag item can be created" do
|
87
|
+
before { stub_data_bag_item_create }
|
88
|
+
subject do
|
89
|
+
Spice::DataBag.create_item(
|
90
|
+
:name => "users", :id => "adam", :real_name => "Adam Jacob"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it { should have_body(data_bag_item_create_response) }
|
95
|
+
it { should respond_with(201) }
|
96
|
+
end
|
97
|
+
|
98
|
+
context "if the data bag item cannot be created" do
|
99
|
+
before { stub_data_bag_item_create(409) }
|
100
|
+
subject do
|
101
|
+
Spice::DataBag.create_item(
|
102
|
+
:name => "users", :id => "adam", :real_name => "Adam Jacob"
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
it { should have_body(data_bag_item_conflict) }
|
107
|
+
it { should respond_with(409) }
|
108
|
+
end
|
109
|
+
|
110
|
+
context "if the data bag does not exist" do
|
111
|
+
before { stub_data_bag_item_create(404) }
|
112
|
+
subject do
|
113
|
+
Spice::DataBag.create_item(
|
114
|
+
:name => "users", :id => "adam", :real_name => "Adam Jacob"
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
it { should have_body(data_bag_not_found) }
|
119
|
+
it { should respond_with(404) }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe ".update_item" do
|
124
|
+
context "if the data bag item can be updated" do
|
125
|
+
before { stub_data_bag_item_update }
|
126
|
+
subject do
|
127
|
+
Spice::DataBag.update_item(
|
128
|
+
:name => "users", :id => "adam", :title => "Supreme Awesomer"
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
it { should have_body(data_bag_item_update_response) }
|
133
|
+
it { should respond_with(200) }
|
134
|
+
end
|
135
|
+
|
136
|
+
context "if the data bag item cannot be updated" do
|
137
|
+
before { stub_data_bag_item_update(404) }
|
138
|
+
subject do
|
139
|
+
Spice::DataBag.update_item(
|
140
|
+
:name => "users", :id => "adam", :title => "Supreme Awesomer"
|
141
|
+
)
|
142
|
+
end
|
143
|
+
it { should have_body(data_bag_item_not_found) }
|
144
|
+
it { should respond_with(404) }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe ".delete_item" do
|
149
|
+
context "if the data bag item can be deleted" do
|
150
|
+
before { stub_data_bag_item_delete }
|
151
|
+
subject{ Spice::DataBag.delete_item(:name => "users", :id => "adam") }
|
152
|
+
|
153
|
+
it { should have_body(data_bag_item_delete_response) }
|
154
|
+
it { should respond_with(200) }
|
155
|
+
end
|
156
|
+
|
157
|
+
context "if the data bag item cannot be deleted" do
|
158
|
+
before { stub_data_bag_item_delete(404) }
|
159
|
+
subject{ Spice::DataBag.delete_item(:name => "users", :id => "adam") }
|
160
|
+
|
161
|
+
it { should have_body(data_bag_item_not_found) }
|
162
|
+
it { should respond_with(404) }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
167
166
|
end
|
168
167
|
end
|
data/spec/spice/node_spec.rb
CHANGED
@@ -2,5 +2,80 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Spice
|
4
4
|
describe Node do
|
5
|
+
describe ".all" do
|
6
|
+
before { stub_node_list }
|
7
|
+
subject { Node.all }
|
8
|
+
|
9
|
+
it { should have_body(node_list_response) }
|
10
|
+
it { should respond_with(200) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".show" do
|
14
|
+
context "if the node is found" do
|
15
|
+
before { stub_node_show }
|
16
|
+
subject { Node.show(:name => "testnode") }
|
17
|
+
|
18
|
+
it { should have_body(node_show_response) }
|
19
|
+
it { should respond_with(200) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "if the node is not found" do
|
23
|
+
before { stub_node_show(404) }
|
24
|
+
subject { Node.show(:name => "testnode") }
|
25
|
+
|
26
|
+
it { should_not have_body(node_show_response) }
|
27
|
+
it { should respond_with(404) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".create" do
|
32
|
+
context "if the node can be created" do
|
33
|
+
before { stub_node_create }
|
34
|
+
subject { Node.create(:name => "testnode") }
|
35
|
+
|
36
|
+
it { should have_body(node_create_response) }
|
37
|
+
it { should respond_with(201) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "if the node has a run list" do
|
41
|
+
before { stub_node_create_with_run_list }
|
42
|
+
subject do
|
43
|
+
Node.create(
|
44
|
+
:name => "testnode",
|
45
|
+
:run_list => ["recipe[unicorn]" ]
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it { should have_body(node_create_response_with_run_list) }
|
50
|
+
it { should respond_with(201) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "if the node already exists" do
|
54
|
+
before { stub_node_create(409) }
|
55
|
+
subject { Node.create(:name => "testnode") }
|
56
|
+
|
57
|
+
it { should have_body(node_conflict) }
|
58
|
+
it { should respond_with(409) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe ".delete" do
|
63
|
+
context "if the node can be deleted" do
|
64
|
+
before { stub_node_delete }
|
65
|
+
subject { Node.delete(:name => "testnode") }
|
66
|
+
|
67
|
+
it { should have_body(node_delete_response) }
|
68
|
+
it { should respond_with(200) }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "if the node cannot be deleted" do
|
72
|
+
before { stub_node_delete(404) }
|
73
|
+
subject { Node.delete(:name => "testnode") }
|
74
|
+
|
75
|
+
it { should have_body(node_not_found) }
|
76
|
+
it { should respond_with(404) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
5
80
|
end
|
6
81
|
end
|
data/spec/spice/role_spec.rb
CHANGED
@@ -2,6 +2,67 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Spice
|
4
4
|
describe Role do
|
5
|
+
describe ".all" do
|
6
|
+
before { stub_role_list }
|
7
|
+
subject { Role.all }
|
5
8
|
|
9
|
+
it { should have_body(role_list_response) }
|
10
|
+
it { should respond_with(200) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".show" do
|
14
|
+
context "if the role is found" do
|
15
|
+
before { stub_role_show }
|
16
|
+
subject { Role.show(:name => "testrole") }
|
17
|
+
|
18
|
+
it { should have_body(role_show_response) }
|
19
|
+
it { should respond_with(200) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "if the role is not found" do
|
23
|
+
before { stub_role_show(404) }
|
24
|
+
subject { Role.show(:name => "testrole") }
|
25
|
+
|
26
|
+
it { should_not have_body(role_show_response) }
|
27
|
+
it { should respond_with(404) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".create" do
|
32
|
+
context "if the role can be created" do
|
33
|
+
before { stub_role_create }
|
34
|
+
subject { Role.create(:name => "testrole") }
|
35
|
+
|
36
|
+
it { should have_body(role_create_response) }
|
37
|
+
it { should respond_with(201) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "if the role already exists" do
|
41
|
+
before { stub_role_create(409) }
|
42
|
+
subject { Role.create(:name => "testrole") }
|
43
|
+
|
44
|
+
it { should have_body(role_conflict) }
|
45
|
+
it { should respond_with(409) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".delete" do
|
50
|
+
context "if the role can be deleted" do
|
51
|
+
before { stub_role_delete }
|
52
|
+
subject { Role.delete(:name => "testrole") }
|
53
|
+
|
54
|
+
it { should have_body(role_delete_response) }
|
55
|
+
it { should respond_with(200) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "if the role cannot be deleted" do
|
59
|
+
before { stub_role_delete(404) }
|
60
|
+
subject { Role.delete(:name => "testrole") }
|
61
|
+
|
62
|
+
it { should have_body(role_not_found) }
|
63
|
+
it { should respond_with(404) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
6
67
|
end
|
7
68
|
end
|