misty 1.3.3 → 1.4.0

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +332 -267
  3. data/lib/misty.rb +1 -1
  4. data/lib/misty/auth.rb +17 -6
  5. data/lib/misty/auth/auth_v2.rb +3 -0
  6. data/lib/misty/auth/auth_v3.rb +13 -5
  7. data/lib/misty/auth/name.rb +3 -3
  8. data/lib/misty/client_pack.rb +2 -2
  9. data/lib/misty/cloud.rb +111 -76
  10. data/lib/misty/config.rb +138 -0
  11. data/lib/misty/{auth/errors.rb → errors.rb} +9 -1
  12. data/lib/misty/http/direct.rb +18 -1
  13. data/lib/misty/http/method_builder.rb +10 -17
  14. data/lib/misty/http/net_http.rb +1 -1
  15. data/lib/misty/http/request.rb +26 -14
  16. data/lib/misty/microversion.rb +22 -41
  17. data/lib/misty/misty.rb +14 -24
  18. data/lib/misty/openstack/cinder/v3.rb +8 -0
  19. data/lib/misty/openstack/ironic/v1.rb +8 -0
  20. data/lib/misty/openstack/magnum/v1.rb +5 -1
  21. data/lib/misty/openstack/manila/v2.rb +8 -0
  22. data/lib/misty/openstack/nova/v2_1.rb +13 -8
  23. data/lib/misty/openstack/service.rb +88 -0
  24. data/lib/misty/openstack/swift/v1.rb +2 -2
  25. data/lib/misty/service.rb +9 -12
  26. data/lib/misty/version.rb +1 -1
  27. data/test/integration/{network_test.rb → networking_test.rb} +8 -8
  28. data/test/integration/test_helper.rb +1 -0
  29. data/test/integration/vcr/{network_using_neutron_v2_0.yml → networking_using_neutron_v2_0.yml} +0 -0
  30. data/test/unit/auth/name_test.rb +31 -27
  31. data/test/unit/auth_helper.rb +4 -4
  32. data/test/unit/auth_test.rb +44 -30
  33. data/test/unit/cloud/config_test.rb +165 -0
  34. data/test/unit/cloud/requests_test.rb +0 -12
  35. data/test/unit/cloud/services_test.rb +41 -12
  36. data/test/unit/cloud_test.rb +35 -44
  37. data/test/unit/http/request_test.rb +1 -1
  38. data/test/unit/microversion_test.rb +59 -35
  39. data/test/unit/misty_test.rb +1 -1
  40. data/test/unit/openstack/service_test.rb +52 -0
  41. data/test/unit/service_helper.rb +23 -20
  42. data/test/unit/services_test.rb +1 -1
  43. data/test/unit/test_helper.rb +0 -4
  44. metadata +37 -22
  45. data/lib/misty/client.rb +0 -104
  46. data/test/unit/client_test.rb +0 -97
