spice 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.DS_Store +0 -0
  2. data/.document +0 -0
  3. data/.gitignore +5 -0
  4. data/.rspec +1 -1
  5. data/CHANGELOG.md +16 -0
  6. data/Gemfile +0 -0
  7. data/Gemfile.lock +2 -5
  8. data/LICENSE.txt +0 -0
  9. data/Notes.md +0 -0
  10. data/README.md +2 -2
  11. data/Rakefile +0 -0
  12. data/TODO.md +2 -2
  13. data/features/spice.feature +0 -0
  14. data/features/step_definitions/spice_steps.rb +0 -0
  15. data/features/support/env.rb +0 -0
  16. data/file.txt +0 -0
  17. data/lib/spice/authentication.rb +0 -0
  18. data/lib/spice/chef.rb +0 -15
  19. data/lib/spice/client.rb +3 -3
  20. data/lib/spice/connection.rb +34 -26
  21. data/lib/spice/cookbook.rb +0 -0
  22. data/lib/spice/data_bag.rb +103 -4
  23. data/{spec/support/authentication.rb → lib/spice/mock.rb} +17 -14
  24. data/lib/spice/node.rb +0 -0
  25. data/lib/spice/role.rb +0 -0
  26. data/lib/spice/version.rb +1 -1
  27. data/lib/spice.rb +8 -0
  28. data/pkg/spice-0.0.1.alpha.1.gem +0 -0
  29. data/spec/spec_helper.rb +2 -0
  30. data/spec/spice/authentication_spec.rb +0 -0
  31. data/spec/spice/chef_spec.rb +1 -1
  32. data/spec/spice/client_spec.rb +4 -4
  33. data/spec/spice/connection_spec.rb +0 -0
  34. data/spec/spice/cookbook_spec.rb +91 -14
  35. data/spec/spice/data_bag_spec.rb +151 -8
  36. data/spec/spice/node_spec.rb +0 -29
  37. data/spec/spice/role_spec.rb +1 -29
  38. data/spec/spice_spec.rb +0 -0
  39. data/spec/support/client_requests.rb +97 -0
  40. data/spec/support/cookbook_requests.rb +172 -0
  41. data/spec/support/data_bag_item_requests.rb +138 -0
  42. data/spec/support/data_bag_requests.rb +95 -0
  43. data/spec/support/respond_with_matcher.rb +53 -0
  44. data/spec/support/vcr.rb +0 -0
  45. data/spice.gemspec +0 -0
  46. metadata +16 -5
@@ -3,23 +3,166 @@ require 'spec_helper'
3
3
  module Spice
4
4
  describe DataBag do
5
5
  describe ".all" do
6
- DataBag.list
6
+ before { stub_data_bag_list }
7
+ subject { DataBag.all }
8
+
9
+ it { should have_body(data_bag_list_response) }
10
+ it { should respond_with(200) }
7
11
  end
8
12
 
9
13
  describe ".show" do
10
- DataBag.show(:name => "testdata")
11
- end
14
+ context "if the data bag is found" do
15
+ before { stub_data_bag_show }
16
+ subject { DataBag.show(:name => "users") }
12
17
 
18
+ it { should have_body(data_bag_show_response) }
19
+ it { should respond_with(200) }
20
+ end
21
+
22
+ context "if the data bag is not found" do
23
+ before { stub_data_bag_show(404) }
24
+ subject { DataBag.show(:name => "users") }
25
+
26
+ it { should_not have_body(data_bag_show_response) }
27
+ it { should respond_with(404) }
28
+ end
29
+ end
30
+
13
31
  describe ".create" do
14
- DataBag.create(:name => "testdata")
32
+ context "if the data bag can be created" do
33
+ before { stub_data_bag_create }
34
+ subject { DataBag.create(:name => "users") }
35
+
36
+ it { should have_body(data_bag_create_response) }
37
+ it { should respond_with(201) }
38
+ end
39
+
40
+ context "if the data bag already exists" do
41
+ before { stub_data_bag_create(409) }
42
+ subject { DataBag.create(:name => "users") }
43
+
44
+ it { should have_body(data_bag_conflict) }
45
+ it { should respond_with(409) }
46
+ end
15
47
  end
16
48
 
