fog-core 2.3.0 → 2.5.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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +2 -0
  3. data/.github/dependabot.yml +2 -2
  4. data/.github/workflows/ci.yml +32 -0
  5. data/.rubocop.yml +16 -12
  6. data/.rubocop_todo.yml +724 -0
  7. data/Gemfile +1 -1
  8. data/README.md +2 -1
  9. data/Rakefile +2 -14
  10. data/SECURITY.md +6 -0
  11. data/changelog.md +26 -0
  12. data/fog-core.gemspec +11 -8
  13. data/lib/fog/compute/models/server.rb +7 -3
  14. data/lib/fog/compute.rb +3 -3
  15. data/lib/fog/core/association.rb +1 -0
  16. data/lib/fog/core/attributes/default.rb +7 -0
  17. data/lib/fog/core/attributes.rb +28 -3
  18. data/lib/fog/core/cache.rb +58 -55
  19. data/lib/fog/core/collection.rb +9 -3
  20. data/lib/fog/core/connection.rb +1 -1
  21. data/lib/fog/core/current_machine.rb +1 -1
  22. data/lib/fog/core/errors.rb +1 -1
  23. data/lib/fog/core/logger.rb +2 -2
  24. data/lib/fog/core/mock.rb +7 -2
  25. data/lib/fog/core/model.rb +34 -5
  26. data/lib/fog/core/provider.rb +7 -7
  27. data/lib/fog/core/scp.rb +15 -11
  28. data/lib/fog/core/service.rb +5 -5
  29. data/lib/fog/core/services_mixin.rb +9 -9
  30. data/lib/fog/core/ssh.rb +3 -2
  31. data/lib/fog/core/stringify_keys.rb +0 -2
  32. data/lib/fog/core/time.rb +2 -2
  33. data/lib/fog/core/uuid.rb +2 -8
  34. data/lib/fog/core/version.rb +1 -1
  35. data/lib/fog/core/wait_for.rb +2 -1
  36. data/lib/fog/core/wait_for_defaults.rb +2 -0
  37. data/lib/fog/core.rb +57 -59
  38. data/lib/fog/formatador.rb +9 -8
  39. data/lib/fog/schema/data_validator.rb +1 -0
  40. data/lib/fog/storage.rb +15 -16
  41. data/lib/fog/test_helpers/collection_helper.rb +2 -0
  42. data/lib/fog/test_helpers/formats_helper.rb +2 -2
  43. data/lib/fog/test_helpers/helper.rb +3 -3
  44. data/lib/fog/test_helpers/minitest/assertions.rb +1 -1
  45. data/lib/fog/test_helpers/minitest/expectations.rb +1 -1
  46. data/lib/fog/test_helpers/mock_helper.rb +84 -84
  47. data/lib/fog/test_helpers/types_helper.rb +1 -0
  48. data/lib/tasks/test_task.rb +4 -5
  49. metadata +46 -81
  50. data/.github/workflows/ruby.yml +0 -18
  51. data/.github/workflows/stale.yml +0 -9
  52. data/spec/compute/models/server_spec.rb +0 -229
  53. data/spec/compute_spec.rb +0 -95
  54. data/spec/connection_spec.rb +0 -105
  55. data/spec/core/cache_spec.rb +0 -191
  56. data/spec/core/model_spec.rb +0 -36
  57. data/spec/core/stringify_keys_spec.rb +0 -38
  58. data/spec/core/whitelist_keys_spec.rb +0 -36
  59. data/spec/credentials_spec.rb +0 -88
  60. data/spec/current_machine_spec.rb +0 -36
  61. data/spec/fake_app/fake_service.rb +0 -18
  62. data/spec/fake_app/models/collection.rb +0 -5
  63. data/spec/fake_app/models/model.rb +0 -2
  64. data/spec/fake_app/requests/request.rb +0 -11
  65. data/spec/fog_attribute_spec.rb +0 -549
  66. data/spec/formatador_spec.rb +0 -154
  67. data/spec/identity_spec.rb +0 -95
  68. data/spec/mocking_spec.rb +0 -84
  69. data/spec/service_spec.rb +0 -201
  70. data/spec/spec_helper.rb +0 -19
  71. data/spec/storage_spec.rb +0 -112
  72. data/spec/test_helpers/formats_helper_spec.rb +0 -121
  73. data/spec/test_helpers/schema_validator_spec.rb +0 -101
  74. data/spec/timeout_spec.rb +0 -20
  75. data/spec/utils_spec.rb +0 -29
  76. data/spec/uuid_spec.rb +0 -11
  77. data/spec/wait_for_spec.rb +0 -30