@@ -0,0 +1,165 @@
1
+ require 'test_helper'
2
+ require 'auth_helper'
3
+ require 'misty/config'
4
+
5
+ describe Misty::Config do
6
+ describe 'without auth' do
7
+ it 'fails' do
8
+ proc do
9
+ Misty::Config.new({})
10
+ end.must_raise Misty::Config::CredentialsError
11
+ end
12
+ end
13
+
14
+ describe 'with auth' do
15
+ let(:auth) do
16
+ {
17
+ :url => 'http://localhost:5000',
18
+ :user_id => 'user_id',
19
+ :password => 'secret',
20
+ :project_id => 'project_id',
21
+ :ssl_verify_mode => false
22
+ }
23
+ end
24
+
25
+ let(:auth_request) do
26
+ stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
27
+ with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}").
28
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'})
29
+ end
30
+
31
+ describe 'fails' do
32
+ it 'with wrong header type' do
33
+ auth_request
34
+ proc do
35
+ Misty::Config.new(:auth => auth, :headers => :blah)
36
+ end.must_raise Misty::HTTP::Header::TypeError
37
+ end
38
+
39
+ it 'with interface wrong type' do
40
+ auth_request
41
+ proc do
42
+ Misty::Config.new(:auth => auth, :interface => 'something')
43
+ end.must_raise Misty::Config::InvalidDataError
44
+ end
45
+
46
+ it 'with region_id wrong type' do
47
+ auth_request
48
+ proc do
49
+ Misty::Config.new(:auth => auth, :region_id => true)
50
+ end.must_raise Misty::Config::InvalidDataError
51
+ end
52
+
53
+ it 'with ssl_verify_mode wrong type' do
54
+ auth_request
55
+ proc do
56
+ Misty::Config.new(:auth => auth, :ssl_verify_mode => 'something')
57
+ end.must_raise Misty::Config::InvalidDataError
58
+ end
59
+ end
60
+
61
+ describe "success" do
62
+ it 'using Cloud level defaults' do
63
+ auth_request
64
+ config = Misty::Config.new(:auth => auth)
65
+ def config.globals
66
+ @globals
67
+ end
68
+
69
+ config.log.must_be_kind_of Logger
70
+ config.auth.must_be_kind_of Misty::AuthV3
71
+ config.globals[:content_type].must_equal Misty::Config::CONTENT_TYPE
72
+ config.globals[:headers].must_be_kind_of Misty::HTTP::Header
73
+ config.globals[:headers].get.must_equal("Accept"=>"application/json; q=1.0")
74
+ config.globals[:interface].must_equal Misty::Config::INTERFACE
75
+ config.globals[:region_id].must_equal Misty::Config::REGION_ID
76
+ config.globals[:ssl_verify_mode].must_equal Misty::Config::SSL_VERIFY_MODE
77
+ end
78
+
79
+ it 'with Cloud level parameters' do
80
+ auth_request
81
+
82
+ LOG_FILE_NAME = "./misty-unit_test-#{Process.pid}"
83
+ config = Misty::Config.new(
84
+ :auth => auth,
85
+ :content_type => :json,
86
+ :headers => {'var' => 'value'},
87
+ :interface => 'admin',
88
+ :region_id => 'regionTest',
89
+ :ssl_verify_mode => false,
90
+ :log_file => LOG_FILE_NAME
91
+ )
92
+ def config.globals
93
+ @globals
94
+ end
95
+
96
+ config.globals[:content_type].must_equal :json
97
+ config.globals[:headers].get.must_equal('Accept' => 'application/json; q=1.0', 'var' => 'value')
98
+ config.globals[:interface].must_equal 'admin'
99
+ config.globals[:region_id].must_equal 'regionTest'
100
+ config.globals[:ssl_verify_mode].must_equal false
101
+ File.exist?(LOG_FILE_NAME).must_equal true
102
+ File.delete(LOG_FILE_NAME) if File.exist?(LOG_FILE_NAME)
103
+ end
104
+
105
+ describe 'service level configurations' do
106
+ it 'with globals defaults' do
107
+ auth_request
108
+ config = Misty::Config.new(
109
+ :auth => auth,
110
+ :compute => {
111
+ :content_type => :json,
112
+ :headers => {'Service Key' => 'Service Value'},
113
+ :interface => 'internal',
114
+ :region_id => 'region local',
115
+ :ssl_verify_mode => false,
116
+
117
+ :base_path => 'base_path_test',
118
+ :base_url => '/base.url.com',
119
+ :version => 'vtest'
120
+ }
121
+ )
122
+
123
+ service_config = config.get_service(:compute)
124
+ service_config[:config][:content_type].must_equal :json
125
+ service_config[:config][:headers].get.must_equal('Accept' => 'application/json; q=1.0', 'Service Key' => 'Service Value')
126
+ service_config[:config][:interface].must_equal 'internal'
127
+ service_config[:config][:region_id].must_equal 'region local'
128
+ service_config[:config][:ssl_verify_mode].must_equal false
129
+ service_config[:config][:base_path].must_equal 'base_path_test'
130
+ service_config[:config][:base_url].must_equal '/base.url.com'
131
+ service_config[:config][:version].must_equal 'vtest'
132
+ end
133
+
134
+ it 'with Cloud level parameters' do
135
+ auth_request
136
+ config = Misty::Config.new(
137
+ :auth => auth,
138
+ :content_type => :json,
139
+ :headers => {'Global Key' => 'Global Value'},
140
+ :interface => 'internal',
141
+ :region_id => 'region_global',
142
+ :ssl_verify_mode => false,
143
+ :networking => {
144
+ :content_type => :hash,
145
+ :headers => {'Local Key' => 'Local Value'},
146
+ :interface => 'admin',
147
+ :region_id => 'region_local',
148
+ :ssl_verify_mode => true
149
+ }
150
+ )
151
+ def config.globals
152
+ @globals
153
+ end
154
+
155
+ service_config = config.get_service(:networking)
156
+ service_config[:config][:content_type].must_equal :hash
157
+ service_config[:config][:headers].get.must_equal('Accept' => 'application/json; q=1.0', 'Global Key' => 'Global Value', 'Local Key' => 'Local Value')
158
+ service_config[:config][:interface].must_equal 'admin'
159
+ service_config[:config][:region_id].must_equal 'region_local'
160
+ service_config[:config][:ssl_verify_mode].must_equal true
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
@@ -46,18 +46,6 @@ describe Misty::Cloud do
46
46
  cloud.image.show_image_member_details('id1', 'id2').response.must_be_kind_of Net::HTTPOK
