fog-core 2.1.0 → 2.6.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.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +2 -0
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/ci.yml +32 -0
- data/.rubocop.yml +16 -12
- data/.rubocop_todo.yml +724 -0
- data/CONTRIBUTING.md +5 -1
- data/Gemfile +1 -1
- data/README.md +2 -1
- data/Rakefile +2 -14
- data/SECURITY.md +6 -0
- data/changelog.md +241 -141
- data/fog-core.gemspec +13 -9
- data/lib/fog/account.rb +0 -16
- data/lib/fog/billing.rb +0 -11
- data/lib/fog/compute/models/server.rb +7 -3
- data/lib/fog/compute.rb +3 -25
- data/lib/fog/core/association.rb +1 -0
- data/lib/fog/core/attributes/default.rb +7 -0
- data/lib/fog/core/attributes.rb +42 -5
- data/lib/fog/core/cache.rb +58 -55
- data/lib/fog/core/collection.rb +9 -3
- data/lib/fog/core/connection.rb +4 -6
- data/lib/fog/core/current_machine.rb +1 -1
- data/lib/fog/core/errors.rb +1 -1
- data/lib/fog/core/logger.rb +5 -2
- data/lib/fog/core/mock.rb +7 -2
- data/lib/fog/core/model.rb +34 -5
- data/lib/fog/core/provider.rb +37 -4
- data/lib/fog/core/scp.rb +16 -11
- data/lib/fog/core/service.rb +5 -5
- data/lib/fog/core/services_mixin.rb +62 -10
- data/lib/fog/core/ssh.rb +49 -25
- data/lib/fog/core/stringify_keys.rb +0 -2
- data/lib/fog/core/time.rb +2 -2
- data/lib/fog/core/uuid.rb +2 -8
- data/lib/fog/core/version.rb +3 -1
- data/lib/fog/core/wait_for.rb +2 -1
- data/lib/fog/core/wait_for_defaults.rb +2 -0
- data/lib/fog/core.rb +57 -59
- data/lib/fog/dns.rb +0 -11
- data/lib/fog/formatador.rb +9 -8
- data/lib/fog/monitoring.rb +0 -11
- data/lib/fog/network.rb +0 -12
- data/lib/fog/schema/data_validator.rb +1 -0
- data/lib/fog/storage.rb +15 -30
- data/lib/fog/support.rb +0 -12
- data/lib/fog/test_helpers/collection_helper.rb +2 -0
- data/lib/fog/test_helpers/formats_helper.rb +2 -2
- data/lib/fog/test_helpers/helper.rb +3 -3
- data/lib/fog/test_helpers/minitest/assertions.rb +1 -1
- data/lib/fog/test_helpers/minitest/expectations.rb +1 -1
- data/lib/fog/test_helpers/mock_helper.rb +84 -84
- data/lib/fog/test_helpers/succeeds_helper.rb +2 -2
- data/lib/fog/test_helpers/types_helper.rb +1 -0
- data/lib/fog/vpn.rb +0 -12
- data/lib/tasks/test_task.rb +4 -5
- metadata +58 -85
- data/.travis.yml +0 -39
- data/spec/compute/models/server_spec.rb +0 -229
- data/spec/compute_spec.rb +0 -95
- data/spec/connection_spec.rb +0 -105
- data/spec/core/cache_spec.rb +0 -191
- data/spec/core/model_spec.rb +0 -36
- data/spec/core/stringify_keys_spec.rb +0 -38
- data/spec/core/whitelist_keys_spec.rb +0 -36
- data/spec/credentials_spec.rb +0 -88
- data/spec/current_machine_spec.rb +0 -36
- data/spec/fake_app/fake_service.rb +0 -18
- data/spec/fake_app/models/collection.rb +0 -5
- data/spec/fake_app/models/model.rb +0 -2
- data/spec/fake_app/requests/request.rb +0 -11
- data/spec/fog_attribute_spec.rb +0 -549
- data/spec/formatador_spec.rb +0 -154
- data/spec/identity_spec.rb +0 -95
- data/spec/mocking_spec.rb +0 -84
- data/spec/service_spec.rb +0 -201
- data/spec/spec_helper.rb +0 -19
- data/spec/storage_spec.rb +0 -114
- data/spec/test_helpers/formats_helper_spec.rb +0 -121
- data/spec/test_helpers/schema_validator_spec.rb +0 -101
- data/spec/timeout_spec.rb +0 -20
- data/spec/utils_spec.rb +0 -29
- data/spec/uuid_spec.rb +0 -11
- data/spec/wait_for_spec.rb +0 -30
data/spec/identity_spec.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Fog
|
4
|
-
module Identity
|
5
|
-
def self.require(*_args); end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "Fog::Identity" do
|
10
|
-
describe "#new" do
|
11
|
-
module Fog
|
12
|
-
module TheRightWay
|
13
|
-
extend Provider
|
14
|
-
service(:identity, "Identity")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Fog
|
19
|
-
module Identity
|
20
|
-
class TheRightWay
|
21
|
-
def initialize(_args); end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "instantiates an instance of Fog::Identity::<Provider> from the :provider keyword arg" do
|
27
|
-
identity = Fog::Identity.new(:provider => :therightway)
|
28
|
-
assert_instance_of(Fog::Identity::TheRightWay, identity)
|
29
|
-
end
|
30
|
-
|
31
|
-
module Fog
|
32
|
-
module Rackspace
|
33
|
-
extend Provider
|
34
|
-
service(:identity, "Identity")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module Fog
|
39
|
-
module Rackspace
|
40
|
-
class Identity
|
41
|
-
def initialize(_args); end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "instantiates an instance of Fog::<Provider>::Identity from the :provider keyword arg" do
|
47
|
-
identity = Fog::Identity.new(:provider => :rackspace)
|
48
|
-
assert_instance_of(Fog::Rackspace::Identity, identity)
|
49
|
-
end
|
50
|
-
|
51
|
-
module Fog
|
52
|
-
module BothWays
|
53
|
-
extend Provider
|
54
|
-
service(:identity, "Identity")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module Fog
|
59
|
-
module BothWays
|
60
|
-
class Identity
|
61
|
-
def initialize(_args); end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
module Fog
|
67
|
-
module Identity
|
68
|
-
class BothWays
|
69
|
-
attr_reader :args
|
70
|
-
def initialize(args)
|
71
|
-
@args = args
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "when both Fog::Identity::<Provider> and Fog::<Provider>::Identity exist" do
|
78
|
-
it "prefers Fog::Identity::<Provider>" do
|
79
|
-
identity = Fog::Identity.new(:provider => :bothways)
|
80
|
-
assert_instance_of(Fog::Identity::BothWays, identity)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it "passes the supplied keyword args less :provider to Fog::Identity::<Provider>#new" do
|
85
|
-
identity = Fog::Identity.new(:provider => :bothways, :extra => :stuff)
|
86
|
-
assert_equal({ :extra => :stuff }, identity.args)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "raises ArgumentError when given a :provider where a Fog::Identity::Provider that does not exist" do
|
90
|
-
assert_raises(ArgumentError) do
|
91
|
-
Fog::Identity.new(:provider => :wat)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
data/spec/mocking_spec.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Fog mocking" do
|
4
|
-
before do
|
5
|
-
@fog_was_mocked = Fog.mock?
|
6
|
-
Fog.unmock! if @fog_was_mocked
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Fog.mock! if @fog_was_mocked
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "Fog.mock!" do
|
14
|
-
it "Fog.mock! returns true" do
|
15
|
-
assert_equal true, Fog.mock!
|
16
|
-
end
|
17
|
-
|
18
|
-
it "Fog.mock? without Fog.mock! returns false" do
|
19
|
-
assert_equal false, Fog.mock?
|
20
|
-
end
|
21
|
-
|
22
|
-
it "Fog.mock? with Fog.mock!" do
|
23
|
-
Fog.mock!
|
24
|
-
assert_equal true, Fog.mock?
|
25
|
-
end
|
26
|
-
|
27
|
-
it "Fog.mocking? without Fog.mock!" do
|
28
|
-
assert_equal false, Fog.mocking?
|
29
|
-
end
|
30
|
-
|
31
|
-
it "Fog.mocking? with Fog.mock!" do
|
32
|
-
Fog.mock!
|
33
|
-
assert_equal true, Fog.mocking?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "Fog::Mock.delay" do
|
38
|
-
it "Fog::Mock.delay defaults to 0" do
|
39
|
-
assert_equal 1, Fog::Mock.delay
|
40
|
-
end
|
41
|
-
|
42
|
-
it "handles reassignment" do
|
43
|
-
Fog::Mock.delay = 2
|
44
|
-
assert_equal 2, Fog::Mock.delay
|
45
|
-
|
46
|
-
Fog::Mock.delay = 1
|
47
|
-
assert_equal 1, Fog::Mock.delay
|
48
|
-
end
|
49
|
-
|
50
|
-
it "raises when given an illegal delay" do
|
51
|
-
assert_raises(ArgumentError) do
|
52
|
-
Fog::Mock.delay = -1
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "Fog::Mock.random_ip" do
|
58
|
-
it "defaults to ipv4" do
|
59
|
-
assert IPAddr.new(Fog::Mock.random_ip).ipv4?
|
60
|
-
end
|
61
|
-
|
62
|
-
it "supports explicit request for v4" do
|
63
|
-
assert IPAddr.new(Fog::Mock.random_ip(:version => :v4)).ipv4?
|
64
|
-
end
|
65
|
-
|
66
|
-
it "supports explicit request for v6" do
|
67
|
-
assert IPAddr.new(Fog::Mock.random_ip(:version => :v6)).ipv6?
|
68
|
-
end
|
69
|
-
|
70
|
-
it "raises when supplied an illegal IP version" do
|
71
|
-
assert_raises(ArgumentError) do
|
72
|
-
IPAddr.new(Fog::Mock.random_ip(:version => :v5)).ipv4?
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "Fog::Mock.not_implemented" do
|
78
|
-
it "raises MockNotImplemented when called" do
|
79
|
-
assert_raises(Fog::Errors::MockNotImplemented) do
|
80
|
-
Fog::Mock.not_implemented
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/spec/service_spec.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Fog::Service do
|
4
|
-
class TestService < Fog::Service
|
5
|
-
requires :generic_api_key
|
6
|
-
recognizes :generic_user
|
7
|
-
|
8
|
-
class Real
|
9
|
-
attr_reader :options
|
10
|
-
|
11
|
-
def initialize(opts = {})
|
12
|
-
@options = opts
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Mock
|
17
|
-
attr_reader :options
|
18
|
-
|
19
|
-
def initialize(opts = {})
|
20
|
-
@options = opts
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class ChildOfTestService < TestService
|
26
|
-
class Real; def initialize(*_args); end; end
|
27
|
-
class Mock; def initialize(*_args); end; end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "properly passes headers" do
|
31
|
-
user_agent_hash = {
|
32
|
-
"User-Agent" => "Generic Fog Client"
|
33
|
-
}
|
34
|
-
params = {
|
35
|
-
:generic_user => "bob",
|
36
|
-
:generic_api_key => "1234",
|
37
|
-
:connection_options => {
|
38
|
-
:headers => user_agent_hash
|
39
|
-
}
|
40
|
-
}
|
41
|
-
service = TestService.new(params)
|
42
|
-
|
43
|
-
assert_equal user_agent_hash, service.options[:connection_options][:headers]
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "when created with a Hash" do
|
47
|
-
it "raises for required argument that are missing" do
|
48
|
-
assert_raises(ArgumentError) { TestService.new({}) }
|
49
|
-
end
|
50
|
-
|
51
|
-
it "converts String keys to be Symbols" do
|
52
|
-
service = TestService.new "generic_api_key" => "abc"
|
53
|
-
assert_includes service.options.keys, :generic_api_key
|
54
|
-
end
|
55
|
-
|
56
|
-
it "removes keys with `nil` values" do
|
57
|
-
service = TestService.new :generic_api_key => "abc", :generic_user => nil
|
58
|
-
refute_includes service.options.keys, :generic_user
|
59
|
-
end
|
60
|
-
|
61
|
-
it "converts number String values with to_i" do
|
62
|
-
service = TestService.new :generic_api_key => "3421"
|
63
|
-
assert_equal 3421, service.options[:generic_api_key]
|
64
|
-
end
|
65
|
-
|
66
|
-
it "converts 'true' String values to TrueClass" do
|
67
|
-
service = TestService.new :generic_api_key => "true"
|
68
|
-
assert_equal true, service.options[:generic_api_key]
|
69
|
-
end
|
70
|
-
|
71
|
-
it "converts 'false' String values to FalseClass" do
|
72
|
-
service = TestService.new :generic_api_key => "false"
|
73
|
-
assert_equal false, service.options[:generic_api_key]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "warns for unrecognised options" do
|
77
|
-
bad_options = { :generic_api_key => "abc", :bad_option => "bad value" }
|
78
|
-
logger = Minitest::Mock.new
|
79
|
-
logger.expect :warning, nil, ["Unrecognized arguments: bad_option"]
|
80
|
-
Fog.stub_const :Logger, logger do
|
81
|
-
TestService.new(bad_options)
|
82
|
-
end
|
83
|
-
logger.verify
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "when creating and mocking is disabled" do
|
88
|
-
it "returns the real service" do
|
89
|
-
Fog.stub :mocking?, false do
|
90
|
-
service = TestService.new(:generic_api_key => "abc")
|
91
|
-
service.must_be_instance_of TestService::Real
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it "TestService::Real has TestService::Collections mixed into the mocked service" do
|
96
|
-
Fog.stub :mocking?, false do
|
97
|
-
service = TestService.new(:generic_api_key => "abc")
|
98
|
-
assert_includes(service.class.ancestors, TestService::Collections)
|
99
|
-
assert_includes(service.class.ancestors, Fog::Service::Collections)
|
100
|
-
refute_includes(service.class.ancestors, ChildOfTestService::Collections)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it "ChildOfTestService::Real has ChildOfTestService::Collections and TestService::Collections mixed in" do
|
105
|
-
Fog.stub :mocking?, true do
|
106
|
-
service = ChildOfTestService.new
|
107
|
-
assert_includes(service.class.ancestors, Fog::Service::Collections)
|
108
|
-
assert_includes(service.class.ancestors, TestService::Collections)
|
109
|
-
assert_includes(service.class.ancestors, ChildOfTestService::Collections)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "when creating and mocking is enabled" do
|
115
|
-
it "returns mocked service" do
|
116
|
-
Fog.stub :mocking?, true do
|
117
|
-
service = TestService.new(:generic_api_key => "abc")
|
118
|
-
service.must_be_instance_of TestService::Mock
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it "TestService::Mock has TestService::Collections mixed into the mocked service" do
|
123
|
-
Fog.stub :mocking?, true do
|
124
|
-
service = TestService.new(:generic_api_key => "abc")
|
125
|
-
assert_includes(service.class.ancestors, Fog::Service::Collections)
|
126
|
-
assert_includes(service.class.ancestors, TestService::Collections)
|
127
|
-
refute_includes(service.class.ancestors, ChildOfTestService::Collections)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
it "ChildOfTestService::Mock has ChildOfTestService::Collections and TestService::Collections mixed in" do
|
132
|
-
Fog.stub :mocking?, true do
|
133
|
-
service = ChildOfTestService.new
|
134
|
-
assert_includes(service.class.ancestors, Fog::Service::Collections)
|
135
|
-
assert_includes(service.class.ancestors, TestService::Collections)
|
136
|
-
assert_includes(service.class.ancestors, ChildOfTestService::Collections)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "when no credentials are provided" do
|
142
|
-
it "uses the global values" do
|
143
|
-
@global_credentials = {
|
144
|
-
:generic_user => "fog",
|
145
|
-
:generic_api_key => "fog"
|
146
|
-
}
|
147
|
-
|
148
|
-
Fog.stub :credentials, @global_credentials do
|
149
|
-
@service = TestService.new
|
150
|
-
assert_equal @service.options, @global_credentials
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "when credentials are provided as settings" do
|
156
|
-
it "merges the global values into settings" do
|
157
|
-
@settings = {
|
158
|
-
:generic_user => "fog"
|
159
|
-
}
|
160
|
-
@global_credentials = {
|
161
|
-
:generic_user => "bob",
|
162
|
-
:generic_api_key => "fog"
|
163
|
-
}
|
164
|
-
|
165
|
-
Fog.stub :credentials, @global_credentials do
|
166
|
-
@service = TestService.new(@settings)
|
167
|
-
assert_equal @service.options[:generic_user], "fog"
|
168
|
-
assert_equal @service.options[:generic_api_key], "fog"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "when config object can configure the service itself" do
|
174
|
-
it "ignores the global and its values" do
|
175
|
-
@config = MiniTest::Mock.new
|
176
|
-
def @config.config_service?; true; end
|
177
|
-
def @config.nil?; false; end
|
178
|
-
def @config.==(other); object_id == other.object_id; end
|
179
|
-
|
180
|
-
unexpected_usage = lambda { raise "Accessing global!" }
|
181
|
-
Fog.stub :credentials, unexpected_usage do
|
182
|
-
@service = TestService.new(@config)
|
183
|
-
assert_equal @config, @service.options
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "#setup_requirements" do
|
189
|
-
before :each do
|
190
|
-
@service = FakeService.new
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should require collections" do
|
194
|
-
assert @service.respond_to?(:collection)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should mock" do
|
198
|
-
assert_includes @service.mocked_requests, :request
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
if ENV["COVERAGE"]
|
2
|
-
require "coveralls"
|
3
|
-
require "simplecov"
|
4
|
-
|
5
|
-
SimpleCov.start do
|
6
|
-
add_filter "/spec/"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
require "minitest/autorun"
|
11
|
-
require "minitest/spec"
|
12
|
-
require "minitest/stub_const"
|
13
|
-
|
14
|
-
$LOAD_PATH.unshift "lib"
|
15
|
-
require "fog/core"
|
16
|
-
|
17
|
-
Dir["spec/fake_app/**/*.rb"].each do |file|
|
18
|
-
require File.join(File.dirname(__FILE__), "..", file)
|
19
|
-
end
|
data/spec/storage_spec.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Fog
|
4
|
-
module Storage
|
5
|
-
def self.require(*_args); end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "Fog::Storage" do
|
10
|
-
describe "#new" do
|
11
|
-
module Fog
|
12
|
-
module TheRightWay
|
13
|
-
extend Provider
|
14
|
-
service(:storage, "Storage")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Fog
|
19
|
-
module Storage
|
20
|
-
class TheRightWay
|
21
|
-
def initialize(_args); end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "instantiates an instance of Fog::Storage::<Provider> from the :provider keyword arg" do
|
27
|
-
compute = Fog::Storage.new(:provider => :therightway)
|
28
|
-
assert_instance_of(Fog::Storage::TheRightWay, compute)
|
29
|
-
end
|
30
|
-
|
31
|
-
module Fog
|
32
|
-
module TheWrongWay
|
33
|
-
extend Provider
|
34
|
-
service(:storage, "Storage")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module Fog
|
39
|
-
module TheWrongWay
|
40
|
-
class Storage
|
41
|
-
def initialize(_args); end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "instantiates an instance of Fog::<Provider>::Storage from the :provider keyword arg" do
|
47
|
-
compute = Fog::Storage.new(:provider => :thewrongway)
|
48
|
-
assert_instance_of(Fog::TheWrongWay::Storage, compute)
|
49
|
-
end
|
50
|
-
|
51
|
-
module Fog
|
52
|
-
module BothWays
|
53
|
-
extend Provider
|
54
|
-
service(:storage, "Storage")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module Fog
|
59
|
-
module BothWays
|
60
|
-
class Storage
|
61
|
-
def initialize(_args); end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
module Fog
|
67
|
-
module Storage
|
68
|
-
class BothWays
|
69
|
-
attr_reader :args
|
70
|
-
|
71
|
-
def initialize(args)
|
72
|
-
@args = args
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "when both Fog::Storage::<Provider> and Fog::<Provider>::Storage exist" do
|
79
|
-
it "prefers Fog::Storage::<Provider>" do
|
80
|
-
compute = Fog::Storage.new(:provider => :bothways)
|
81
|
-
assert_instance_of(Fog::Storage::BothWays, compute)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it "passes the supplied keyword args less :provider to Fog::Storage::<Provider>#new" do
|
86
|
-
compute = Fog::Storage.new(:provider => :bothways, :extra => :stuff)
|
87
|
-
assert_equal({ :extra => :stuff }, compute.args)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "raises ArgumentError when given a :provider where a Fog::Storage::Provider that does not exist" do
|
91
|
-
assert_raises(ArgumentError) do
|
92
|
-
Fog::Storage.new(:provider => :wat)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe ".get_body_size" do
|
98
|
-
it "doesn't alter the encoding of the string passed to it" do
|
99
|
-
body = "foo".encode("UTF-8")
|
100
|
-
Fog::Storage.get_body_size(body)
|
101
|
-
|
102
|
-
assert_equal("UTF-8", body.encoding.to_s)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "respects frozen strings" do
|
106
|
-
if RUBY_VERSION >= "2.3.0"
|
107
|
-
body = "foo".freeze
|
108
|
-
Fog::Storage.get_body_size(body)
|
109
|
-
else
|
110
|
-
skip
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "fog/test_helpers/formats_helper"
|
3
|
-
require "fog/test_helpers/types_helper"
|
4
|
-
|
5
|
-
module Shindo
|
6
|
-
class Tests
|
7
|
-
def test(_str, &_block)
|
8
|
-
yield
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "formats_helper" do
|
14
|
-
let(:shindo) { Shindo::Tests.new }
|
15
|
-
|
16
|
-
it "comparing welcome data against schema" do
|
17
|
-
data = { :welcome => "Hello" }
|
18
|
-
assert shindo.data_matches_schema(:welcome => String) { data }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#data_matches_schema" do
|
22
|
-
it "when value matches schema expectation" do
|
23
|
-
assert shindo.data_matches_schema("key" => String) { { "key" => "Value" } }
|
24
|
-
end
|
25
|
-
|
26
|
-
it "when values within an array all match schema expectation" do
|
27
|
-
assert shindo.data_matches_schema("key" => [Integer]) { { "key" => [1, 2] } }
|
28
|
-
end
|
29
|
-
|
30
|
-
it "when nested values match schema expectation" do
|
31
|
-
assert shindo.data_matches_schema("key" => { :nested_key => String }) { { "key" => { :nested_key => "Value" } } }
|
32
|
-
end
|
33
|
-
|
34
|
-
it "when collection of values all match schema expectation" do
|
35
|
-
assert shindo.data_matches_schema([{ "key" => String }]) { [{ "key" => "Value" }, { "key" => "Value" }] }
|
36
|
-
end
|
37
|
-
|
38
|
-
it "when collection is empty although schema covers optional members" do
|
39
|
-
assert shindo.data_matches_schema([{ "key" => String }], :allow_optional_rules => true) { [] }
|
40
|
-
end
|
41
|
-
|
42
|
-
it "when additional keys are passed and not strict" do
|
43
|
-
assert shindo.data_matches_schema({ "key" => String }, { :allow_extra_keys => true }) { { "key" => "Value", :extra => "Bonus" } }
|
44
|
-
end
|
45
|
-
|
46
|
-
it "when value is nil and schema expects NilClass" do
|
47
|
-
assert shindo.data_matches_schema("key" => NilClass) { { "key" => nil } }
|
48
|
-
end
|
49
|
-
|
50
|
-
it "when value and schema match as hashes" do
|
51
|
-
assert shindo.data_matches_schema({}) { {} }
|
52
|
-
end
|
53
|
-
|
54
|
-
it "when value and schema match as arrays" do
|
55
|
-
assert shindo.data_matches_schema([]) { [] }
|
56
|
-
end
|
57
|
-
|
58
|
-
it "when value is a Time" do
|
59
|
-
assert shindo.data_matches_schema("time" => Time) { { "time" => Time.now } }
|
60
|
-
end
|
61
|
-
|
62
|
-
it "when key is missing but value should be NilClass (#1477)" do
|
63
|
-
assert shindo.data_matches_schema({ "key" => NilClass }, { :allow_optional_rules => true }) { {} }
|
64
|
-
end
|
65
|
-
|
66
|
-
it "when key is missing but value is nullable (#1477)" do
|
67
|
-
assert shindo.data_matches_schema({ "key" => Fog::Nullable::String }, { :allow_optional_rules => true }) { {} }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#formats backwards compatible changes" do
|
72
|
-
|
73
|
-
it "when value matches schema expectation" do
|
74
|
-
assert shindo.formats("key" => String) { { "key" => "Value" } }
|
75
|
-
end
|
76
|
-
|
77
|
-
it "when values within an array all match schema expectation" do
|
78
|
-
assert shindo.formats("key" => [Integer]) { { "key" => [1, 2] } }
|
79
|
-
end
|
80
|
-
|
81
|
-
it "when nested values match schema expectation" do
|
82
|
-
assert shindo.formats("key" => { :nested_key => String }) { { "key" => { :nested_key => "Value" } } }
|
83
|
-
end
|
84
|
-
|
85
|
-
it "when collection of values all match schema expectation" do
|
86
|
-
assert shindo.formats([{ "key" => String }]) { [{ "key" => "Value" }, { "key" => "Value" }] }
|
87
|
-
end
|
88
|
-
|
89
|
-
it "when collection is empty although schema covers optional members" do
|
90
|
-
assert shindo.formats([{ "key" => String }]) { [] }
|
91
|
-
end
|
92
|
-
|
93
|
-
it "when additional keys are passed and not strict" do
|
94
|
-
assert shindo.formats({ "key" => String }, false) { { "key" => "Value", :extra => "Bonus" } }
|
95
|
-
end
|
96
|
-
|
97
|
-
it "when value is nil and schema expects NilClass" do
|
98
|
-
assert shindo.formats("key" => NilClass) { { "key" => nil } }
|
99
|
-
end
|
100
|
-
|
101
|
-
it "when value and schema match as hashes" do
|
102
|
-
assert shindo.formats({}) { {} }
|
103
|
-
end
|
104
|
-
|
105
|
-
it "when value and schema match as arrays" do
|
106
|
-
assert shindo.formats([]) { [] }
|
107
|
-
end
|
108
|
-
|
109
|
-
it "when value is a Time" do
|
110
|
-
assert shindo.formats("time" => Time) { { "time" => Time.now } }
|
111
|
-
end
|
112
|
-
|
113
|
-
it "when key is missing but value should be NilClass (#1477)" do
|
114
|
-
assert shindo.formats("key" => NilClass) { {} }
|
115
|
-
end
|
116
|
-
|
117
|
-
it "when key is missing but value is nullable (#1477)" do
|
118
|
-
assert shindo.formats("key" => Fog::Nullable::String) { {} }
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|