fog-core 2.3.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +2 -0
- data/.github/dependabot.yml +2 -2
- data/.github/workflows/ci.yml +32 -0
- data/.rubocop.yml +16 -12
- data/.rubocop_todo.yml +724 -0
- data/Gemfile +1 -1
- data/README.md +2 -1
- data/Rakefile +2 -14
- data/SECURITY.md +6 -0
- data/changelog.md +26 -0
- data/fog-core.gemspec +11 -8
- data/lib/fog/compute/models/server.rb +7 -3
- data/lib/fog/compute.rb +3 -3
- data/lib/fog/core/association.rb +1 -0
- data/lib/fog/core/attributes/default.rb +7 -0
- data/lib/fog/core/attributes.rb +28 -3
- data/lib/fog/core/cache.rb +58 -55
- data/lib/fog/core/collection.rb +9 -3
- data/lib/fog/core/connection.rb +1 -1
- data/lib/fog/core/current_machine.rb +1 -1
- data/lib/fog/core/errors.rb +1 -1
- data/lib/fog/core/logger.rb +2 -2
- data/lib/fog/core/mock.rb +7 -2
- data/lib/fog/core/model.rb +34 -5
- data/lib/fog/core/provider.rb +7 -7
- data/lib/fog/core/scp.rb +15 -11
- data/lib/fog/core/service.rb +5 -5
- data/lib/fog/core/services_mixin.rb +9 -9
- data/lib/fog/core/ssh.rb +3 -2
- 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 +1 -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/formatador.rb +9 -8
- data/lib/fog/schema/data_validator.rb +1 -0
- data/lib/fog/storage.rb +15 -16
- 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/types_helper.rb +1 -0
- data/lib/tasks/test_task.rb +4 -5
- metadata +46 -81
- data/.github/workflows/ruby.yml +0 -18
- data/.github/workflows/stale.yml +0 -9
- 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 -112
- 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
|
-
class Identity
|
14
|
-
def initialize(_args); end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module Fog
|
20
|
-
module TheRightWay
|
21
|
-
extend Provider
|
22
|
-
service(:identity, "Identity")
|
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::TheRightWay::Identity, identity)
|
29
|
-
end
|
30
|
-
|
31
|
-
module Fog
|
32
|
-
module Identity
|
33
|
-
class TheWrongWay
|
34
|
-
def initialize(_args); end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Fog
|
40
|
-
module TheWrongWay
|
41
|
-
extend Provider
|
42
|
-
service(:identity, "Identity")
|
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 => :thewrongway)
|
48
|
-
assert_instance_of(Fog::Identity::TheWrongWay, identity)
|
49
|
-
end
|
50
|
-
|
51
|
-
module Fog
|
52
|
-
module BothWays
|
53
|
-
class Identity
|
54
|
-
attr_reader :args
|
55
|
-
def initialize(args)
|
56
|
-
@args = args
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
module Fog
|
63
|
-
module Identity
|
64
|
-
class BothWays
|
65
|
-
def initialize(_args); end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
module Fog
|
71
|
-
module BothWays
|
72
|
-
extend Provider
|
73
|
-
service(:identity, "Identity")
|
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::BothWays::Identity, 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,112 +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
|
-
class Storage
|
14
|
-
def initialize(_args); end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module Fog
|
20
|
-
module TheRightWay
|
21
|
-
extend Provider
|
22
|
-
service(:storage, "Storage")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "instantiates an instance of Fog::<Provider>::Storage from the :provider keyword arg" do
|
27
|
-
compute = Fog::Storage.new(:provider => :therightway)
|
28
|
-
assert_instance_of(Fog::TheRightWay::Storage, compute)
|
29
|
-
end
|
30
|
-
|
31
|
-
module Fog
|
32
|
-
module Storage
|
33
|
-
class TheWrongWay
|
34
|
-
def initialize(_args); end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module TheWrongWay
|
39
|
-
extend Provider
|
40
|
-
service(:storage, "Storage")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it "instantiates an instance of Fog::Storage::<Provider> from the :provider keyword arg" do
|
45
|
-
compute = Fog::Storage.new(:provider => :thewrongway)
|
46
|
-
assert_instance_of(Fog::Storage::TheWrongWay, compute)
|
47
|
-
end
|
48
|
-
|
49
|
-
module Fog
|
50
|
-
module BothWays
|
51
|
-
class Storage
|
52
|
-
attr_reader :args
|
53
|
-
|
54
|
-
def initialize(args)
|
55
|
-
@args = args
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
module Fog
|
62
|
-
module Storage
|
63
|
-
class BothWays
|
64
|
-
def initialize(_args); end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
module Fog
|
70
|
-
module BothWays
|
71
|
-
extend Provider
|
72
|
-
service(:storage, "Storage")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "when both Fog::Storage::<Provider> and Fog::<Provider>::Storage exist" do
|
77
|
-
it "prefers Fog::Storage::<Provider>" do
|
78
|
-
compute = Fog::Storage.new(:provider => :bothways)
|
79
|
-
assert_instance_of(Fog::BothWays::Storage, compute)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "passes the supplied keyword args less :provider to Fog::Storage::<Provider>#new" do
|
84
|
-
compute = Fog::Storage.new(:provider => :bothways, :extra => :stuff)
|
85
|
-
assert_equal({ :extra => :stuff }, compute.args)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "raises ArgumentError when given a :provider where a Fog::Storage::Provider that does not exist" do
|
89
|
-
assert_raises(ArgumentError) do
|
90
|
-
Fog::Storage.new(:provider => :wat)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe ".get_body_size" do
|
96
|
-
it "doesn't alter the encoding of the string passed to it" do
|
97
|
-
body = "foo".encode("UTF-8")
|
98
|
-
Fog::Storage.get_body_size(body)
|
99
|
-
|
100
|
-
assert_equal("UTF-8", body.encoding.to_s)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "respects frozen strings" do
|
104
|
-
if RUBY_VERSION >= "2.3.0"
|
105
|
-
body = "foo".freeze
|
106
|
-
Fog::Storage.get_body_size(body)
|
107
|
-
else
|
108
|
-
skip
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
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
|