47
47
  end
48
48
 
49
- it 'successful with an extra header parameter' do
50
- stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
51
- to_return(:status => 200, :body => JSON.dump(auth_response_v3('network', 'neutron')), :headers => {'x-subject-token'=>'token_data'})
52
-
53
- stub_request(:get, "http://localhost/v2.0/networks?name=value").
54
- with(:headers => {'Test-Header'=>'test header value'}).
55
- to_return(:status => 200, :body => "", :headers => {})
56
-
57
- header = Misty::HTTP::Header.new('Test-Header' => 'test header value')
58
- cloud.network.list_networks('name=value', header).response.must_be_kind_of Net::HTTPOK
59
- end
60
-
61
49
  it 'fails when not enough arguments' do
62
50
  proc do
63
51
  # '/v2/images/{image_id}/members/{member_id}'
@@ -2,15 +2,17 @@ require 'test_helper'
2
2
  require 'auth_helper'
3
3
 
4
4
  describe 'Misty::Cloud' do
5
- let(:cloud) do
6
- auth = {
5
+ let(:auth) do
6
+ {
7
7
  :url => 'http://localhost:5000',
8
8
  :user => 'admin',
9
9
  :password => 'secret',
10
10
  :project => 'admin',
11
11
  :project_domain_id => 'default'
12
12
  }
13
+ end
13
14
 
15
+ let(:cloud) do
14
16
  Misty::Cloud.new(:auth => auth)
15
17
  end
16
18
 
@@ -100,16 +102,42 @@ describe 'Misty::Cloud' do
100
102
  cloud.block_storage.must_be_kind_of Misty::Openstack::Cinder::V3
101
103
  end
102
104
 
103
- it '#compute' do
104
- stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
105
- with(:body => JSON.dump(auth_body), :headers => auth_headers).
106
- to_return(:status => 200, :body => JSON.dump(auth_response_v3('compute', 'nova')), :headers => token_header)
105
+ describe '#compute' do
106
+ it 'without microversion provided' do
107
+ stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
108
+ with(:body => JSON.dump(auth_body), :headers => auth_headers).
109
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('compute', 'nova')), :headers => token_header)
107
110
 
108
- stub_request(:get, 'http://localhost/').
109
- with(:headers => auth_headers).
110
- to_return(:status => 200, :body => JSON.dump(versions), :headers => {})
111
+ stub_request(:get, 'http://localhost/').
112
+ with(:headers => auth_headers).
113
+ to_return(:status => 200, :body => JSON.dump(versions), :headers => {})
114
+
115
+ cloud.compute.must_be_kind_of Misty::Openstack::Nova::V2_1
116
+ end
111
117
 