17
- describe ".update" do
18
- DataBag.update(:name => "testdata")
49
+ describe ".delete" do
50
+ context "if the data bag can be deleted" do
51
+ before { stub_data_bag_delete }
52
+ subject { DataBag.delete(:name => "users") }
53
+
54
+ it { should have_body(data_bag_delete_response) }
55
+ it { should respond_with(200) }
56
+ end
57
+
58
+ context "if the data bag cannot be deleted" do
59
+ before { stub_data_bag_delete(404) }
60
+ subject { DataBag.delete(:name => "users") }
61
+
62
+ it { should have_body(data_bag_not_found) }
63
+ it { should respond_with(404) }
64
+ end
65
+ end
66
+
67
+ describe ".show_item" do
68
+ context "if the data bag item exists" do
69
+ before { stub_data_bag_item_show }
70
+ subject { DataBag.show_item(:name => "users", :id => "adam") }
71
+
72
+ it { should have_body(data_bag_item_show_response) }
73
+ it { should respond_with(200) }
74
+ end
75
+
76
+ context "if the data bag item does not exist" do
77
+ before { stub_data_bag_item_show(404) }
78
+ subject { DataBag.show_item(:name => "users", :id => "adam") }
79
+
80
+ it { should have_body(data_bag_item_not_found) }
81
+ it { should respond_with(404) }
82
+ end
19
83
  end
84
+
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
20
105
 
21
- describe ".delete" do
22
- DataBag.delete(:name => "testdata")
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
+
164
+
165
+ end
23
166
  end
24
167
  end
25
168
  end
@@ -2,34 +2,5 @@ require 'spec_helper'
2
2
 
3
3
  module Spice
4
4
  describe Node do
5
- describe ".all" do
6
- VCR.use_cassette 'node/list', :record => :new_episodes do
7
- Node.list
8
- end
9
- end
10
-
11
- describe ".show" do
12
- VCR.use_cassette 'node/show', :record => :new_episodes do
13
- Node.show(:name => "testnode")
14
- end
15
- end
16
-
17
- describe ".create" do
18
- VCR.use_cassette 'node/create', :record => :new_episodes do
19
- Node.create(:name => "testnode")
20
- end
21
- end
22
-
23
- describe ".update" do
24
- VCR.use_cassette 'node/update', :record => :new_episodes do
25
- Node.update(:name => "testnode")
26
- end
27
- end
28
-
29
- describe ".delete" do
30
- VCR.use_cassette 'node/delete', :record => :new_episodes do
31
- Node.delete(:name => "testnode")
32
- end
33
- end
34
5
  end
35
6
  end
@@ -2,34 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module Spice
4
4
  describe Role do
5
- describe ".all" do
6
- VCR.use_cassette 'role/list', :record => :new_episodes do
7
- Role.list
8
- end
9
- end
10
-
11
- describe ".show" do
12
- VCR.use_cassette 'role/show', :record => :new_episodes do
13
- Role.show(:name => "testrole")
14
- end
15
- end
16
-
17
- describe ".create" do
18
- VCR.use_cassette 'role/create', :record => :new_episodes do
19
- Role.create(:name => "testrole")
20
- end
21
- end
22
-
23
- describe ".update" do
24
- VCR.use_cassette 'role/update', :record => :new_episodes do
25
- Role.update(:name => "testrole")
26
- end
27
- end
28
-
29
- describe ".delete" do
30
- VCR.use_cassette 'role/delete', :record => :new_episodes do
31
- Role.delete(:name => "testrole")
32
- end
33
- end
5
+
34
6
  end
35
7
  end
