зеркало из
1
0
Форкнуть 0

Removing azure-core related unit tests

This commit is contained in:
veronicagg 2016-05-27 16:07:32 -07:00 коммит произвёл Vishrut Shah
Родитель 23ddb04181
Коммит 5103f2fb23
9 изменённых файлов: 0 добавлений и 507 удалений

Просмотреть файл

@ -33,10 +33,6 @@ describe Azure::Blob::Auth::SharedAccessSignature do
subject { Azure::Blob::Auth::SharedAccessSignature.new(access_account_name, access_key_base64) }
it 'decodes the base64 encoded access_key' do
subject.access_key.must_equal 'access-key'
end
describe '#signable_string' do
it 'constructs a string in the required format' do

Просмотреть файл

@ -1,51 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
require 'azure/core/auth/shared_key_lite'
describe Azure::Core::Auth::SharedKeyLite do
subject { Azure::Core::Auth::SharedKeyLite.new 'account-name', 'YWNjZXNzLWtleQ==' }
let(:verb) { 'POST' }
let(:uri) { URI.parse 'http://dummy.uri/resource' }
let(:headers) do
{
'Content-MD5' => 'foo',
'Content-Type' => 'foo',
'Date' => 'foo'
}
end
let(:headers_without_date) {
headers_without_date = headers.clone
headers_without_date.delete 'Date'
headers_without_date
}
describe 'sign' do
it 'creates a signature from the provided HTTP method, uri, and reduced set of standard headers' do
subject.sign(verb, uri, headers).must_equal 'account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE='
end
it 'ignores standard headers other than Content-MD5, Content-Type, and Date' do
subject.sign(verb, uri, headers.merge({'Content-Encoding' => 'foo'})).must_equal 'account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE='
end
it 'throws IndexError when there is no Date header' do
assert_raises IndexError do
subject.sign(verb, uri, headers_without_date)
end
end
end
end

Просмотреть файл

@ -1,58 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
require 'azure/core/auth/shared_key'
describe Azure::Core::Auth::SharedKey do
subject { Azure::Core::Auth::SharedKey.new 'account-name', 'YWNjZXNzLWtleQ==' }
let(:verb) { 'POST' }
let(:uri) { URI.parse 'http://dummy.uri/resource' }
let(:headers) do
{
'Content-Encoding' => 'foo',
'Content-Language' => 'foo',
'Content-Length' => 'foo',
'Content-MD5' => 'foo',
'Content-Type' => 'foo',
'Date' => 'foo',
'If-Modified-Since' => 'foo',
'If-Match' => 'foo',
'If-None-Match' => 'foo',
'If-Unmodified-Since' => 'foo',
'Range' => 'foo',
'x-ms-ImATeapot' => 'teapot',
'x-ms-ShortAndStout' => 'True'
}
end
describe 'sign' do
it 'creates a signature from the provided HTTP method, uri, and a specific set of standard headers' do
subject.sign(verb, uri, headers).must_equal 'account-name:vcdxlDVoE1QvJerkg0ci3Wlnj2Qq8yzlsrkRf5dEU/I='
end
end
describe 'canonicalized_headers' do
it 'creates a canonicalized header string' do
subject.canonicalized_headers(headers).must_equal "x-ms-imateapot:teapot\nx-ms-shortandstout:True"
end
end
describe 'canonicalized_resource' do
it 'creates a canonicalized resource string' do
subject.canonicalized_resource(uri).must_equal '/account-name/resource'
end
end
end

Просмотреть файл

@ -1,30 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "test_helper"
require "azure/core/auth/signer"
describe Azure::Core::Auth::Signer do
subject { Azure::Core::Auth::Signer.new "YWNjZXNzLWtleQ==" }
it "decodes the base64 encoded access_key" do
subject.access_key.must_equal "access-key"
end
describe "sign" do
it "creates a signature for the body, as a base64 encoded string, which represents a HMAC hash using the access_key" do
subject.sign("body").must_equal "iuUxVhs1E7PeSNx/90ViyJNO24160qYpoWeCcOsnMoM="
end
end
end