112
- cloud.compute.must_be_kind_of Misty::Openstack::Nova::V2_1
118
+ it 'with microversion provided' do
119
+ stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
120
+ with(:body => JSON.dump(auth_body), :headers => auth_headers).
121
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('compute', 'nova')), :headers => token_header)
122
+
123
+ stub_request(:get, 'http://localhost/').
124
+ with(:headers => auth_headers).
125
+ to_return(:status => 200, :body => JSON.dump(versions), :headers => {})
126
+
127
+ compute_cloud = Misty::Cloud.new(:auth => auth, :compute => {:version => '2.17'})
128
+
129
+ compute_cloud.compute.must_be_kind_of Misty::Openstack::Nova::V2_1
130
+
131
+ stub_request(:get, "http://localhost/servers").
132
+ with(:headers => {'Accept'=>'application/json; q=1.0', 'X-Auth-Token'=>'token_data', 'X-Openstack-Nova-Api-Version'=>'2.17'})
133
+
134
+ compute_cloud.compute.list_servers
135
+
136
+ stub_request(:get, "http://localhost/servers").
137
+ with(:headers => {'Accept'=>'application/json; q=1.0', 'X-Auth-Token'=>'token_data', 'X-Openstack-Nova-Api-Version'=>'2.19'})
138
+
139
+ compute_cloud.compute(:version => '2.19').list_servers
140
+ end
113
141
  end
114
142
 
115
143
  it '#dataProcessing' do
@@ -175,7 +203,7 @@ describe 'Misty::Cloud' do
175
203
  to_return(:status => 200, :body => JSON.dump(auth_response_v3('object-store', 'swift')), :headers => token_header)
176
204
 
177
205
  stub_request(:post, "http://localhost/?bulk-delete=1").
178
- with(:headers => {'Accept'=>'application/json; q=1.0', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'text/plain', 'User-Agent'=>'Ruby', 'X-Auth-Token'=>'token_data'}).
206
+ with(:headers => {'Accept'=>'application/json; q=1.0', 'Content-Type'=>'text/plain', 'User-Agent'=>'Ruby', 'X-Auth-Token'=>'token_data'}).
179
207
  to_return(:status => 200, :body => "", :headers => {})
180
208
 
181
209
  cloud.object_storage.requests.must_include :bulk_delete
@@ -222,7 +250,8 @@ describe 'Misty::Cloud' do
222
250
 
223
251
  it '#data is ambiguous' do
224
252
  stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
225
- with(:body => JSON.dump(auth_body), :headers => auth_headers)
253
+ with(:body => JSON.dump(auth_body), :headers => auth_headers).
254
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('Identity', 'keystone')), :headers => token_header)
226
255
 
227
256
  proc do
228
257
  cloud.data
@@ -1,43 +1,51 @@
1
1
  require 'test_helper'
2
- require 'service_helper'
3
2
  require 'auth_helper'
4
3
 
5
- describe '#dot_to_underscore' do
6
- it 'returns a valid name' do
7
- name = Misty::Cloud.dot_to_underscore('v20.90.01')
8
- name.must_equal 'v20_90_01'
4
+ describe Misty::Cloud do
5
+ describe '#dot_to_underscore' do
6
+ it 'returns a valid name' do
7
+ name = Misty::Cloud.dot_to_underscore('v20.90.01')
8
+ name.must_equal 'v20_90_01'
9
+ end
9
10
  end
10
- end
11
11
 
