rubineti 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "yajl-ruby", "~> 0.7.8"
4
- gem "net-http-persistent", "~> 1.4.1"
3
+ gem "hugs", "~> 1.0.0"
5
4
 
6
5
  group :development do
7
6
  gem "rake"
@@ -9,5 +8,5 @@ group :development do
9
8
  gem "vcr", "~> 1.3.3"
10
9
  gem "webmock", "~> 1.6.1"
11
10
  gem "minitest", "~> 2.0.0"
12
- gem "mocha", "~> 0.9.10"
11
+ gem "yajl-ruby", "~> 0.7.8"
13
12
  end
data/Gemfile.lock CHANGED
@@ -4,13 +4,14 @@ GEM
4
4
  addressable (2.2.2)
5
5
  crack (0.1.8)
6
6
  git (1.2.5)
7
+ hugs (1.0.0)
8
+ net-http-persistent (~> 1.4.1)
9
+ yajl-ruby (~> 0.7.8)
7
10
  jeweler (1.5.1)
8
11
  bundler (~> 1.0.0)
9
12
  git (>= 1.2.5)
10
13
  rake
11
14
  minitest (2.0.0)
12
- mocha (0.9.10)
13
- rake
14
15
  net-http-persistent (1.4.1)
15
16
  rake (0.8.7)
16
17
  vcr (1.3.3)
@@ -23,10 +24,9 @@ PLATFORMS
23
24
  ruby
24
25
 
25
26
  DEPENDENCIES
27
+ hugs (~> 1.0.0)
26
28
  jeweler (~> 1.5.1)
27
29
  minitest (~> 2.0.0)
28
- mocha (~> 0.9.10)
29
- net-http-persistent (~> 1.4.1)
30
30
  rake
31
31
  vcr (~> 1.3.3)
32
32
  webmock (~> 1.6.1)
data/README.md CHANGED
@@ -10,35 +10,17 @@
10
10
 
11
11
  ### Examples
12
12
 