@@ -1,229 +0,0 @@
1
- require "spec_helper"
2
- require "fog/compute/models/server"
3
-
4
- describe Fog::Compute::Server do
5
- before do
6
- @server = Fog::Compute::Server.new
7
- end
8
-
9
- describe "#sshable?" do
10
- describe "when the server is not ready" do
11
- it "is false" do
12
- @server.stub(:ready?, false) do
13
- refute @server.sshable?
14
- end
15
- end
16
- end
17
-
18
- describe "when the server is ready" do
19
- describe "when the ssh_ip_address is nil" do
20
- it "is false" do
21
- @server.stub(:ready?, true) do
22
- @server.stub(:ssh_ip_address, nil) do
23
- refute @server.sshable?
24
- end
25
- end
26
- end
27
- end
28
-
29
-
30
- describe "when the ssh_ip_address exists" do
31
- # Define these constants which would be imported by net-ssh once loaded
32
- module Net
33
- module SSH
34
- class AuthenticationFailed < RuntimeError
35
- end
36
- class Disconnect < RuntimeError
37
- end
38
- end
39
- end
40
-
41
- describe "and ssh times out" do
42
- it "is false" do
43
- @server.stub(:ready?, true) do
44
- @server.stub(:ssh_ip_address, "10.0.0.1") do
45
- raises_timeout = lambda { |_time| raise Timeout::Error.new }
46
- Timeout.stub(:timeout, raises_timeout) do
47
- refute @server.sshable?
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
54
- describe "and it raises Net::SSH::AuthenticationFailed" do
55
- it "is false" do
56
- @server.stub(:ready?, true) do
57
- @server.stub(:ssh_ip_address, "10.0.0.1") do
58
- raise_error = lambda { |_cmd, _options| raise Net::SSH::AuthenticationFailed.new }
59
- @server.stub(:ssh, raise_error) do
60
- refute @server.sshable?
61
- end
62
- end
63
- end
64
- end
65
-
66
- it "resets SSH timeout" do
67
- @server.instance_variable_set(:@sshable_timeout, 8)
68
- @server.stub(:ready?, true) do
69
- @server.stub(:ssh_ip_address, "10.0.0.1") do
70
- raise_error = lambda { |_cmd, _options| raise Net::SSH::AuthenticationFailed.new }
71
- @server.stub(:ssh, raise_error) do
72
- @server.sshable?
73
- assert_nil @server.instance_variable_get(:@sshable_timeout), nil
74
- end
75
- end
76
- end
77
- end
78
- end
79
-
80
- describe "and it raises Net::SSH::Disconnect" do
81
- it "is false" do
82
- @server.stub(:ready?, true) do
83
- @server.stub(:ssh_ip_address, "10.0.0.1") do
84
- raise_error = lambda { |_cmd, _options| raise Net::SSH::Disconnect.new }
85
- @server.stub(:ssh, raise_error) do
86
- refute @server.sshable?
87
- end
88
- end
89
- end
90
- end
91
-
92
- it "resets SSH timeout" do
93
- @server.instance_variable_set(:@sshable_timeout, 8)
94
- @server.stub(:ready?, true) do
95
- @server.stub(:ssh_ip_address, "10.0.0.1") do
96
- raise_error = lambda { |_cmd, _options| raise Net::SSH::Disconnect.new }
97
- @server.stub(:ssh, raise_error) do
98
- @server.sshable?
99
- assert_nil @server.instance_variable_get(:@sshable_timeout), nil
100
- end
101
- end
102
- end
103
- end
104
- end
105
-
106
- describe "and it raises SystemCallError" do
107
- it "is false" do
108
- @server.stub(:ready?, true) do
109
- @server.stub(:ssh_ip_address, "10.0.0.1") do
110
- raise_error = lambda { |_cmd, _options| raise SystemCallError.new("message, 0") }
111
- @server.stub(:ssh, raise_error) do
112
- refute @server.sshable?
113
- end
114
- end
115
- end
116
- end
117
-
118
- it "does not increase SSH timeout" do
119
- @server.stub(:ready?, true) do
120
- @server.stub(:ssh_ip_address, "10.0.0.1") do
121
- raise_error = lambda { |_cmd, _options| raise SystemCallError.new("message, 0") }
122
- @server.stub(:ssh, raise_error) do
123
- @server.sshable?
124
- assert_equal @server.instance_variable_get(:@sshable_timeout), 8
125
- end
126
- end
127
- end
128
- end
129
- end
130
-
131
- describe "and ssh completes within the designated timeout" do
132
- it "is true" do
133
- @server.stub(:ready?, true) do
134
- @server.stub(:ssh_ip_address, "10.0.0.1") do
135
- @server.stub(:ssh, "datum") do
136
- assert @server.sshable?
137
- end
138
- end
139
- end
140
- end
141
- end
142
-
143
- describe "when called successively" do
144
- describe "and ssh times out" do
145
- it "increases the timeout factor by 1.5" do
146
- @server.stub(:ready?, true) do
147
- @server.stub(:ssh_ip_address, "10.0.0.1") do
148
- raises_timeout = lambda do |time|
149
- assert(time == 8)
150
- raise Timeout::Error.new
151
- end
152
- Timeout.stub(:timeout, raises_timeout) do
153
- refute @server.sshable?
154
- end
155
-
156
- raises_timeout = lambda do |time|
157
- assert_equal(12, time)
158
- raise Timeout::Error.new
159
- end
160
- Timeout.stub(:timeout, raises_timeout) do
161
- refute @server.sshable?
162
- end
163
- end
164
- end
165
- end
166
-
167
- it "does not increase timeout beyond 60s" do
168
- @server.stub(:ready?, true) do
169
- @server.stub(:ssh_ip_address, "10.0.0.1") do
170
- raises_timeout = lambda { |_time| raise Timeout::Error.new }
171
- Timeout.stub(:timeout, raises_timeout) do
172
- 5.times { refute @server.sshable? }
173
- end
174
-
175
- raises_timeout = lambda do |time|
176
- assert_equal(60, time)
177
- raise Timeout::Error.new
178
- end
179
- Timeout.stub(:timeout, raises_timeout) do
180
- refute @server.sshable?
181
- end
182
-
183
- raises_timeout = lambda do |time|
184
- assert_equal(60, time)
185
- raise Timeout::Error.new
186
- end
187
- Timeout.stub(:timeout, raises_timeout) do
188
- refute @server.sshable?
189
- end
190
- end
191
- end
192
- end
193
-
194
- describe "when ssh eventually succeeds" do
195
- it "resets the timeout to the initial value" do
196
- @server.stub(:ready?, true) do
197
- @server.stub(:ssh_ip_address, "10.0.0.1") do
198
- raises_timeout = lambda do |time|
199
- assert(time == 8)
200
- raise Timeout::Error.new
201
- end
202
- Timeout.stub(:timeout, raises_timeout) do
203
- refute @server.sshable?
204
- end
205
-
206
- @server.stub(:ssh, "datum") do
207
- assert @server.sshable?
208
- end
209
-
210
- raises_timeout = lambda do |time|
211
- assert_equal(8, time)
212
- raise Timeout::Error.new
213
- end
214
- Timeout.stub(:timeout, raises_timeout) do
215
- refute @server.sshable?
216
- end
217
- end
218
- end
219
- end
220
- end
221
-
222
- end
223
- end
224
-
225
- end
226
- end
227
-
228
- end
229
- end
data/spec/compute_spec.rb DELETED
@@ -1,95 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Fog
4
- module Compute
5
- def self.require(*_args); end
6
- end
7
- end
8
-
9
- describe "Fog::Compute" do
10
- describe "#new" do
11
- module Fog
12
- module TheRightWay
13
- class Compute
14
- def initialize(_args); end
15
- end
16
- end
17
- end
18
-
19
- module Fog
20
- module TheRightWay
21
- extend Provider
22
- service(:compute, "Compute")
23
- end
24
- end
25
-
26
- it "instantiates an instance of Fog::Compute::<Provider> from the :provider keyword arg" do
27
- compute = Fog::Compute.new(:provider => :therightway)
28
- assert_instance_of(Fog::TheRightWay::Compute, compute)
29
- end
30
-
31
- module Fog
32
- module Compute
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(:compute, "Compute")
43
- end
44
- end
45
-
46
- it "instantiates an instance of Fog::<Provider>::Compute from the :provider keyword arg" do
47
- compute = Fog::Compute.new(:provider => :thewrongway)
48
- assert_instance_of(Fog::Compute::TheWrongWay, compute)
49
- end
50
-
51
- module Fog
52
- module BothWays
53
- class Compute
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 Compute
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(:compute, "Compute")
74
- end
75
- end
76
-
77
- describe "when both Fog::Compute::<Provider> and Fog::<Provider>::Compute exist" do
78
- it "prefers Fog::<Provider>::Compute" do
79
- compute = Fog::Compute.new(:provider => :bothways)
80
- assert_instance_of(Fog::BothWays::Compute, compute)
81
- end
82
- end
83
-
84
- it "passes the supplied keyword args less :provider to Fog::Compute::<Provider>#new" do
85
- compute = Fog::Compute.new(:provider => :bothways, :extra => :stuff)
86
- assert_equal({ :extra => :stuff }, compute.args)
87
- end
88
-
89
- it "raises ArgumentError when given a :provider where a Fog::Compute::Provider that does not exist" do
90
- assert_raises(ArgumentError) do
91
- Fog::Compute.new(:provider => :wat)
92
- end
93
- end
94
- end
95
- end
@@ -1,105 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fog::Core::Connection do
4
- it "raises ArgumentError when no arguments given" do
5
- assert_raises(ArgumentError) do
6
- Fog::Core::Connection.new
7
- end
8
- end
9
-
10
- [:request, :reset].each do |method|
11
- it "responds to #{method}" do
12
- connection = Fog::Core::Connection.new("http://example.com")
13
- assert connection.respond_to?(method)
14
- end
15
- end
16
-
17
- it "adds custom user-agents to Fog requests" do
18
- Fog::VERSION = 'Version'
19
- Fog::Core::Connection.add_user_agent("my-app/1.2")
20
-
21
- connection = Fog::Core::Connection.new("http://example.com")
22
- assert_equal "my-app/1.2 fog/Version fog-core/#{Fog::Core::VERSION}",
23
- connection.instance_variable_get(:@excon).data[:headers]["User-Agent"]
24
-
25
- Fog.send(:remove_const, :VERSION)
26
- end
27
-
28
- it "doesn't error when persistence is enabled" do
29
- Fog::Core::Connection.new("http://example.com", true)
30
- end
31
-
32
- it "doesn't error when persistence is enabled and debug_response is disabled" do
33
- options = {
34
- :debug_response => false
35
- }
36
- Fog::Core::Connection.new("http://example.com", true, options)
37
- end
38
-
39
- describe ":path_prefix" do
40
- it "does not emit a warning when provided this argument in the initializer" do
41
- $stderr = StringIO.new
42
-
43
- Fog::Core::Connection.new("http://example.com", false, :path_prefix => "foo")
44
-
45
- assert_empty($stderr.string)
46
- end
47
-
48
- it "raises when the 'path' arg is present and this arg is supplied" do
49
- assert_raises(ArgumentError) do
50
- Fog::Core::Connection.new("http://example.com", false, :path_prefix => "foo", :path => "bar")
51
- end
52
- end
53
- end
54
-
55
- describe "#request" do
56
- describe "default behavior" do
57
- it "supplies the 'path' arg directly to Excon" do
58
- spy = Object.new
59
- spy.instance_eval do
60
- def params
61
- @params
62
- end
63
- def new(_, params)
64
- @params = params
65
- end
66
- end
67
-
68
- Object.stub_const("Excon", spy) do
69
- Fog::Core::Connection.new("http://example.com", false, :path => "bar")
70
- assert_equal("bar", spy.params[:path])
71
- end
72
- end
73
- end
74
-
75
- describe "with path_prefix supplied to the initializer" do
76
- let(:spy) do
77
- Object.new.tap do |spy|
78
- spy.instance_eval do
79
- def new(*_args); self; end
80
- def params; @params; end
81
- def request(params)
82
- @params = params
83
- end
84
- end
85
- end
86
- end
87
-
88
- it "uses the initializer-supplied :path_prefix arg with #request :arg to formulate a path to send to Excon.request" do
89
- Object.stub_const("Excon", spy) do
90
- c = Fog::Core::Connection.new("http://example.com", false, :path_prefix => "foo")
91
- c.request(:path => "bar")
92
- assert_equal("foo/bar", spy.params[:path])
93
- end
94
- end
95
-
96
- it "does not introduce consecutive '/'s into the path if 'path' starts with a '/'" do
97
- Object.stub_const("Excon", spy) do
98
- c = Fog::Core::Connection.new("http://example.com", false, :path_prefix => "foo")
99
- c.request(:path => "/bar")
100
- assert_equal("foo/bar", spy.params[:path])
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,191 +0,0 @@
1
- require "spec_helper"
2
- require "securerandom"
3
- require "tmpdir"
4
-
5
- module Fog
6
- class SubFogTestModel < Fog::Model
7
- identity :id
8
- end
9
- end
10
-
11
- module Fog
12
- class SubFogTestService < Fog::Service
13
-
14
- class Mock
15
- attr_reader :options
16
-
17
- def initialize(opts = {})
18
- @options = opts
19
- end
20
- end
21
- end
22
- end
23
-
24
- describe Fog::Cache do
25
- before(:each) do
26
- Fog.mock!
27
- @service = Fog::SubFogTestService.new
28
- Fog::Cache.namespace_prefix = "test-dir"
29
- end
30
-
31
- it "has a namespace_prefix configurable" do
32
- Fog::Cache.namespace_prefix = "for-service-user-region-foo"
33
-
34
- # Expand path does not downcase. case insensitive platform tests.
35
- example_cache = File.expand_path(Fog::Cache.namespace(Fog::SubFogTestModel, @service)).downcase
36
- expected_namespace = File.expand_path("~/.fog-cache/for-service-user-region-foo").downcase
37
-
38
- assert_equal example_cache.include?(expected_namespace), true
39
- end
40
-
41
- it "has metadata associated to the namespace that you can save to" do
42
- Fog::Cache.clean!
43
- Fog::Cache.namespace_prefix = "for-service-user-region-foo"
44
- # nothing exists, nothing comes back
45
- assert_equal Fog::Cache.metadata, {}
46
- # write/read
47
- Fog::Cache.write_metadata({:last_dumped => "Tuesday, November 8, 2016"})
48
- assert_equal Fog::Cache.metadata[:last_dumped], "Tuesday, November 8, 2016"
49
-
50
- # diff namespace, diff metadata
51
- Fog::Cache.namespace_prefix = "different-namespace"
52
- assert_nil Fog::Cache.metadata[:last_dumped]
53
- # still accessible per namespace
54
- Fog::Cache.namespace_prefix = "for-service-user-region-foo"
55
- assert_equal Fog::Cache.metadata[:last_dumped], "Tuesday, November 8, 2016"
56
- # can overwrite
57
- Fog::Cache.write_metadata({:last_dumped => "Diff date"})
58
- assert_equal Fog::Cache.metadata[:last_dumped], "Diff date"
59
-
60
- # can't write a non-hash/data entry.
61
- assert_raises Fog::Cache::CacheDir do
62
- Fog::Cache.write_metadata("boo")
63
- end
64
-
65
- # namespace must be set as well.
66
- assert_raises Fog::Cache::CacheDir do
67
- Fog::Cache.namespace_prefix = nil
68
- Fog::Cache.write_metadata({:a => "b"})
69
- end
70
-
71
- end
72
-
73
- it "can load cache data from disk" do
74
- path = File.expand_path("~/.fog-cache-test-#{Time.now.to_i}.yml")
75
- data = "--- ok\n...\n"
76
- File.open(path, "w") { |f|
77
- f.write(data)
78
- }
79
-
80
- assert_equal "ok", Fog::Cache.load_cache(path)
81
- end
82
-
83
- it "load bad cache data - empty file, from disk" do
84
- path = File.expand_path("~/.fog-cache-test-2-#{Time.now.to_i}.yml")
85
- data = ""
86
- File.open(path, "w") { |f|
87
- f.write(data)
88
- }
89
-
90
- assert !Fog::Cache.load_cache(path)
91
- end
92
-
93
- it "must have a namespace_prefix configurable" do
94
- Fog::Cache.namespace_prefix = nil
95
- assert_raises Fog::Cache::CacheDir do
96
- Fog::Cache.load(Fog::SubFogTestModel, @service)
97
- end
98
- end
99
-
100
- it "can create a namespace" do
101
- Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
102
- assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), false
103
-
104
- Fog::Cache.create_namespace(Fog::SubFogTestModel, @service)
105
- assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), true
106
- end
107
-
108
- it "will raise if no cache data found" do
109
- Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
110
-
111
- assert_raises Fog::Cache::CacheNotFound do
112
- Fog::Cache.load(Fog::SubFogTestModel, @service)
113
- end
114
- end
115
-
116
- it "Fog cache ignores bad cache data - empty file, from disk" do
117
- Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
118
- id = SecureRandom.hex
119
- a = Fog::SubFogTestModel.new(:id => id, :service => @service)
120
- a.cache.dump
121
-
122
- # input bad data
123
- path_dir = File.expand_path(Fog::Cache.namespace(Fog::SubFogTestModel, @service))
124
- path = File.join(path_dir, "foo.yml")
125
- data = ""
126
- File.open(path, "w") { |f|
127
- f.write(data)
128
- }
129
-
130
- assert_equal 1, Fog::Cache.load(Fog::SubFogTestModel, @service).size
131
- end
132
-
133
-
134
- it "can be dumped and reloaded back in" do
135
-
136
- Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
137
-
138
- id = SecureRandom.hex
139
- a = Fog::SubFogTestModel.new(:id => id, :service => @service)
140
-
141
- assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), false
142
- a.cache.dump
143
- assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), true
144
-
145
- instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
146
-
147
- assert_equal instances.first.id, a.id
148
- assert_equal instances.first.class, a.class
149
- end
150
-
151
- it "dumping two models that have a duplicate identity" do
152
- Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
153
-
154
- id = SecureRandom.hex
155
-
156
- # security groups on aws for eg can have the same identity group name 'default'.
157
- # there are no restrictions on `identity` fog attributes to be uniq.
158
- a = Fog::SubFogTestModel.new(:id => id, :service => @service, :bar => 'bar')
159
- b = Fog::SubFogTestModel.new(:id => id, :service => @service, :foo => 'foo')
160
-
161
- a.cache.dump
162
- b.cache.dump
163
-
164
- instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
165
-
166
- assert_equal instances.size, 2
167
- end
168
-
169
- it "dumping two models that have a duplicate identity twice" do
170
- Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
171
-
172
- id = SecureRandom.hex
173
-
174
- # security groups on aws for eg can have the same identity group name 'default'.
175
- # there are no restrictions on `identity` fog attributes to be uniq.
176
- a = Fog::SubFogTestModel.new(:id => id, :service => @service, :bar => 'bar')
177
- b = Fog::SubFogTestModel.new(:id => id, :service => @service, :foo => 'foo')
178
-
179
- a.cache.dump
180
- b.cache.dump
181
-
182
- # and then again, w/out expiring cache
183
- a.cache.dump
184
- b.cache.dump
185
-
186
- instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
187
-
188
- # unique-ify based on the attributes...
189
- assert_equal instances.size, 2
190
- end
191
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
- require "securerandom"
3
-
4
- class FogTestModel < Fog::Model
5
- identity :id
6
- end
7
-
8
- describe Fog::Model do
9
- describe "#==" do
10
- it "is not equal if one is not a Fog::Model" do
11
- a = FogTestModel.new
12
- b = 2
13
- refute_equal a, b
14
- refute_equal b, a
15
- end
16
-
17
- it "is equal if it is the same object" do
18
- a = b = FogTestModel.new
19
- assert_equal a, b
20
- end
21
-
22
- it "is equal if it has the same non-nil identity and the same class" do
23
- id = SecureRandom.hex
24
- assert_equal FogTestModel.new(:id => id), FogTestModel.new(:id => id)
25
- end
26
-
27
- it "is not equal if both have nil identity, but are different objects" do
28
- refute_equal FogTestModel.new, FogTestModel.new
29
- end
30
-
31
- it "is not equal if it has a different identity" do
32
- refute_equal FogTestModel.new(:id => SecureRandom.hex),
33
- FogTestModel.new(:id => SecureRandom.hex)
34
- end
35
- end
36
- end
@@ -1,38 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Fog::StringifyKeys" do
4
- describe ".stringify" do
5
- describe "when key is a Symbol" do
6
- it "replaces key with String" do
7
- input = { :key => "value" }
8
- output = Fog::StringifyKeys.stringify(input)
9
- assert(output.key?("key"))
10
- end
11
- end
12
-
13
- describe "when key is a String" do
14
- it "keeps key as String" do
15
- input = { "key" => "value" }
16
- output = Fog::StringifyKeys.stringify(input)
17
- assert(output.key?("key"))
18
- end
19
- end
20
-
21
- describe "when Hash is empty" do
22
- it "returns empty Hash" do
23
- assert_equal({}, Fog::StringifyKeys.stringify({}))
24
- end
25
- end
26
-
27
- describe "when keys are deeply nested" do
28
- it "updates only top level key" do
29
- input = { :key1 => { :key2 => { :key3 => nil }}}
30
-
31
- output = Fog::StringifyKeys.stringify(input)
32
-
33
- expected = { "key1" => { :key2 => { :key3 => nil }}}
34
- assert_equal(expected, output)
35
- end
36
- end
37
- end
38
- end