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.
@@ -0,0 +1,2 @@
1
+ require 'spec_helper'
2
+
@@ -1,97 +1,95 @@
1
- def stub_client_list(name="testclient")
1
+ def stub_client_list
2
2
  stub_request(:get, "http://localhost:4000/clients").
3
3
  to_return(
4
4
  :status => 200,
5
- :body => "{\"#{name}\":\"http://localhost:4000/clients/#{name}\"}",
6
- :headers => {})
5
+ :body => client_list_response
6
+ )
7
7
  end
8
8
 
9
- def stub_client_show(name, status=200)
9
+ def stub_client_show(status=200)
10
10
  case status
11
11
  when 200
12
- stub_request(:get, "http://localhost:4000/clients/#{name}").
12
+ stub_request(:get, "http://localhost:4000/clients/testclient").
13
13
  to_return(
14
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
- }
15
+ :body => client_show_response
22
16
  )
23
17
  when 404
24
- stub_request(:get, "http://localhost:4000/clients/#{name}").
25
- to_return(
26
- :status => status,
27
- :body => "{\"error\":[\"Cannot load client #{name}\"]}")
18
+ stub_request(:get, "http://localhost:4000/clients/testclient").
19
+ to_return(
20
+ :status => status,
21
+ :body => client_not_found
22
+ )
28
23
  end
29
24
  end
30
25
 
31
- def stub_client_create(name, admin=false, status=201)
26
+ def stub_client_create(status=201)
32
27
  case status
33
28
  when 201
34
29
  stub_request(:post, "http://localhost:4000/clients").
35
30
  with(
36
- :body => "{\"name\":\"#{name}\",\"admin\":#{admin}}").
31
+ :body => client_create_payload ).
37
32
  to_return(
38
33
  :status => status,
39
- :body => %Q{
40
- {
41
- "private_key":"RSA PRIVATE KEY",
42
- "uri":"http://http://localhost:4000/clients/#{name}"}
43
- },
44
- :headers => {}
34
+ :body => client_create_response
45
35
  )
46
36
  when 409
47
37
  stub_request(:post, "http://localhost:4000/clients").
48
38
  with(
49
- :body => "{\"name\":\"#{name}\",\"admin\":#{admin}}").
39
+ :body => client_create_payload ).
50
40
  to_return(
51
41
  :status => status,
52
- :body => %Q{
53
- {
54
- "private_key":"RSA PRIVATE KEY",
55
- "uri":"http://http://localhost:4000/clients/#{name}"}
56
- },
57
- :headers => {}
42
+ :body => client_conflict
58
43
  )
59
44
  end
60
45
  end
61
46
 
62
- def stub_client_update(name, admin=false, private_key=false, status=200)
47
+ def stub_client_delete(status=200)
63
48
  case status
64
49
  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}").
50
+ stub_request(:delete, "http://localhost:4000/clients/testclient").
84
51
  with(:body => "").
85
52
  to_return(
86
53
  :status => status,
87
- :body => ""
54
+ :body => client_delete_response
88
55
  )
89
56
  when 404
90
- stub_request(:delete, "http://localhost:4000/clients/#{name}").
57
+ stub_request(:delete, "http://localhost:4000/clients/testclient").
91
58
  with(:body => "").
92
59
  to_return(
93
60
  :status => status,
94
- :body => "{\"error\":[\"Cannot load client sasdasdf\"]}"
61
+ :body => client_not_found
95
62
  )
96
63
  end
64
+ end
65
+
66
+ # payloads and responses
67
+
68
+ def client_list_response
69
+ { "testclient" => "http://localhost:4000/clients/testclient" }
70
+ end
71
+
72
+ def client_show_response
73
+ { "adam" => "http://localhost:4000/clients/testclient" }
74
+ end
75
+
76
+ def client_delete_response
77
+ { "name" => "users", "json_class" => "Chef::Client", "chef_type" => "client" }
78
+ end
79
+
80
+ def client_not_found
81
+ { "error" => [ "Could not load client testclient" ] }
82
+ end
83
+
84
+ def client_conflict
85
+ { "error" => [ "Client already exists" ] }
86
+ end
87
+
88
+ def client_create_payload
89
+ { "name" => "testclient" }
90
+ end
91
+
92
+ def client_create_response
93
+ { "private_key"=>"-----BEGIN RSA PRIVATE KEY-----",
94
+ "uri"=>"http://localhost:4000/clients/testclient" }
97
95
  end
@@ -2,171 +2,94 @@ def stub_cookbook_list
2
2
  stub_request(:get, "http://localhost:4000/cookbooks").