Просмотреть файл

@ -1,61 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
require 'azure/core/http/http_error'
describe Azure::Core::Http::HTTPError do
let :http_response do
stub(body: Fixtures[:http_error], status_code: 409, uri: 'http://dummy.uri', headers: {})
end
subject do
Azure::Core::Http::HTTPError.new(http_response)
end
it 'is an instance of Azure::Core::Error' do
subject.must_be_kind_of Azure::Core::Error
end
it 'lets us see the original uri' do
subject.uri.must_equal 'http://dummy.uri'
end
it "lets us see the errors'status code" do
subject.status_code.must_equal 409
end
it "lets us see the error's type" do
subject.type.must_equal 'TableAlreadyExists'
end
it "lets us see the error's description" do
subject.description.must_equal 'The table specified already exists.'
end
it 'generates an error message that wraps both the type and description' do
subject.message.must_equal 'TableAlreadyExists (409): The table specified already exists.'
end
describe 'with invalid http_response body' do
let :http_response do
stub(:body => "\r\nInvalid request\r\n", :status_code => 409, :uri => 'http://dummy.uri', headers: {})
end
it 'sets the type to unknown if the response body is not an XML' do
subject.type.must_equal 'Unknown'
subject.description.must_equal 'Invalid request'
end
end
end

Просмотреть файл

@ -1,138 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
require 'azure/core/http/http_request'
describe Azure::Core::Http::HttpRequest do
let(:uri) { URI('http://example.com') }
describe ' default_headers ' do
subject do
Azure::Core::Http::HttpRequest.new(:get, uri, body: nil, current_time: 'Thu, 04 Oct 2012 06:38:27 GMT')
end
it 'sets the x-ms-date header to the current_time' do
subject.headers['x-ms-date'] = 'Thu, 04 Oct 2012 06:38:27 GMT'
end
it 'sets the x-ms-version header to the current API version' do
subject.headers['x-ms-version'] = '2011-08-18'
end
it 'sets the DataServiceVersion header to the current API version' do
subject.headers['DataServiceVersion'] = '1.0;NetFx'
end
it 'sets the MaxDataServiceVersion header to the current max` API version' do
subject.headers['MaxDataServiceVersion'] = '2.0;NetFx'
end
end
describe 'when passed custom headers' do
subject do
Azure::Core::Http::HttpRequest.new(:get,
uri,
body: nil,
headers: {
'blah' => 'something',
'x-ms-version' => '123'
})
end
it 'should have overridden the value of x-ms-version' do
subject.headers['x-ms-version'].must_equal '123'
end
it 'should have added in the blah = something header' do
subject.headers['blah'].must_equal 'something'
end
end
describe ' when passed a body ' do
subject do
Azure::Core::Http::HttpRequest.new(:post, uri, body: '<body/>')
end
it 'sets the default Content-Type header' do
subject.headers['Content-Type'].must_equal 'application/atom+xml; charset=utf-8'
end
it 'sets the Content-Length header' do
subject.headers['Content-Length'].must_equal '7'
end
it 'sets the Content-MD5 header to a Base64 encoded representation of the MD5 hash of the body' do
subject.headers['Content-MD5'].must_equal 'PNeJy7qyzV4XUoBBHkVu0g=='
end
end
describe ' when the body is nil ' do
subject do
Azure::Core::Http::HttpRequest.new(:get, uri)
end
it 'leaves the Content-Type, Content-Length, and Content-MD5 headers blank' do
subject.headers['Content-Length'].must_equal '0'
subject.headers['Content-MD5'].must_be_nil
end
end
describe '#call' do
let(:mock_conn) do
conn = mock
conn.expects(:run_request, [uri, nil, nil]).returns(mock_res)
conn
end
subject do
sub = Azure::Core::Http::HttpRequest.new(:get, uri)
sub.expects(:http_setup).returns(mock_conn)
sub
end
describe 'on success' do
let(:body) { '</body>' }
let(:mock_res) do
res = mock
res.expects(:success?).returns(true)
res.expects(:body).returns(body)
res
end
it 'should return a response' do
subject.call.body.must_equal(body)
end
end
describe 'on failure' do
let(:body) { 'OH NO!!' }
let(:mock_res) do
res = mock
res.expects(:success?).returns(false).at_least_once
res.expects(:status).returns(401).at_least_once
res.expects(:body).returns(body).at_least_once
res
end
it 'should return a response' do
-> { subject.call }.must_raise(Azure::Core::Http::HTTPError)
end
end
end
end