13
- Initialize a connection
14
-
15
- @connection = Rubineti::Compute.new :host => "ganeti.primary", :credentials => "fake:credentials"
16
-
17
- View all jobs
18
-
19
- @connection.jobs_list
20
-
21
- Handling query params
22
-
23
- @connection.instance_info "instance_name", :query => "bulk=1"
24
-
25
- The responses are objectified [(by Yajl)](https://github.com/lloyd/yajl), and returned unmodified.
26
-
27
- ## Testing
28
-
29
- Tests can run offline thanks to [VCR](https://github.com/myronmarston/vcr).
30
-
31
- $ bundle exec rake
32
-
33
- ## Documents
34
-
35
- * [Ganeti's remote API](http://docs.ganeti.org/ganeti/2.1/html/rapi.html)
13
+ See the examples section in the [wiki](http://github.com/retr0h/rubineti/wiki/Examples).
36
14
 
37
15
  ## Contributions
38
16
 
39
17
  I have implemented the end-points immediately needed. Feel free to send me pull requests, if you
40
18
  wish to help out.
41
19
 
20
+ ## TODO
21
+
22
+ * Remove #cassette_for test helper. It's a bad idea to use fixture data to test other fixtures.
23
+
42
24
  ## Credits
43
25
 
44
26
  Wesley Beary's [fog](https://github.com/geemus/fog), for which I referenced.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -12,7 +12,7 @@ module Rubineti
12
12
  # Returns a list of cluster information.
13
13
 
14
14
  def cluster_info
15
- get "/#{Ganeti::Version}/info"
15
+ request.get "/#{Ganeti::Version}/info"
16
16
  end
17
17
 
18
18
  ##
@@ -20,7 +20,7 @@ module Rubineti
20
20
  # Returns a job_id.
21
21
 
22
22
  def cluster_redistribute_config
23
- put "/#{Ganeti::Version}/redistribute-config"
23
+ request.put "/#{Ganeti::Version}/redistribute-config"
24
24
  end
25
25
 
26
26
  ##
@@ -61,14 +61,14 @@ module Rubineti
61
61
  # Returns the cluster API version.
62
62
 
63
63
  def cluster_version
64
- get "/version"
64
+ request.get "/version"
65
65
  end
66
66
 
67
67
  ##
68
68
  # Return a list of all OSes.
69
69
 
70
70
  def cluster_os_list
71
- get "/#{Ganeti::Version}/os"
71
+ request.get "/#{Ganeti::Version}/os"
72
72
  end
73
73
  end
74
74
  end
@@ -24,7 +24,7 @@ module Rubineti
24
24
  # checks will be done.
25
25
 
26
26
  def instance_create params = {}
27
- post "/#{Ganeti::Version}/instances", params
27
+ request.post "/#{Ganeti::Version}/instances", params
28
28
  end
29
29
 
30
30
  ##
@@ -45,7 +45,7 @@ module Rubineti
45
45
  # checks will be done.
46
46
 
47
47
  def instance_delete instance_name, params = {}
48
- delete "/#{Ganeti::Version}/instances/#{instance_name}", params
48
+ request.delete "/#{Ganeti::Version}/instances/#{instance_name}", params
49
49
  end
50
50
 
51
51
  ##
@@ -68,7 +68,7 @@ module Rubineti
68
68
  # The result will be a job id.
69
69
 
70
70
  def instance_info instance_name, params = {}
71
- get "/#{Ganeti::Version}/instances/#{instance_name}/info", params
71
+ request.get "/#{Ganeti::Version}/instances/#{instance_name}/info", params
72
72
  end
73
73
 
74
74
  ##
@@ -76,7 +76,7 @@ module Rubineti
76
76
  # the bulk output from +#instances_list+.
77
77
 
78
78
  def instance_list instance_name
79
- get "/#{Ganeti::Version}/instances/#{instance_name}"
79
+ request.get "/#{Ganeti::Version}/instances/#{instance_name}"
80
80
  end
81
81
 
82
82
  ##
@@ -132,7 +132,7 @@ module Rubineti
132
132
  # checks will be done.
133
133
 
134
134
  def instance_reboot instance_name, params = {}
135
- post "/#{Ganeti::Version}/instances/#{instance_name}/reboot", params
135
+ request.post "/#{Ganeti::Version}/instances/#{instance_name}/reboot", params
136
136
  end
137
137
 
138
138
  ##
@@ -142,7 +142,7 @@ module Rubineti
142
142
  # Takes the parameters os (OS template name) and nostartup (bool).
143
143
 
144
144
  def instance_reinstall instance_name, params = {}
145
- post "/#{Ganeti::Version}/instances/#{instance_name}/reinstall", params
145
+ request.post "/#{Ganeti::Version}/instances/#{instance_name}/reinstall", params
146
146
  end
147
147
 
148
148
  ##
@@ -153,7 +153,7 @@ module Rubineti
153
153
  # - http://docs.ganeti.org/ganeti/#{Ganeti::Version}.2/html/rapi.html#instances-instance-name-rename
154
154
 
155
155
  def instance_rename instance_name, params = {}
156
- $stderr.print "WARNING: Instances#instance_rename not implemented."
156
+ warn "WARNING: Instances#instance_rename not implemented."
157
157
  # put "/#{Ganeti::Version}/instances/#{instance_name}/rename", params
158
158
  end
159
159
 
@@ -183,7 +183,7 @@ module Rubineti
183
183
  # checks will be done.
184
184
 
185
185
  def instance_shutdown instance_name, params = {}
186
- put "/#{Ganeti::Version}/instances/#{instance_name}/shutdown", params
186
+ request.put "/#{Ganeti::Version}/instances/#{instance_name}/shutdown", params
187
187
  end
188
188
 
189
189
  ##
@@ -193,7 +193,7 @@ module Rubineti
193
193
  # the output contains detailed information about instances as a list.
194
194
 
195
195
  def instances_list params = {}
196
- get "/#{Ganeti::Version}/instances", params
196
+ request.get "/#{Ganeti::Version}/instances", params
197
197
  end
198
198
 
199
199
  ##
@@ -205,7 +205,7 @@ module Rubineti
205
205
  # checks will be done.
206
206
 
207
207
  def instance_startup instance_name, params = {}
208
- put "/#{Ganeti::Version}/instances/#{instance_name}/startup", params
208
+ request.put "/#{Ganeti::Version}/instances/#{instance_name}/startup", params
209
209
  end
210
210
 
211
211
  ##
@@ -4,7 +4,7 @@ module Rubineti
4
4
  # Returns an Array of all jobs.
5
5
 
6
6
  def jobs_list
7
- get "/#{Ganeti::Version}/jobs"
7
+ request.get "/#{Ganeti::Version}/jobs"
8
8
  end
9
9
 
10
10
  ##
@@ -13,7 +13,7 @@ module Rubineti
13
13
  # +job_id+: A String of the 'job id'.
14
14
 
15
15
  def job_list job_id
16
- get "/#{Ganeti::Version}/jobs/#{job_id}"
16
+ request.get "/#{Ganeti::Version}/jobs/#{job_id}"
17
17
  end
18
18
 
19
19
  ##
@@ -22,7 +22,7 @@ module Rubineti
22
22
  # Returns information about a node.
23
23
 
24
24
  def node_list node_name
25
- get "/2/nodes/#{node_name}"
25
+ request.get "/2/nodes/#{node_name}"
26
26
  end
27
27
 
28
28
  ##
@@ -55,7 +55,7 @@ module Rubineti
55
55
  # Returns the current node role.
56
56
 
57
57
  def node_role_list node_name
58
- get "/2/nodes/#{node_name}/role"
58
+ request.get "/2/nodes/#{node_name}/role"
59
59
  end
60
60
 
61
61
  ##
@@ -65,7 +65,7 @@ module Rubineti
65
65
  # the output contains detailed information about instances as a list.
66
66
 
67
67
  def nodes_list params = {}
68
- get "/2/nodes", params
68
+ request.get "/2/nodes", params
69
69
  end
70
70
 
71
71
  ##
@@ -1,12 +1,7 @@
1
- require "net/http/persistent"
2
- require "base64"
1
+ require "hugs"
3
2
 
4
3
  module Rubineti
5
4
  class Compute
6
- Headers = {
7
- :json => "application/json"
8
- }.freeze
9
-
10
5
  ##
11
6
  # Include endpoints.
12
7
  # TODO: meta; discover the endpoints?
@@ -23,88 +18,16 @@ module Rubineti
23
18
  # +host+: A String with the host to connect.
24
19
 
25
20
  def initialize options
26
- @user = options[:user]
27
- @password = options[:password]
28
- @host = options[:host]
29
- @port = options[:port] || 5080
30
- @scheme = options[:scheme] || "https"
31
-
32
- requires [:user, :password, :host]
33
- end
34
-
35
- ##
36
- # Perform an HTTP get, delete, post, or put.
37
- # +path+: A String with the path to the HTTP resource.
38
- # +params+: A Hash with the following keys:
39
- # - +:query+: Query String in the format "foo=bar"
40
- # - +:body+: A sub Hash to be JSON encoded, and posted in
41
- # the message body.
42
-
43
- %w(get delete post put).each do |verb|
44
- define_method verb do |*args|
45
- path = args[0]
46
- params = args[1] || {}
47
- clazz = eval "Net::HTTP::#{verb.capitalize}"
48
-
49
- parse response_for(clazz, path, params)
50
- end
51
- end
52
-
53
- ##
54
- # :method: get
55
-
56
- ##
57
- # :method: delete
58
-
59
- ##
60
- # :method: post
61
-
62
- ##
63
- # :method: put
64
-
65
- private
66
- ##
67
- # Worker method to be called by #get, #delete, #post, #put.
68
- # Method arguments have been documented in the callers.
69
-
70
- def response_for request, path, params
71
- query = params[:query] && params.delete(:query)
72
- body = params[:body] && params.delete(:body)
73
-
74
- @http ||= Net::HTTP::Persistent.new
75
- @url ||= URI.parse "#{@scheme}://#{@host}:#{@port}"
76
-
77
- @request = request.new [path, query].compact.join "?"
78
- @request.body = encode(body) if body
79
- common_headers @request
80
-
81
- @http.request(@url, @request).body
82
- end
83
-
84
- def common_headers request
85
- request.basic_auth @user, @password
86
- case request.class.to_s
87
- when Net::HTTP::Get.to_s, Net::HTTP::Delete.to_s
88
- request.add_field "accept", Headers[:json]
89
- when Net::HTTP::Post.to_s, Net::HTTP::Put.to_s
90
- request.add_field "accept", Headers[:json]
91
- request.add_field "content-type", Headers[:json]
92
- end
93
- end
94
-
95
- def parse data
96
- ::Yajl::Parser.parse data
97
- end
98
-
99
- def encode hash
100
- ::Yajl::Encoder.encode hash
21
+ @connection = Hugs.new(
22
+ :user => options[:user],
23
+ :password => options[:password],
24
+ :host => options[:host],
25
+ :port => options[:port] || 5080,
26
+ )
101
27
  end
102
28
 
103
- def requires args
104
- args.each do |arg|
105
- raise StandardError.new "FATAL: Rubineti::Compute#initialize :#{arg} required." if
106
- self.instance_variable_get(:"@#{arg}").nil?
107
- end
29
+ def request
30
+ @connection
108
31
  end
109
32
  end
110
33
  end
data/rubineti.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubineti}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["retr0h"]
12
- s.date = %q{2010-12-07}
12
+ s.date = %q{2010-12-11}
13
13
  s.email = %q{john@dewey.ws}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -53,7 +53,6 @@ Gem::Specification.new do |s|
53
53
  "test/lib/rubineti/compute/test_instances.rb",
54
54
  "test/lib/rubineti/compute/test_jobs.rb",
55
55
  "test/lib/rubineti/compute/test_node.rb",
56
- "test/lib/rubineti/test_compute.rb",
57
56
  "test/support.rb"
58
57
  ]
59
58
  s.homepage = %q{http://github.com/retr0h/rubineti}
@@ -65,7 +64,6 @@ Gem::Specification.new do |s|
65
64
  "test/lib/rubineti/compute/test_instances.rb",
66
65
  "test/lib/rubineti/compute/test_jobs.rb",
67
66
  "test/lib/rubineti/compute/test_node.rb",
68
- "test/lib/rubineti/test_compute.rb",
69
67
  "test/support.rb"
70
68
  ]
71
69
 
@@ -74,33 +72,30 @@ Gem::Specification.new do |s|
74
72
  s.specification_version = 3
75
73
 
76
74
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
77
- s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.7.8"])
78
- s.add_runtime_dependency(%q<net-http-persistent>, ["~> 1.4.1"])
75
+ s.add_runtime_dependency(%q<hugs>, ["~> 1.0.0"])
79
76
  s.add_development_dependency(%q<rake>, [">= 0"])
80
77
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
81
78
  s.add_development_dependency(%q<vcr>, ["~> 1.3.3"])
82
79
  s.add_development_dependency(%q<webmock>, ["~> 1.6.1"])
83
80
  s.add_development_dependency(%q<minitest>, ["~> 2.0.0"])
84
- s.add_development_dependency(%q<mocha>, ["~> 0.9.10"])
81
+ s.add_development_dependency(%q<yajl-ruby>, ["~> 0.7.8"])
85
82
  else
86
- s.add_dependency(%q<yajl-ruby>, ["~> 0.7.8"])
87
- s.add_dependency(%q<net-http-persistent>, ["~> 1.4.1"])
83
+ s.add_dependency(%q<hugs>, ["~> 1.0.0"])
88
84
  s.add_dependency(%q<rake>, [">= 0"])
89
85
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
90
86
  s.add_dependency(%q<vcr>, ["~> 1.3.3"])
91
87
  s.add_dependency(%q<webmock>, ["~> 1.6.1"])
92
88
  s.add_dependency(%q<minitest>, ["~> 2.0.0"])
93
- s.add_dependency(%q<mocha>, ["~> 0.9.10"])
89
+ s.add_dependency(%q<yajl-ruby>, ["~> 0.7.8"])
94
90
  end
95
91
  else
96
- s.add_dependency(%q<yajl-ruby>, ["~> 0.7.8"])
97
- s.add_dependency(%q<net-http-persistent>, ["~> 1.4.1"])
92
+ s.add_dependency(%q<hugs>, ["~> 1.0.0"])
98
93
  s.add_dependency(%q<rake>, [">= 0"])
99
94
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
100
95
  s.add_dependency(%q<vcr>, ["~> 1.3.3"])
101
96
  s.add_dependency(%q<webmock>, ["~> 1.6.1"])
102
97
  s.add_dependency(%q<minitest>, ["~> 2.0.0"])
103
- s.add_dependency(%q<mocha>, ["~> 0.9.10"])
98
+ s.add_dependency(%q<yajl-ruby>, ["~> 0.7.8"])
104
99
  end
105
100
  end
106
101
 
data/test/support.rb CHANGED
@@ -1,18 +1,16 @@
1
1
  Bundler.setup :default, :test
2
2
 
3
3
  require "minitest/spec"
4
- require "mocha"
5
4
 
6
5
  Dir[File.join "./lib", "**", "*.rb"].each { |f| require f }
7
6
 
8
7
  class MiniTest::Unit::TestCase
9
8
  Connection = Rubineti::Compute.new(
10
- :host => "ganeti.primary",
11
- :user => "fake",
9
+ :host => "ganeti.primary",
10
+ :user => "fake",
12
11
  :password => "credentials"
13
12
  )
14
13
  Job_Matcher = %r{^\d{4}$}
15
- Json_Headers_Matcher = %r{#{Rubineti::Compute::Headers[:json]}}
16
14
  Not_Implemented_Matcher = %r{^WARNING: [A-Z][a-z]+#[a-z]+_[a-z_]+ not implemented.$}
17
15
 
18
16
  require "yajl"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 1.1.0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - retr0h
@@ -14,42 +14,27 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-07 00:00:00 -08:00
17
+ date: 2010-12-11 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: yajl-ruby
21
+ name: hugs
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
+ - 1
28
29
  - 0
29
- - 7
30
- - 8
31
- version: 0.7.8
30
+ - 0
31
+ version: 1.0.0
32
32
  type: :runtime
33
33
  prerelease: false
34
34
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: net-http-persistent
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 4
45
- - 1
46
- version: 1.4.1
47
- type: :runtime
48
- prerelease: false
49
- version_requirements: *id002
50
35
  - !ruby/object:Gem::Dependency
51
36
  name: rake
52
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
53
38
  none: false
54
39
  requirements:
55
40
  - - ">="
@@ -59,10 +44,10 @@ dependencies:
59
44
  version: "0"
60
45
  type: :development
61
46
  prerelease: false
62
- version_requirements: *id003
47
+ version_requirements: *id002
63
48
  - !ruby/object:Gem::Dependency
64
49
  name: jeweler
65
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &id003 !ruby/object:Gem::Requirement
66
51
  none: false
67
52
  requirements:
68
53
  - - ~>
@@ -74,10 +59,10 @@ dependencies:
74
59
  version: 1.5.1
75
60
  type: :development
76
61
  prerelease: false
77
- version_requirements: *id004
62
+ version_requirements: *id003
78
63
  - !ruby/object:Gem::Dependency
79
64
  name: vcr
80
- requirement: &id005 !ruby/object:Gem::Requirement
65
+ requirement: &id004 !ruby/object:Gem::Requirement
81
66
  none: false
82
67
  requirements:
83
68
  - - ~>
@@ -89,10 +74,10 @@ dependencies:
89
74
  version: 1.3.3
90
75
  type: :development
91
76
  prerelease: false
92
- version_requirements: *id005
77
+ version_requirements: *id004
93
78
  - !ruby/object:Gem::Dependency
94
79
  name: webmock
95
- requirement: &id006 !ruby/object:Gem::Requirement
80
+ requirement: &id005 !ruby/object:Gem::Requirement
96
81
  none: false
97
82
  requirements:
98
83
  - - ~>
@@ -104,10 +89,10 @@ dependencies:
104
89
  version: 1.6.1
105
90
  type: :development
106
91
  prerelease: false
107
- version_requirements: *id006
92
+ version_requirements: *id005
108
93
  - !ruby/object:Gem::Dependency
109
94
  name: minitest
110
- requirement: &id007 !ruby/object:Gem::Requirement
95
+ requirement: &id006 !ruby/object:Gem::Requirement
111
96
  none: false
112
97
  requirements:
113
98
  - - ~>
@@ -119,22 +104,22 @@ dependencies:
119
104
  version: 2.0.0
120
105
  type: :development
121
106
  prerelease: false
122
- version_requirements: *id007
107
+ version_requirements: *id006
123
108
  - !ruby/object:Gem::Dependency
124
- name: mocha
125
- requirement: &id008 !ruby/object:Gem::Requirement
109
+ name: yajl-ruby
110
+ requirement: &id007 !ruby/object:Gem::Requirement
126
111
  none: false
127
112
  requirements:
128
113
  - - ~>
129
114
  - !ruby/object:Gem::Version
130
115
  segments:
131
116
  - 0
132
- - 9
133
- - 10
134
- version: 0.9.10
117
+ - 7
118
+ - 8
119
+ version: 0.7.8
135
120
  type: :development
136
121
  prerelease: false
137
- version_requirements: *id008
122
+ version_requirements: *id007
138
123
  description:
139
124
  email: john@dewey.ws
140
125
  executables: []
@@ -182,7 +167,6 @@ files:
182
167
  - test/lib/rubineti/compute/test_instances.rb
183
168
  - test/lib/rubineti/compute/test_jobs.rb
184
169
  - test/lib/rubineti/compute/test_node.rb
185
- - test/lib/rubineti/test_compute.rb
186
170
  - test/support.rb
187
171
  has_rdoc: true
188
172
  homepage: http://github.com/retr0h/rubineti
@@ -221,5 +205,4 @@ test_files:
221
205
  - test/lib/rubineti/compute/test_instances.rb
222
206
  - test/lib/rubineti/compute/test_jobs.rb
223
207
  - test/lib/rubineti/compute/test_node.rb
224
- - test/lib/rubineti/test_compute.rb
225
208
  - test/support.rb
@@ -1,92 +0,0 @@
1
- require "support"
2
-
3
- describe Rubineti::Compute do
4
- before do
5
- @user = "fake"
6
- @password = "credentials"
7
- @valid_params = {
8
- :host => "ganeti.primary",
9
- :user => @user,
10
- :password => @password
11
- }
12
- end
13
-
14
- describe "#requires" do
15
- [:user, :password, :host].each do |opt|
16
- it "has required '#{opt}' option" do
17
- lambda { Rubineti::Compute.new @valid_params.reject { |k,v| k == opt } }.must_raise StandardError
18
- end
19
- end
20
- end
21
-
22
- describe "#response_for" do
23
- before do
24
- @instance = Rubineti::Compute.new @valid_params
25
- @http = mock(:request => mock(:body => :body))
26
- @request = Net::HTTP::Get
27
-
28
- Net::HTTP::Persistent.stubs :new => @http
29
- end
30
-
31
- it "generates a path" do
32
- @instance.send :response_for, @request, "/", {}
33
-
34
- @instance.instance_variable_get(:@request).path.must_equal "/"
35
- end
36
-
37
- it "generates a path when a valid :query exists" do
38
- @instance.send :response_for, @request, "/", :query => "foo=bar"
39
-
40
- @instance.instance_variable_get(:@request).path.must_equal "/?foo=bar"
41
- end
42
-
43
- it "generates a path when a nil :query exists" do
44
- @instance.send :response_for, @request, "/", :query => nil
45
-
46
- @instance.instance_variable_get(:@request).path.must_equal "/"
47
- end
48
-
49
- it "sets the body as JSON when a valid :body exists" do
50
- @instance.send :response_for, @request, "/", :body => {:foo => :bar}
51
-
52
- @instance.instance_variable_get(:@request).body.must_equal '{"foo":"bar"}'
53
- end
54
-
55
- it "doesn't set the body when an invalid :body exists" do
56
- @instance.send :response_for, @request, "/", :body => nil
57
-
58
- @instance.instance_variable_get(:@request).body.must_be_nil
59
- end
60
-
61
- describe "headers" do
62
- it "has authentication" do
63
- @instance.send :response_for, @request, "/", {}
64
-
65
- @instance.instance_variable_get(:@request).get_fields("authorization").join.
66
- must_match %r{Basic #{Base64.encode64("#{@user}:#{@password}").delete("\r\n")}}
67
- end
68
-
69
- [Net::HTTP::Post, Net::HTTP::Put].each do |clazz|
70
- it "has content-type and accept for '#{clazz}'" do
71
- @instance.send :response_for, clazz, "/", {}
72
-
73
- @instance.instance_variable_get(:@request).get_fields("content-type").join.
74
- must_match Json_Headers_Matcher
75
- @instance.instance_variable_get(:@request).get_fields("accept").join.
76
- must_match Json_Headers_Matcher
77
- end
78
- end
79
-
80
- [Net::HTTP::Get, Net::HTTP::Delete].each do |clazz|
81
- it "has accept for '#{clazz}'" do
82
- @instance.send :response_for, clazz, "/", {}
83
-
84
- @instance.instance_variable_get(:@request).get_fields("accept").join.
85
- must_match Json_Headers_Matcher
86
- @instance.instance_variable_get(:@request).get_fields("content-type").
87
- must_be_nil
88
- end
89
- end
90
- end
91
- end
92
- end