data/spec/spice_spec.rb CHANGED
File without changes
@@ -0,0 +1,97 @@
1
+ def stub_client_list(name="testclient")
2
+ stub_request(:get, "http://localhost:4000/clients").
3
+ to_return(
4
+ :status => 200,
5
+ :body => "{\"#{name}\":\"http://localhost:4000/clients/#{name}\"}",
6
+ :headers => {})
7
+ end
8
+
9
+ def stub_client_show(name, status=200)
10
+ case status
11
+ when 200
12
+ stub_request(:get, "http://localhost:4000/clients/#{name}").
13
+ to_return(
14
+ :status => status,
15
+ :body => %Q{{"name": "#{name}",
16
+ "chef_type": "client",
17
+ "json_class": "Chef::ApiClient",
18
+ "public_key": "RSA PUBLIC KEY",
19
+ "_rev": "1-68532bf2122a54464db6ad65a24e2225",
20
+ "admin": true}
21
+ }
22
+ )
23
+ when 404
24
+ stub_request(:get, "http://localhost:4000/clients/#{name}").
25
+ to_return(
26
+ :status => status,
27
+ :body => "{\"error\":[\"Cannot load client #{name}\"]}")
28
+ end
29
+ end
30
+
31
+ def stub_client_create(name, admin=false, status=201)
32
+ case status
33
+ when 201
34
+ stub_request(:post, "http://localhost:4000/clients").
35
+ with(
36
+ :body => "{\"name\":\"#{name}\",\"admin\":#{admin}}").
37
+ to_return(
38
+ :status => status,
39
+ :body => %Q{
40
+ {
41
+ "private_key":"RSA PRIVATE KEY",
42
+ "uri":"http://http://localhost:4000/clients/#{name}"}
43
+ },
44
+ :headers => {}
45
+ )
46
+ when 409
47
+ stub_request(:post, "http://localhost:4000/clients").
48
+ with(
49
+ :body => "{\"name\":\"#{name}\",\"admin\":#{admin}}").
50
+ to_return(
51
+ :status => status,
52
+ :body => %Q{
53
+ {
54
+ "private_key":"RSA PRIVATE KEY",
55
+ "uri":"http://http://localhost:4000/clients/#{name}"}
56
+ },
57
+ :headers => {}
58
+ )
59
+ end
60
+ end
61
+
62
+ def stub_client_update(name, admin=false, private_key=false, status=200)
63
+ case status
64
+ when 200
65
+ stub_request(:put, "http://localhost:4000/clients/#{name}").
66
+ with(:body => "{\"admin\":#{admin},\"private_key\":#{private_key}}").
67
+ to_return(
68
+ :status => status,
69
+ :body => %Q{{#{"\"private_key\":\"RSA PRIVATE KEY\"," if private_key}\"admin\": true}
70
+ }
71
+ )
72
+ # when 404
73
+ # stub_request(:get, "http://localhost:4000/clients/#{name}").
74
+ # to_return(
75
+ # :status => status,
76
+ # :body => "{\"error\":[\"Cannot load client #{name}\"]}")
77
+ end
78
+ end
79
+
80
+ def stub_client_delete(name, status=200)
81
+ case status
82
+ when 200
83
+ stub_request(:delete, "http://localhost:4000/clients/#{name}").
84
+ with(:body => "").
85
+ to_return(
86
+ :status => status,
87
+ :body => ""
88
+ )
89
+ when 404
90
+ stub_request(:delete, "http://localhost:4000/clients/#{name}").
91
+ with(:body => "").
92
+ to_return(
93
+ :status => status,
94
+ :body => "{\"error\":[\"Cannot load client sasdasdf\"]}"
95
+ )
96
+ end
97
+ end
@@ -0,0 +1,172 @@
1
+ def stub_cookbook_list
2
+ stub_request(:get, "http://localhost:4000/cookbooks").
3
+ to_return(
4
+ :status => 200,
5
+ :body => "[\"unicorn\",\"apache2\"]",
6
+ :headers => {})
7
+ end
8
+
9
+ def stub_cookbook_show(name, status=200)
10
+ case status
11
+ when 200
12
+ stub_request(:get, "http://localhost:4000/cookbooks/#{name}").
13
+ to_return(
14
+ :status => status,
15
+ :body => %Q{{
16
+ "#{name}": [
17
+ "0.1.2"
18
+ ]
19
+ }}
20
+ )
21
+ when 404
22
+ stub_request(:get, "http://localhost:4000/cookbooks/#{name}").
23
+ to_return(
24
+ :status => status,
25
+ :body => "{\"error\":[\"Cannot load cookbook #{name}\"]}")
26
+ end
27
+ end
28
+
29
+
30
+ # TODO: stub /cookbooks/COOKBOOK_NAME/COOKBOOK_VERSION
31
+
32
+ def stub_cookbook_update(name, status=200)
33
+ case status
34
+ when 200
35
+ stub_request(:put, "http://localhost:4000/cookbooks/#{name}").
36
+ with(:body => update_cookbook_payload).
37
+ to_return(
38
+ :status => status,
39
+ :body => %Q{{#{"\"private_key\":\"RSA PRIVATE KEY\"," if private_key}\"admin\": true}
40
+ }
41
+ )
42
+ # when 404
43
+ # stub_request(:get, "http://localhost:4000/cookbooks/#{name}").
44
+ # to_return(
45
+ # :status => status,
46
+ # :body => "{\"error\":[\"Cannot load cookbook #{name}\"]}")
47
+ end
48
+ end
49
+
50
+ def stub_cookbook_delete(name, status=200)
51
+ case status
52
+ when 200
53
+ stub_request(:delete, "http://localhost:4000/cookbooks/#{name}").
54
+ with(:body => "").
55
+ to_return(
56
+ :status => status,
57
+ :body => ""
58
+ )
59
+ when 404
60
+ stub_request(:delete, "http://localhost:4000/cookbooks/#{name}").
61
+ with(:body => "").
62
+ to_return(
63
+ :status => status,
64
+ :body => "{\"error\":[\"Cannot load cookbook sasdasdf\"]}"
65
+ )
66
+ end
67
+ end
68
+
69
+ update_cookbook_payload = %Q{
70
+ {
71
+ "definitions": [
72
+ {
73
+ "name": "unicorn_config.rb",
74
+ "checksum": "c92b659171552e896074caa58dada0c2",
75
+ "path": "definitions/unicorn_config.rb",
76
+ "specificity": "default"
77
+ }
78
+ ],
79
+ "name": "unicorn-0.1.2",
80
+ "attributes": [
81
+
82
+ ],
83
+ "files": [
84
+
85
+ ],
86
+ "json_class": "Chef::CookbookVersion",
87
+ "providers": [
88
+
89
+ ],
90
+ "metadata": {
91
+ "dependencies": {
92
+ "ruby": [
93
+
94
+ ],
95
+ "rubygems": [
96
+
97
+ ]
98
+ },
99
+ "name": "unicorn",
100
+ "maintainer_email": "ops@opscode.com",
101
+ "attributes": {
102
+ },
103
+ "license": "Apache 2.0",
104
+ "suggestions": {
105
+ },
106
+ "platforms": {
107
+ },
108
+ "maintainer": "Opscode, Inc",
109
+ "long_description": "= LICENSE AND AUTHOR:\n\nAuthor:: Adam Jacob <adam@opscode.com>\n\nCopyright 2009-2010, Opscode, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
110
+ "recommendations": {
111
+ },
112
+ "version": "0.1.2",
113
+ "conflicting": {
114
+ },
115
+ "recipes": {
116
+ "unicorn": "Installs unicorn rubygem"
117
+ },
118
+ "groupings": {
119
+ },
120
+ "replacing": {
121
+ },
122
+ "description": "Installs/Configures unicorn",
123
+ "providing": {
124
+ }
125
+ },
126
+ "libraries": [
127
+
128
+ ],
129
+ "templates": [
130
+ {
131
+ "name": "unicorn.rb.erb",
132
+ "checksum": "36a1cc1b225708db96d48026c3f624b2",
133
+ "path": "templates/default/unicorn.rb.erb",
134
+ "specificity": "default"
135
+ }
136
+ ],
137
+ "resources": [
138
+
139
+ ],
140
+ "cookbook_name": "unicorn",
141
+ "version": "0.1.2",
142
+ "recipes": [
143
+ {
144
+ "name": "default.rb",
145
+ "checksum": "ba0dadcbca26710a521e0e3160cc5e20",
146
+ "path": "recipes/default.rb",
147
+ "specificity": "default"
148
+ }
149
+ ],
150
+ "root_files": [
151
+ {
152
+ "name": "README.rdoc",
153
+ "checksum": "d18c630c8a68ffa4852d13214d0525a6",
154
+ "path": "README.rdoc",
155
+ "specificity": "default"
156
+ },
157
+ {
158
+ "name": "metadata.rb",
159
+ "checksum": "967087a09f48f234028d3aa27a094882",
160
+ "path": "metadata.rb",
161
+ "specificity": "default"
162
+ },
163
+ {
164
+ "name": "metadata.json",
165
+ "checksum": "45b27c78955f6a738d2d42d88056c57c",
166
+ "path": "metadata.json",
167
+ "specificity": "default"
168
+ }
169
+ ],
170
+ "chef_type": "cookbook_version"
171
+ }
172
+ }
@@ -0,0 +1,138 @@
1
+ def stub_data_bag_item_show(status=200)
2
+ case status
3
+ when 200
4
+ stub_request(:get, "http://localhost:4000/data/users/adam").
5
+ to_return(
6
+ :status => status,
7
+ :body => data_bag_item_show_response
8
+ )
9
+ when 404
10
+ stub_request(:get, "http://localhost:4000/data/users/adam").
11
+ to_return(
12
+ :status => status,
13
+ :body => data_bag_item_not_found
14
+ )
15
+ end
16
+ end
17
+
18
+
19
+ def stub_data_bag_item_create(status=201)
20
+ case status
21
+ when 201
22
+ stub_request(:post, "http://localhost:4000/data/users").
23
+ with(
24
+ :body => data_bag_item_create_payload ).
25
+ to_return(
26
+ :status => status,
27
+ :body => data_bag_item_create_response
28
+ )
29
+ when 409
30
+ stub_request(:post, "http://localhost:4000/data/users").
31
+ with(
32
+ :body => data_bag_item_create_payload ).
33
+ to_return(
34
+ :status => status,
35
+ :body => data_bag_item_conflict
36
+ )
37
+ when 404
38
+ stub_request(:post, "http://localhost:4000/data/users").
39
+ with(
40
+ :body => data_bag_item_create_payload ).
41
+ to_return(
42
+ :status => status,
43
+ :body => data_bag_not_found
44
+ )
45
+ end
46
+ end
47
+
48
+ def stub_data_bag_item_update(status=200)
49
+ case status
50
+ when 200
51
+ stub_request(:put, "http://localhost:4000/data/users/adam").
52
+ with(
53
+ :body => data_bag_item_update_payload ).
54
+ to_return(
55
+ :status => status,
56
+ :body => data_bag_item_update_response
57
+ )
58
+ when 404
59
+ stub_request(:put, "http://localhost:4000/data/users/adam").
60
+ with(
61
+ :body => data_bag_item_update_payload ).
62
+ to_return(
63
+ :status => status,
64
+ :body => data_bag_item_not_found
65
+ )
66
+ end
67
+ end
68
+
69
+ def stub_data_bag_item_delete(status=200)
70
+ case status
71
+ when 200
72
+ stub_request(:delete, "http://localhost:4000/data/users/adam").
73
+ with(:body => "").
74
+ to_return(
75
+ :status => status,
76
+ :body => data_bag_item_delete_response
77
+ )
78
+ when 404
79
+ stub_request(:delete, "http://localhost:4000/data/users/adam").
80
+ with(:body => "").
81
+ to_return(
82
+ :status => status,
83
+ :body => data_bag_item_not_found
84
+ )
85
+ end
86
+ end
87
+
88
+ def data_bag_item_create_payload
89
+ { "id" => "adam", "real_name" => "Adam Jacob" }
90
+ end
91
+
92
+ def data_bag_item_create_response
93
+ { "id" => "adam",
94
+ "data_bag" => "users",
95
+ "chef_type" => "data_bag_item",
96
+ "real_name" => "Adam Jacob" }
97
+ end
98
+
99
+ def data_bag_item_show_response
100
+ { "name" => "users", "id" => "adam" }
101
+ end
102
+
103
+ def data_bag_item_update_payload
104
+ { "title" => "Supreme Awesomer" }
105
+ end
106
+
107
+ def data_bag_item_update_response
108
+ {
109
+ "_rev" => "2-0f58b834949ce8a8b5f713bf8a525de7",
110
+ "title" => "Supreme Awesomer",
111
+ "id" => "adam",
112
+ "data_bag" => "users",
113
+ "chef_type" => "data_bag_item"
114
+ }
115
+ end
116
+
117
+ def data_bag_item_delete_response
118
+ { "name" => "data_bag_item_users_adam",
119
+ "raw_data" => {
120
+ "id" => "adam"
121
+ },
122
+ "json_class" => "Chef::DataBagItem",
123
+ "data_bag" => "users",
124
+ "chef_type" => "data_bag_item"
125
+ }
126
+ end
127
+
128
+ def data_bag_item_not_found
129
+ { "error" => [ "Cannot load data bag users item adam" ] }
130
+ end
131
+
132
+ def data_bag_item_conflict
133
+ { "error" => [ "Databag Item adam already exists" ] }
134
+ end
135
+
136
+ def data_bag_item_show_response
137
+ { "real_name" => "Adam Jacob", "id" => "adam" }
138
+ end