12
- describe Misty::Cloud do
13
- describe 'A service' do
14
- let(:auth) do
15
- stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
16
- with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"name\":\"admin\",\"domain\":{\"id\":\"default\"},\"password\":\"secret\"}}},\"scope\":{\"project\":{\"name\":\"admin\",\"domain\":{\"id\":\"default\"}}}}}",
17
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
18
- to_return(:status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'})
19
-
20
- auth = {
21
- :url => 'http://localhost:5000',
22
- :user => 'admin',
23
- :password => 'secret',
24
- :project => 'admin',
25
- :project_domain_id => 'default'
12
+ describe 'identity' do
13
+ let(:arg) do
14
+ arg = {
15
+ :auth => {
16
+ :url => 'http://localhost:5000',
17
+ :user_id => 'user_id',
18
+ :password => 'secret',
19
+ :project_id => 'project_id',
20
+ :ssl_verify_mode => false
21
+ },
26
22
  }
27
23
  end
28
24
 
25
+ let(:auth_request) do
26
+ stub_request(:post, "http://localhost:5000/v3/auth/tokens").
27
+ with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}",
28
+ :headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
29
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'})
30
+ end
31
+
29
32
  it 'uses default version' do
30
- cloud = Misty::Cloud.new(:auth => auth)
33
+ auth_request
34
+ cloud = Misty::Cloud.new(arg)
31
35
  cloud.identity.must_be_kind_of Misty::Openstack::Keystone::V3
32
36
  end
33
37
 
34
38
  it 'uses default version when provided version is out of range' do
35
- cloud = Misty::Cloud.new(:auth => auth, :identity => {:api_version => 'v1'})
39
+ auth_request
40
+ arg.merge!(:identity => {:api_version => 'v1'})
41
+ cloud = Misty::Cloud.new(arg)
36
42
  cloud.identity.must_be_kind_of Misty::Openstack::Keystone::V3
37
43
  end
38
44
 
39
45
  it 'uses provided version' do
40
- cloud = Misty::Cloud.new(:auth => auth, :identity => {:api_version => 'v2.0'})
46
+ auth_request
47
+ arg.merge!(:identity => {:api_version => 'v2.0'})
48
+ cloud = Misty::Cloud.new(arg)
41
49
  cloud.identity.must_be_kind_of Misty::Openstack::Keystone::V2_0
42
50
  end
43
51
  end
@@ -51,23 +59,6 @@ describe Misty::Cloud do
51
59
  end
52
60
  end
53
61
 
54
- describe '#config' do
55
- it 'sets up default values' do
56
- Misty::Auth.stub :factory, nil do
57
- config = Misty::Cloud.set_configuration({})
58
- config.must_be_kind_of Misty::Cloud::Config
59
-
60
- config.content_type.must_equal Misty::CONTENT_TYPE
61
- config.headers.must_be_kind_of Misty::HTTP::Header
62
- config.headers.get.must_equal({"Accept"=>"application/json; q=1.0"})
63
- config.interface.must_equal Misty::INTERFACE
64
- config.log.must_be_kind_of Logger
65
- config.region_id.must_equal Misty::REGION_ID
66
- config.ssl_verify_mode.must_equal Misty::SSL_VERIFY_MODE
67
- end
68
- end
69
- end
70
-
71
62
  describe '#new' do
72
63
  describe 'fails' do
73
64
  it 'when no parameters' do
@@ -79,13 +70,13 @@ describe Misty::Cloud do
79
70
  it 'with empty credentials' do
80
71
  proc do
81
72
  Misty::Cloud.new(:auth => {})
82
- end.must_raise Misty::Auth::URLError
73
+ end.must_raise Misty::Config::CredentialsError
83
74
  end
84
75
 
85
76
  it 'with incomplete credentials' do
86
77
  proc do
87
78
  Misty::Cloud.new(:auth => {:user => 'user', :url => 'http://localhost' })
88
- end.must_raise Misty::Auth::CredentialsError
79
+ end.must_raise Misty::Config::CredentialsError
89
80
  end
90
81
 
91
82
  it 'without url' do
@@ -130,7 +121,7 @@ describe Misty::Cloud do
130
121
 
131
122
  Misty::AuthV2.stub :new, authv2 do
132
123
  cloud = Misty::Cloud.new(:auth => authv2_data)
133
- authv2.verify
124
+ assert_mock authv2
134
125
  end
135
126
  end
136
127
  end
@@ -150,7 +141,7 @@ describe Misty::Cloud do
150
141
 
151
142
  Misty::AuthV3.stub :new, authv3 do
152
143
  cloud = Misty::Cloud.new(:auth => authv3_data)
153
- authv3.verify
144
+ assert_mock authv3
154
145
  end
155
146
  end
156
147
  end
@@ -126,7 +126,7 @@ describe Misty::HTTP::Request do
126
126
  end
127
127
 
128
128
  it '#http_to_s' do
129
- service.http_to_s('/resource', 'headers', 'data' => 'value').must_equal "base_url='localhost:80', path='/resource', header=headers, data='{\"data\"=>\"value\"}'"
129
+ service.http_to_s('VERB', '/resource', 'headers', 'data' => 'value').must_equal "HTTP VERB base_url='localhost:80', path='/resource', header=headers, data='{\"data\"=>\"value\"}'"
130
130
  end
131
131
  end
132
132
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'auth_helper'
3
- require 'misty/client'
4
3
  require 'misty/microversion'
4
+ require 'misty/http/request'
5
5
 
6
6
  describe Misty::Microversion do
7
7
  let(:versions_data) do
@@ -16,60 +16,84 @@ describe Misty::Microversion do
16
16
  'updated' => '2013-07-23T11:33:21Z',
17
17
  'links' => [{ 'href' => 'http://localhost/v2.1/', 'rel' => 'self' }],
18
18
  'min_version' => '2.1',
19
- 'version' => '2.25',
19
+ 'version' => '2.60',
20
20
  'id' => 'v2.1' }] }