3
3
  to_return(
4
4
  :status => 200,
5
- :body => "[\"unicorn\",\"apache2\"]",
6
- :headers => {})
5
+ :body => cookbook_list_response
6
+ )
7
7
  end
8
8
 
9
- def stub_cookbook_show(name, status=200)
9
+ def stub_cookbook_show(status=200)
10
10
  case status
11
11
  when 200
12
- stub_request(:get, "http://localhost:4000/cookbooks/#{name}").
12
+ stub_request(:get, "http://localhost:4000/cookbooks/testcookbook").
13
13
  to_return(
14
14
  :status => status,
15
- :body => %Q{{
16
- "#{name}": [
17
- "0.1.2"
18
- ]
19
- }}
15
+ :body => cookbook_show_response
20
16
  )
21
17
  when 404
22
- stub_request(:get, "http://localhost:4000/cookbooks/#{name}").
23
- to_return(
24
- :status => status,
25
- :body => "{\"error\":[\"Cannot load cookbook #{name}\"]}")
18
+ stub_request(:get, "http://localhost:4000/cookbooks/testcookbook").
19
+ to_return(
20
+ :status => status,
21
+ :body => cookbook_not_found
22
+ )
26
23
  end
27
24
  end
28
25
 
29
-
30
- # TODO: stub /cookbooks/COOKBOOK_NAME/COOKBOOK_VERSION
31
-
32
- def stub_cookbook_update(name, status=200)
26
+ def stub_cookbook_create(status=201)
33
27
  case status