Просмотреть файл

@ -1,20 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
require 'azure/core/http/http_response'
describe Azure::Core::Http::HttpResponse do
# TODO: fill in with better tests.
end

Просмотреть файл

@ -1,23 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
require 'azure/core/http/retry_policy'
describe Azure::Core::Http::RetryPolicy do
it 'uses blocks as retry logic' do
retry_policy = Azure::Core::Http::RetryPolicy.new do |a,b| true end
retry_policy.should_retry?(nil, nil).must_equal true
end
end

Просмотреть файл

@ -1,122 +0,0 @@
#-------------------------------------------------------------------------
# # Copyright (c) Microsoft and contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require 'test_helper'
describe Azure::Core::Logger do
subject { Azure::Core::Logger }
let(:msg) { "message" }
after {
subject.initialize_external_logger(nil)
}
describe "Log without external logger" do
before {
subject.initialize_external_logger(nil)
}
it "#info" do
out, err = capture_io { subject.info(msg) }
assert_equal("\e[37m\e[1m" + msg + "\e[0m\e[0m\n", out)
end
it "#error_with_exit" do
out, err = capture_io do
error = assert_raises(RuntimeError) do
subject.error_with_exit(msg)
end
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m", error.message)
end
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m\n", out)
end
it "#warn" do
out, err = capture_io do
warn = subject.warn(msg)
assert_equal(msg, warn)
end
assert_equal("\e[33m" + msg + "\e[0m\n", out)
end
it "#error" do
out, err = capture_io do
error = subject.error(msg)
assert_equal(msg, error)
end
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m\n", out)
end
it "#exception_message" do
out, err = capture_io do
exception = assert_raises(RuntimeError) do
subject.exception_message(msg)
end
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m", exception.message)
end
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m\n", out)
end
it "#success" do
out, err = capture_io { subject.success(msg) }
assert_equal("\e[32m" + msg + "\n\e[0m", out)
end
end
describe "Log with external logger" do
let(:fake_output) { StringIO.new }
before {
subject.initialize_external_logger(Logger.new(fake_output))
}
it "#info" do
subject.info(msg)
assert_match(/INFO -- : #{msg}\n/, fake_output.string)
end
it "#error_with_exit" do
error = assert_raises(RuntimeError) do
subject.error_with_exit(msg)
end
assert_match(/ERROR -- : #{msg}\n/, fake_output.string)
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m", error.message)
end
it "#warn" do
warn = subject.warn(msg)
assert_match(/WARN -- : #{msg}\n/, fake_output.string)
assert_equal(msg, warn)
end
it "#error" do
error = subject.error(msg)
assert_match(/ERROR -- : #{msg}\n/, fake_output.string)
assert_equal(msg, error)
end
it "#exception_message" do
exception = assert_raises(RuntimeError) do
subject.exception_message(msg)
end
assert_match(/WARN -- : #{msg}\n/, fake_output.string)
assert_equal("\e[31m\e[1m" + msg + "\e[0m\e[0m", exception.message)
end
it "#success" do
subject.success(msg)
assert_match(/INFO -- : #{msg}\n/, fake_output.string)
end
end
end