21
21
  end
22
22
 
23
- let(:microversion_service) do
24
- auth = Minitest::Mock.new
23
+ describe '#set_version' do
24
+ let(:service) do
25
+ service = Object.new
26
+ service.extend(Misty::Microversion)
25
27
 
26
- def auth.get_url(*args)
27
- 'http://localhost'
28
+ def service.headers
29
+ @headers = Misty::HTTP::Header.new
30
+ end
31
+ service.headers
32
+ service
28
33
  end
29
34
 
30
- def auth.get_token
31
- 'token_id'
32
- end
35
+ describe 'fetch versions' do
36
+ before do
37
+ service.extend(Misty::HTTP::Request)
33
38
 
34
- setup = Misty::Cloud::Config.new
35
- setup.content_type = :ruby
36
- setup.log = Logger.new('/dev/null')
37
- setup.interface = Misty::INTERFACE
38
- setup.region_id = Misty::REGION_ID
39
- setup.ssl_verify_mode = Misty::SSL_VERIFY_MODE
40
- setup.headers = Misty::HTTP::Header.new('Accept' => 'application/json; q=1.0')
39
+ stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
40
+ with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}").
41
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'})
41
42
 
42
- stub_request(:get, 'http://localhost/').
43
- with(:headers => {'Accept'=>'application/json'}).
44
- to_return(:status => 200, :body => JSON.dump(versions_data), :headers => {})
43
+ def service.setup
44
+ @uri = URI.parse('http://localhost/')
45
+ @log = Logger.new('/dev/null')
46
+ @auth = Misty::AuthV3.new(
47
+ :url => 'http://localhost:5000',
48
+ :user_id => 'user_id',
49
+ :password => 'secret',
50
+ :project_id => 'project_id'
51
+ )
52
+ end
53
+ service.setup
54
+ end
45
55
 
46
- Misty::Openstack::Nova::V2_1.new(auth, setup, {})
47
- end
56
+ let(:fetch_request) do
57
+ stub_request(:get, "http://localhost/").
58
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby', 'X-Auth-Token'=>'token_data'}).
59
+ to_return(:status => 200, :body => JSON.dump(versions_data), :headers => {})
60
+ end
48
61
 
49
- describe '#version_get' do
50
- it 'returns the version number' do
51
- microversion_service.version_get('2.12').must_equal '2.12'
52
- end
62
+ it 'set microversion when number within min/max range' do
63
+ fetch_request
64
+
65
+ def service.service_names
66
+ %w{service_name1}
67
+ end
53
68
 
54
- it 'returns the version number' do
55
- microversion_service.version_get('CURRENT').must_equal '2.25'
69
+ service.microversion_header('2.60').must_equal({"X-Openstack-API-Version" => "service_name1 2.60"})
70
+ end
71
+
72
+ it 'fails when asked version is not within min-max range' do
73
+ fetch_request
74
+
75
+ proc do
76
+ service.set_version('3.20')
77
+ end.must_raise Misty::Microversion::VersionError
78
+ end
56
79
  end
57
80
 
58
- it 'fails when version is not within supporterd interval' do
59
- proc do
60
- microversion_service.version_get('2.0')
61
- end.must_raise Misty::Microversion::VersionError
81
+ it "set microversion to 'latest'" do
82
+ def service.service_names
83
+ %w{service_name2}
84
+ end
85
+ service.microversion_header('latest').must_equal({"X-Openstack-API-Version" => "service_name2 latest"})
62
86
  end
63
87
 
64
- it 'fails when LATEST version is not available' do
88
+ it 'fails when version is a wrong word' do
65
89
  proc do
66
- microversion_service.version_get('LATEST')
90
+ service.set_version('testing')
67
91
  end.must_raise Misty::Microversion::VersionError
68
92
  end
69
93
 
70
- it 'fails when using an invalid version State' do
94
+ it "fails when version does't match <number.number>" do
71
95
  proc do
72
- microversion_service.version_get('OTHER')
96
+ service.set_version('1.2.3')
73
97
  end.must_raise Misty::Microversion::VersionError
74
98
  end
75
99
  end