34
- when 200
35
- stub_request(:put, "http://localhost:4000/cookbooks/#{name}").
36
- with(:body => update_cookbook_payload).
28
+ when 201
29
+ stub_request(:post, "http://localhost:4000/cookbooks").
30
+ with(
31
+ :body => cookbook_create_payload ).
37
32
  to_return(
38
- :status => status,
39
- :body => %Q{{#{"\"private_key\":\"RSA PRIVATE KEY\"," if private_key}\"admin\": true}
40
- }
33
+ :status => status,
34
+ :body => cookbook_create_response
35
+ )
36
+ when 409
37
+ stub_request(:post, "http://localhost:4000/cookbooks").
38
+ with(
39
+ :body => cookbook_create_payload ).
40
+ to_return(
41
+ :status => status,
42
+ :body => cookbook_conflict
41
43
  )
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
44
  end
48
45
  end
49
46
 
50
- def stub_cookbook_delete(name, status=200)
47
+ def stub_cookbook_delete(status=200)
51
48
  case status
52
49
  when 200
53
- stub_request(:delete, "http://localhost:4000/cookbooks/#{name}").
50
+ stub_request(:delete, "http://localhost:4000/cookbooks/testcookbook").
54
51
  with(:body => "").
55
52
  to_return(
56
53
  :status => status,
57
- :body => ""
54
+ :body => cookbook_delete_response
58
55
  )
59
56
  when 404
60
- stub_request(:delete, "http://localhost:4000/cookbooks/#{name}").
57
+ stub_request(:delete, "http://localhost:4000/cookbooks/testcookbook").
61
58
  with(:body => "").
62
59
  to_return(
63
60
  :status => status,
64
- :body => "{\"error\":[\"Cannot load cookbook sasdasdf\"]}"
61
+ :body => cookbook_not_found
65
62
  )
66
63
  end
67
64
  end
68
65
 
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": [
66
+ # payloads and responses
81
67
 
82
- ],
83
- "files": [
68
+ def cookbook_list_response
69
+ { "testcookbook" => "http://localhost:4000/cookbooks/testcookbook" }
70
+ end
84
71
 
85
- ],
86
- "json_class": "Chef::CookbookVersion",
87
- "providers": [
72
+ def cookbook_show_response
73
+ { "adam" => "http://localhost:4000/cookbooks/testcookbook" }
74
+ end
88
75
 
89
- ],
90
- "metadata": {
91
- "dependencies": {
92
- "ruby": [
76
+ def cookbook_delete_response
77
+ { "name" => "users", "json_class" => "Chef::Cookbook", "chef_type" => "cookbook" }
78
+ end
93
79
 
94
- ],
95
- "rubygems": [
80
+ def cookbook_not_found
81
+ { "error" => [ "Could not load cookbook testcookbook" ] }
82
+ end
96
83
 
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": [
84
+ def cookbook_conflict
85
+ { "error" => [ "Cookbook already exists" ] }
86
+ end
127
87
 
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": [
88
+ def cookbook_create_payload
89
+ { "name" => "testcookbook" }
90
+ end
138
91
 
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
- }
92
+ def cookbook_create_response
93
+ { "private_key"=>"-----BEGIN RSA PRIVATE KEY-----",
94
+ "uri"=>"http://localhost:4000/cookbooks/testcookbook" }
95
+ end
@@ -0,0 +1,138 @@
1
+ def stub_node_list
2
+ stub_request(:get, "http://localhost:4000/nodes").
3
+ to_return(
4
+ :status => 200,
5
+ :body => node_list_response
6
+ )
7
+ end
8
+
9
+ def stub_node_show(status=200)
10
+ case status
11
+ when 200
12
+ stub_request(:get, "http://localhost:4000/nodes/testnode").
13
+ to_return(
14
+ :status => status,
15
+ :body => node_show_response
16
+ )
17
+ when 404
18
+ stub_request(:get, "http://localhost:4000/nodes/testnode").
19
+ to_return(
20
+ :status => status,
21
+ :body => node_not_found
22
+ )
23
+ end
24
+ end
25
+
26
+ def stub_node_create(status=201)
27
+ case status
28
+ when 201
29
+ stub_request(:post, "http://localhost:4000/nodes").
30
+ with(
31
+ :body => node_create_payload ).
32
+ to_return(
33
+ :status => status,
34
+ :body => node_create_response
35
+ )
36
+ when 409
37
+ stub_request(:post, "http://localhost:4000/nodes").
38
+ with(
39
+ :body => node_create_payload ).
40
+ to_return(
41
+ :status => status,
42
+ :body => node_conflict
43
+ )
44
+ end
45
+ end
46
+
47
+ def stub_node_create_with_run_list
48
+ stub_request(:post, "http://localhost:4000/nodes").
49
+ with(
50
+ :body => node_create_payload_with_run_list ).
51
+ to_return(
52
+ :status => 201,
53
+ :body => node_create_response_with_run_list
54
+ )
55
+ end
56
+
57
+ def stub_node_delete(status=200)
58
+ case status
59
+ when 200
60
+ stub_request(:delete, "http://localhost:4000/nodes/testnode").
61
+ with(:body => "").
62
+ to_return(
63
+ :status => status,
64
+ :body => node_delete_response
65
+ )
66
+ when 404
67
+ stub_request(:delete, "http://localhost:4000/nodes/testnode").
68
+ with(:body => "").
69
+ to_return(
70
+ :status => status,
71
+ :body => node_not_found
72
+ )
73
+ end
74
+ end
75
+
76
+ # payloads and responses
77
+
78
+ def node_list_response
79
+ { "testnode" => "http://localhost:4000/nodes/testnode" }
80
+ end
81
+
82
+ def node_show_response
83
+ { "adam" => "http://localhost:4000/nodes/testnode" }
84
+ end
85
+
86
+ def node_delete_response
87
+ {
88
+ "normal" => {},
89
+ "name" => "foo",
90
+ "override" => {},
91
+ "default" => {},
92
+ "json_class" => "Chef::Node",
93
+ "automatic" => {},
94
+ "run_list" => [],
95
+ "chef_type" => "node"
96
+ }
97
+ end
98
+
99
+ def node_not_found
100
+ { "error" => [ "Could not load node testnode" ] }
101
+ end
102
+
103
+ def node_conflict
104
+ { "error" => [ "Node already exists" ] }
105
+ end
106
+
107
+ def node_create_payload
108
+ {
109
+ "name" => "testnode",
110
+ "chef_type" => "node",
111
+ "json_class" => "Chef::Node",
112
+ "attributes" => {},
113
+ "overrides" => {},
114
+ "defaults" => {},
115
+ "run_list" => []
116
+ }
117
+ end
118
+
119
+ def node_create_payload_with_run_list
120
+ {
121
+ "name" => "testnode",
122
+ "chef_type" => "node",
123
+ "json_class" => "Chef::Node",
124
+ "attributes" => {},
125
+ "overrides" => {},
126
+ "defaults" => {},
127
+ "run_list" => [ "recipe[unicorn]" ]
128
+ }
129
+ end
130
+
131
+ def node_create_response_with_run_list
132
+ { "uri" => "http://localhost:4000/nodes/testnode" }
133
+ end
134
+
135
+ def node_create_response
136
+ { "private_key"=>"-----BEGIN RSA PRIVATE KEY-----",
137
+ "uri"=>"http://localhost:4000/nodes/testnode" }
138
+ end