fog-core 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +2 -0
- data/.github/workflows/ruby.yml +1 -1
- data/.github/workflows/stale.yml +1 -1
- data/.rubocop.yml +16 -12
- data/.rubocop_todo.yml +724 -0
- data/Gemfile +1 -1
- data/Rakefile +2 -14
- data/changelog.md +14 -0
- data/fog-core.gemspec +10 -7
- data/lib/fog/compute/models/server.rb +7 -3
- data/lib/fog/compute.rb +2 -2
- 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 +6 -1
- 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 +4 -4
- 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 -58
- data/lib/fog/formatador.rb +7 -6
- data/lib/fog/schema/data_validator.rb +1 -0
- data/lib/fog/storage.rb +15 -15
- 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 +2 -2
- data/spec/compute/models/server_spec.rb +7 -7
- data/spec/compute_spec.rb +6 -6
- data/spec/connection_spec.rb +11 -9
- data/spec/core/cache_spec.rb +51 -15
- data/spec/core/collection_spec.rb +24 -0
- data/spec/core/model_spec.rb +36 -3
- data/spec/core/stringify_keys_spec.rb +3 -3
- data/spec/core/whitelist_keys_spec.rb +2 -2
- data/spec/current_machine_spec.rb +2 -2
- data/spec/fog_attribute_spec.rb +183 -163
- data/spec/formatador_spec.rb +7 -7
- data/spec/identity_spec.rb +6 -6
- data/spec/mocking_spec.rb +3 -3
- data/spec/service_spec.rb +19 -19
- data/spec/spec_helper.rb +3 -8
- data/spec/storage_spec.rb +6 -6
- data/spec/test_helpers/formats_helper_spec.rb +8 -8
- data/spec/test_helpers/schema_validator_spec.rb +8 -8
- data/spec/utils_spec.rb +6 -6
- data/spec/wait_for_spec.rb +2 -2
- metadata +44 -53
@@ -9,91 +9,91 @@ Fog.mock! if ENV["FOG_MOCK"] == "true"
|
|
9
9
|
# if in mocked mode, fill in some fake credentials for us
|
10
10
|
if Fog.mock?
|
11
11
|
Fog.credentials = {
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
12
|
+
aws_access_key_id: "aws_access_key_id",
|
13
|
+
aws_secret_access_key: "aws_secret_access_key",
|
14
|
+
ia_access_key_id: "aws_access_key_id",
|
15
|
+
ia_secret_access_key: "aws_secret_access_key",
|
16
|
+
bluebox_api_key: "bluebox_api_key",
|
17
|
+
bluebox_customer_id: "bluebox_customer_id",
|
18
|
+
brightbox_client_id: "brightbox_client_id",
|
19
|
+
brightbox_secret: "brightbox_secret",
|
20
|
+
cloudstack_disk_offering_id: "",
|
21
|
+
cloudstack_host: "http://cloudstack.example.org",
|
22
|
+
cloudstack_network_ids: "",
|
23
|
+
cloudstack_service_offering_id: "4437ac6c-9fe3-477a-57ec-60a5a45896a4",
|
24
|
+
cloudstack_template_id: "8a31cf9c-f248-0588-256e-9dbf58785216",
|
25
|
+
cloudstack_zone_id: "c554c592-e09c-9df5-7688-4a32754a4305",
|
26
|
+
clodo_api_key: "clodo_api_key",
|
27
|
+
clodo_username: "clodo_username",
|
28
|
+
digitalocean_api_key: "digitalocean_api_key",
|
29
|
+
digitalocean_client_id: "digitalocean_client_id",
|
30
|
+
dnsimple_token: "dnsimple_token",
|
31
|
+
dnsimple_account: "dnsimple_account",
|
32
|
+
dnsmadeeasy_api_key: "dnsmadeeasy_api_key",
|
33
|
+
dnsmadeeasy_secret_key: "dnsmadeeasy_secret_key",
|
34
|
+
glesys_username: "glesys_username",
|
35
|
+
glesys_api_key: "glesys_api_key",
|
36
|
+
go_grid_api_key: "go_grid_api_key",
|
37
|
+
go_grid_shared_secret: "go_grid_shared_secret",
|
38
|
+
google_storage_access_key_id: "google_storage_access_key_id",
|
39
|
+
google_storage_secret_access_key: "google_storage_secret_access_key",
|
40
|
+
google_project: "google_project_name",
|
41
|
+
google_client_email: "fake@developer.gserviceaccount.com",
|
42
|
+
google_key_location: "~/fake.p12",
|
43
|
+
hp_access_key: "hp_access_key",
|
44
|
+
hp_secret_key: "hp_secret_key",
|
45
|
+
hp_tenant_id: "hp_tenant_id",
|
46
|
+
hp_avl_zone: "hp_avl_zone",
|
47
|
+
os_account_meta_temp_url_key: "os_account_meta_temp_url_key",
|
48
|
+
ibm_username: "ibm_username",
|
49
|
+
ibm_password: "ibm_password",
|
50
|
+
joyent_username: "joyentuser",
|
51
|
+
joyent_password: "joyentpass",
|
52
|
+
linode_api_key: "linode_api_key",
|
53
|
+
local_root: "~/.fog",
|
54
|
+
bare_metal_cloud_password: "bare_metal_cloud_password",
|
55
|
+
bare_metal_cloud_username: "bare_metal_cloud_username",
|
56
|
+
ninefold_compute_key: "ninefold_compute_key",
|
57
|
+
ninefold_compute_secret: "ninefold_compute_secret",
|
58
|
+
ninefold_storage_secret: "ninefold_storage_secret",
|
59
|
+
ninefold_storage_token: "ninefold_storage_token",
|
60
60
|
# :public_key_path => "~/.ssh/id_rsa.pub",
|
61
61
|
# :private_key_path => "~/.ssh/id_rsa",
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
62
|
+
openstack_api_key: "openstack_api_key",
|
63
|
+
openstack_username: "openstack_username",
|
64
|
+
openstack_tenant: "openstack_tenant",
|
65
|
+
openstack_auth_url: "http://openstack:35357/v2.0/tokens",
|
66
|
+
ovirt_url: "http://ovirt:8080/api",
|
67
|
+
ovirt_username: "admin@internal",
|
68
|
+
ovirt_password: "123123",
|
69
|
+
rackspace_api_key: "rackspace_api_key",
|
70
|
+
rackspace_username: "rackspace_username",
|
71
|
+
riakcs_access_key_id: "riakcs_access_key_id",
|
72
|
+
riakcs_secret_access_key: "riakcs_secret_access_key",
|
73
|
+
vcloud_host: "vcloud_host",
|
74
|
+
vcloud_password: "vcloud_password",
|
75
|
+
vcloud_username: "vcloud_username",
|
76
|
+
vcloud_director_host: "vcloud-director-host",
|
77
|
+
vcloud_director_password: "vcloud_director_password",
|
78
|
+
vcloud_director_username: "vcd_user@vcd_org_name",
|
79
|
+
voxel_api_key: "voxel_api_key",
|
80
|
+
voxel_api_secret: "voxel_api_secret",
|
81
|
+
zerigo_email: "zerigo_email",
|
82
|
+
zerigo_token: "zerigo_token",
|
83
|
+
dynect_customer: "dynect_customer",
|
84
|
+
dynect_username: "dynect_username",
|
85
|
+
dynect_password: "dynect_password",
|
86
|
+
vsphere_server: "virtualcenter.lan",
|
87
|
+
vsphere_username: "apiuser",
|
88
|
+
vsphere_password: "apipassword",
|
89
|
+
vsphere_expected_pubkey_hash: "abcdef1234567890",
|
90
|
+
libvirt_uri: "qemu:///system",
|
91
|
+
libvirt_username: "root",
|
92
|
+
libvirt_password: "password",
|
93
|
+
cloudsigma_username: "csuname",
|
94
|
+
cloudsigma_password: "cspass",
|
95
|
+
kubevirt_token: "[TOKEN]",
|
96
|
+
kubevirt_hostname: "localhost",
|
97
|
+
kubevirt_port: "6443"
|
98
98
|
}.merge(Fog.credentials)
|
99
99
|
end
|
data/lib/tasks/test_task.rb
CHANGED
@@ -27,8 +27,8 @@ module Fog
|
|
27
27
|
Fog.providers.each do |key, value|
|
28
28
|
threads << Thread.new do
|
29
29
|
Thread.main[:results] << {
|
30
|
-
:
|
31
|
-
:
|
30
|
+
provider: value,
|
31
|
+
success: sh("export FOG_MOCK=#{mocked} && bundle exec shindont +#{key}")
|
32
32
|
}
|
33
33
|
end
|
34
34
|
end
|
@@ -26,13 +26,13 @@ describe Fog::Compute::Server do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
29
|
describe "when the ssh_ip_address exists" do
|
31
30
|
# Define these constants which would be imported by net-ssh once loaded
|
32
31
|
module Net
|
33
32
|
module SSH
|
34
33
|
class AuthenticationFailed < RuntimeError
|
35
34
|
end
|
35
|
+
|
36
36
|
class Disconnect < RuntimeError
|
37
37
|
end
|
38
38
|
end
|
@@ -55,7 +55,7 @@ describe Fog::Compute::Server do
|
|
55
55
|
it "is false" do
|
56
56
|
@server.stub(:ready?, true) do
|
57
57
|
@server.stub(:ssh_ip_address, "10.0.0.1") do
|
58
|
-
raise_error = lambda { |_cmd, _options| raise Net::SSH::AuthenticationFailed.new }
|
58
|
+
raise_error = lambda { |_cmd, _options={}| raise Net::SSH::AuthenticationFailed.new }
|
59
59
|
@server.stub(:ssh, raise_error) do
|
60
60
|
refute @server.sshable?
|
61
61
|
end
|
@@ -67,7 +67,7 @@ describe Fog::Compute::Server do
|
|
67
67
|
@server.instance_variable_set(:@sshable_timeout, 8)
|
68
68
|
@server.stub(:ready?, true) do
|
69
69
|
@server.stub(:ssh_ip_address, "10.0.0.1") do
|
70
|
-
raise_error = lambda { |_cmd, _options| raise Net::SSH::AuthenticationFailed.new }
|
70
|
+
raise_error = lambda { |_cmd, _options={}| raise Net::SSH::AuthenticationFailed.new }
|
71
71
|
@server.stub(:ssh, raise_error) do
|
72
72
|
@server.sshable?
|
73
73
|
assert_nil @server.instance_variable_get(:@sshable_timeout), nil
|
@@ -81,7 +81,7 @@ describe Fog::Compute::Server do
|
|
81
81
|
it "is false" do
|
82
82
|
@server.stub(:ready?, true) do
|
83
83
|
@server.stub(:ssh_ip_address, "10.0.0.1") do
|
84
|
-
raise_error = lambda { |_cmd, _options| raise Net::SSH::Disconnect.new }
|
84
|
+
raise_error = lambda { |_cmd, _options={}| raise Net::SSH::Disconnect.new }
|
85
85
|
@server.stub(:ssh, raise_error) do
|
86
86
|
refute @server.sshable?
|
87
87
|
end
|
@@ -93,7 +93,7 @@ describe Fog::Compute::Server do
|
|
93
93
|
@server.instance_variable_set(:@sshable_timeout, 8)
|
94
94
|
@server.stub(:ready?, true) do
|
95
95
|
@server.stub(:ssh_ip_address, "10.0.0.1") do
|
96
|
-
raise_error = lambda { |_cmd, _options| raise Net::SSH::Disconnect.new }
|
96
|
+
raise_error = lambda { |_cmd, _options={}| raise Net::SSH::Disconnect.new }
|
97
97
|
@server.stub(:ssh, raise_error) do
|
98
98
|
@server.sshable?
|
99
99
|
assert_nil @server.instance_variable_get(:@sshable_timeout), nil
|
@@ -107,7 +107,7 @@ describe Fog::Compute::Server do
|
|
107
107
|
it "is false" do
|
108
108
|
@server.stub(:ready?, true) do
|
109
109
|
@server.stub(:ssh_ip_address, "10.0.0.1") do
|
110
|
-
raise_error = lambda { |_cmd, _options| raise SystemCallError.new("message, 0") }
|
110
|
+
raise_error = lambda { |_cmd, _options={}| raise SystemCallError.new("message, 0") }
|
111
111
|
@server.stub(:ssh, raise_error) do
|
112
112
|
refute @server.sshable?
|
113
113
|
end
|
@@ -118,7 +118,7 @@ describe Fog::Compute::Server do
|
|
118
118
|
it "does not increase SSH timeout" do
|
119
119
|
@server.stub(:ready?, true) do
|
120
120
|
@server.stub(:ssh_ip_address, "10.0.0.1") do
|
121
|
-
raise_error = lambda { |_cmd, _options| raise SystemCallError.new("message, 0") }
|
121
|
+
raise_error = lambda { |_cmd, _options={}| raise SystemCallError.new("message, 0") }
|
122
122
|
@server.stub(:ssh, raise_error) do
|
123
123
|
@server.sshable?
|
124
124
|
assert_equal @server.instance_variable_get(:@sshable_timeout), 8
|
data/spec/compute_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe "Fog::Compute" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "instantiates an instance of Fog::Compute::<Provider> from the :provider keyword arg" do
|
27
|
-
compute = Fog::Compute.new(:
|
27
|
+
compute = Fog::Compute.new(provider: :therightway)
|
28
28
|
assert_instance_of(Fog::TheRightWay::Compute, compute)
|
29
29
|
end
|
30
30
|
|
@@ -44,7 +44,7 @@ describe "Fog::Compute" do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "instantiates an instance of Fog::<Provider>::Compute from the :provider keyword arg" do
|
47
|
-
compute = Fog::Compute.new(:
|
47
|
+
compute = Fog::Compute.new(provider: :thewrongway)
|
48
48
|
assert_instance_of(Fog::Compute::TheWrongWay, compute)
|
49
49
|
end
|
50
50
|
|
@@ -76,19 +76,19 @@ describe "Fog::Compute" do
|
|
76
76
|
|
77
77
|
describe "when both Fog::Compute::<Provider> and Fog::<Provider>::Compute exist" do
|
78
78
|
it "prefers Fog::<Provider>::Compute" do
|
79
|
-
compute = Fog::Compute.new(:
|
79
|
+
compute = Fog::Compute.new(provider: :bothways)
|
80
80
|
assert_instance_of(Fog::BothWays::Compute, compute)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
it "passes the supplied keyword args less :provider to Fog::Compute::<Provider>#new" do
|
85
|
-
compute = Fog::Compute.new(:
|
86
|
-
assert_equal({ :
|
85
|
+
compute = Fog::Compute.new(provider: :bothways, extra: :stuff)
|
86
|
+
assert_equal({ extra: :stuff }, compute.args)
|
87
87
|
end
|
88
88
|
|
89
89
|
it "raises ArgumentError when given a :provider where a Fog::Compute::Provider that does not exist" do
|
90
90
|
assert_raises(ArgumentError) do
|
91
|
-
Fog::Compute.new(:
|
91
|
+
Fog::Compute.new(provider: :wat)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/spec/connection_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Fog::Core::Connection do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "adds custom user-agents to Fog requests" do
|
18
|
-
Fog::VERSION =
|
18
|
+
Fog::VERSION = "Version".freeze
|
19
19
|
Fog::Core::Connection.add_user_agent("my-app/1.2")
|
20
20
|
|
21
21
|
connection = Fog::Core::Connection.new("http://example.com")
|
@@ -31,7 +31,7 @@ describe Fog::Core::Connection do
|
|
31
31
|
|
32
32
|
it "doesn't error when persistence is enabled and debug_response is disabled" do
|
33
33
|
options = {
|
34
|
-
:
|
34
|
+
debug_response: false
|
35
35
|
}
|
36
36
|
Fog::Core::Connection.new("http://example.com", true, options)
|
37
37
|
end
|
@@ -40,14 +40,14 @@ describe Fog::Core::Connection do
|
|
40
40
|
it "does not emit a warning when provided this argument in the initializer" do
|
41
41
|
$stderr = StringIO.new
|
42
42
|
|
43
|
-
Fog::Core::Connection.new("http://example.com", false, :
|
43
|
+
Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo")
|
44
44
|
|
45
45
|
assert_empty($stderr.string)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "raises when the 'path' arg is present and this arg is supplied" do
|
49
49
|
assert_raises(ArgumentError) do
|
50
|
-
Fog::Core::Connection.new("http://example.com", false, :
|
50
|
+
Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo", path: "bar")
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -60,13 +60,14 @@ describe Fog::Core::Connection do
|
|
60
60
|
def params
|
61
61
|
@params
|
62
62
|
end
|
63
|
+
|
63
64
|
def new(_, params)
|
64
65
|
@params = params
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
69
|
Object.stub_const("Excon", spy) do
|
69
|
-
Fog::Core::Connection.new("http://example.com", false, :
|
70
|
+
Fog::Core::Connection.new("http://example.com", false, path: "bar")
|
70
71
|
assert_equal("bar", spy.params[:path])
|
71
72
|
end
|
72
73
|
end
|
@@ -78,6 +79,7 @@ describe Fog::Core::Connection do
|
|
78
79
|
spy.instance_eval do
|
79
80
|
def new(*_args); self; end
|
80
81
|
def params; @params; end
|
82
|
+
|
81
83
|
def request(params)
|
82
84
|
@params = params
|
83
85
|
end
|
@@ -87,16 +89,16 @@ describe Fog::Core::Connection do
|
|
87
89
|
|
88
90
|
it "uses the initializer-supplied :path_prefix arg with #request :arg to formulate a path to send to Excon.request" do
|
89
91
|
Object.stub_const("Excon", spy) do
|
90
|
-
c = Fog::Core::Connection.new("http://example.com", false, :
|
91
|
-
c.request(:
|
92
|
+
c = Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo")
|
93
|
+
c.request(path: "bar")
|
92
94
|
assert_equal("foo/bar", spy.params[:path])
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
98
|
it "does not introduce consecutive '/'s into the path if 'path' starts with a '/'" do
|
97
99
|
Object.stub_const("Excon", spy) do
|
98
|
-
c = Fog::Core::Connection.new("http://example.com", false, :
|
99
|
-
c.request(:
|
100
|
+
c = Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo")
|
101
|
+
c.request(path: "/bar")
|
100
102
|
assert_equal("foo/bar", spy.params[:path])
|
101
103
|
end
|
102
104
|
end
|
data/spec/core/cache_spec.rb
CHANGED
@@ -1,10 +1,33 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "securerandom"
|
3
|
-
require "tmpdir"
|
4
3
|
|
5
4
|
module Fog
|
6
5
|
class SubFogTestModel < Fog::Model
|
7
6
|
identity :id
|
7
|
+
|
8
|
+
attribute :config
|
9
|
+
attribute :subconfig
|
10
|
+
|
11
|
+
def initialize(new_attributes = {})
|
12
|
+
super
|
13
|
+
|
14
|
+
# This way we make YAML to use aliases
|
15
|
+
self.config = {
|
16
|
+
"users" => [
|
17
|
+
{ "user1" => "user1@email" },
|
18
|
+
{ "user2" => "user2@email" }
|
19
|
+
]
|
20
|
+
}
|
21
|
+
self.subconfig = config["users"][0]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Fog
|
27
|
+
class SubFogTestCollection < Fog::Collection
|
28
|
+
model Fog::SubFogTestModel
|
29
|
+
|
30
|
+
attribute :spec_attribute
|
8
31
|
end
|
9
32
|
end
|
10
33
|
|
@@ -44,7 +67,7 @@ describe Fog::Cache do
|
|
44
67
|
# nothing exists, nothing comes back
|
45
68
|
assert_equal Fog::Cache.metadata, {}
|
46
69
|
# write/read
|
47
|
-
Fog::Cache.write_metadata({:
|
70
|
+
Fog::Cache.write_metadata({last_dumped: "Tuesday, November 8, 2016"})
|
48
71
|
assert_equal Fog::Cache.metadata[:last_dumped], "Tuesday, November 8, 2016"
|
49
72
|
|
50
73
|
# diff namespace, diff metadata
|
@@ -52,10 +75,10 @@ describe Fog::Cache do
|
|
52
75
|
assert_nil Fog::Cache.metadata[:last_dumped]
|
53
76
|
# still accessible per namespace
|
54
77
|
Fog::Cache.namespace_prefix = "for-service-user-region-foo"
|
55
|
-
assert_equal Fog::Cache.metadata[:last_dumped],
|
78
|
+
assert_equal Fog::Cache.metadata[:last_dumped], "Tuesday, November 8, 2016"
|
56
79
|
# can overwrite
|
57
|
-
Fog::Cache.write_metadata({:
|
58
|
-
assert_equal Fog::Cache.metadata[:last_dumped],
|
80
|
+
Fog::Cache.write_metadata({last_dumped: "Diff date"})
|
81
|
+
assert_equal Fog::Cache.metadata[:last_dumped], "Diff date"
|
59
82
|
|
60
83
|
# can't write a non-hash/data entry.
|
61
84
|
assert_raises Fog::Cache::CacheDir do
|
@@ -65,10 +88,9 @@ describe Fog::Cache do
|
|
65
88
|
# namespace must be set as well.
|
66
89
|
assert_raises Fog::Cache::CacheDir do
|
67
90
|
Fog::Cache.namespace_prefix = nil
|
68
|
-
Fog::Cache.write_metadata({:
|
91
|
+
Fog::Cache.write_metadata({a: "b"})
|
69
92
|
end
|
70
|
-
|
71
|
-
end
|
93
|
+
end
|
72
94
|
|
73
95
|
it "can load cache data from disk" do
|
74
96
|
path = File.expand_path("~/.fog-cache-test-#{Time.now.to_i}.yml")
|
@@ -116,7 +138,7 @@ describe Fog::Cache do
|
|
116
138
|
it "Fog cache ignores bad cache data - empty file, from disk" do
|
117
139
|
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
118
140
|
id = SecureRandom.hex
|
119
|
-
a = Fog::SubFogTestModel.new(:
|
141
|
+
a = Fog::SubFogTestModel.new(id: id, service: @service)
|
120
142
|
a.cache.dump
|
121
143
|
|
122
144
|
# input bad data
|
@@ -130,13 +152,12 @@ describe Fog::Cache do
|
|
130
152
|
assert_equal 1, Fog::Cache.load(Fog::SubFogTestModel, @service).size
|
131
153
|
end
|
132
154
|
|
133
|
-
|
134
155
|
it "can be dumped and reloaded back in" do
|
135
156
|
|
136
157
|
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
137
158
|
|
138
159
|
id = SecureRandom.hex
|
139
|
-
a = Fog::SubFogTestModel.new(:
|
160
|
+
a = Fog::SubFogTestModel.new(id: id, service: @service)
|
140
161
|
|
141
162
|
assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), false
|
142
163
|
a.cache.dump
|
@@ -155,8 +176,8 @@ describe Fog::Cache do
|
|
155
176
|
|
156
177
|
# security groups on aws for eg can have the same identity group name 'default'.
|
157
178
|
# there are no restrictions on `identity` fog attributes to be uniq.
|
158
|
-
a = Fog::SubFogTestModel.new(:
|
159
|
-
b = Fog::SubFogTestModel.new(:
|
179
|
+
a = Fog::SubFogTestModel.new(id: id, service: @service, bar: "bar")
|
180
|
+
b = Fog::SubFogTestModel.new(id: id, service: @service, foo: "foo")
|
160
181
|
|
161
182
|
a.cache.dump
|
162
183
|
b.cache.dump
|
@@ -173,8 +194,8 @@ describe Fog::Cache do
|
|
173
194
|
|
174
195
|
# security groups on aws for eg can have the same identity group name 'default'.
|
175
196
|
# there are no restrictions on `identity` fog attributes to be uniq.
|
176
|
-
a = Fog::SubFogTestModel.new(:
|
177
|
-
b = Fog::SubFogTestModel.new(:
|
197
|
+
a = Fog::SubFogTestModel.new(id: id, service: @service, bar: "bar")
|
198
|
+
b = Fog::SubFogTestModel.new(id: id, service: @service, foo: "foo")
|
178
199
|
|
179
200
|
a.cache.dump
|
180
201
|
b.cache.dump
|
@@ -188,4 +209,19 @@ describe Fog::Cache do
|
|
188
209
|
# unique-ify based on the attributes...
|
189
210
|
assert_equal instances.size, 2
|
190
211
|
end
|
212
|
+
|
213
|
+
it "dumps model with collection attributes and reloads them" do
|
214
|
+
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
215
|
+
|
216
|
+
c = Fog::SubFogTestCollection.new(service: @service, spec_attribute: 42)
|
217
|
+
|
218
|
+
id = SecureRandom.hex
|
219
|
+
a = Fog::SubFogTestModel.new(id: id, service: @service, collection: c)
|
220
|
+
|
221
|
+
a.cache.dump
|
222
|
+
|
223
|
+
instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
|
224
|
+
assert_equal instances.first.id, id
|
225
|
+
assert_equal instances.first.collection.spec_attribute, 42
|
226
|
+
end
|
191
227
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "securerandom"
|
3
|
+
|
4
|
+
class FogTestModelForCollection < Fog::Model
|
5
|
+
identity :id
|
6
|
+
end
|
7
|
+
|
8
|
+
class FogTestCollection < Fog::Collection
|
9
|
+
model FogTestModelForCollection
|
10
|
+
|
11
|
+
def all
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Fog::Collection do
|
17
|
+
describe "array delegation" do
|
18
|
+
it "delegates methods with keywords to Array" do
|
19
|
+
c = FogTestCollection.new
|
20
|
+
c << FogTestModelForCollection.new(id: SecureRandom.hex)
|
21
|
+
assert_equal c.sample(1, random: Random)[0], c[0]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/core/model_spec.rb
CHANGED
@@ -3,6 +3,17 @@ require "securerandom"
|
|
3
3
|
|
4
4
|
class FogTestModel < Fog::Model
|
5
5
|
identity :id
|
6
|
+
attribute :value
|
7
|
+
|
8
|
+
def create
|
9
|
+
self.identity = SecureRandom.hex
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
self.value = 42
|
15
|
+
self
|
16
|
+
end
|
6
17
|
end
|
7
18
|
|
8
19
|
describe Fog::Model do
|
@@ -21,7 +32,7 @@ describe Fog::Model do
|
|
21
32
|
|
22
33
|
it "is equal if it has the same non-nil identity and the same class" do
|
23
34
|
id = SecureRandom.hex
|
24
|
-
assert_equal FogTestModel.new(:
|
35
|
+
assert_equal FogTestModel.new(id: id), FogTestModel.new(id: id)
|
25
36
|
end
|
26
37
|
|
27
38
|
it "is not equal if both have nil identity, but are different objects" do
|
@@ -29,8 +40,30 @@ describe Fog::Model do
|
|
29
40
|
end
|
30
41
|
|
31
42
|
it "is not equal if it has a different identity" do
|
32
|
-
refute_equal FogTestModel.new(:
|
33
|
-
FogTestModel.new(:
|
43
|
+
refute_equal FogTestModel.new(id: SecureRandom.hex),
|
44
|
+
FogTestModel.new(id: SecureRandom.hex)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#save" do
|
49
|
+
describe "on a non persisted object" do
|
50
|
+
it "creates a new resource" do
|
51
|
+
a = FogTestModel.new
|
52
|
+
a.stub(:persisted?, false) do
|
53
|
+
a.save
|
54
|
+
refute_nil(a.identity)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "on a persisted object" do
|
60
|
+
it "updates resource" do
|
61
|
+
a = FogTestModel.new
|
62
|
+
a.stub(:persisted?, true) do
|
63
|
+
a.save
|
64
|
+
assert_equal(a.value, 42)
|
65
|
+
end
|
66
|
+
end
|
34
67
|
end
|
35
68
|
end
|
36
69
|
end
|
@@ -4,7 +4,7 @@ describe "Fog::StringifyKeys" do
|
|
4
4
|
describe ".stringify" do
|
5
5
|
describe "when key is a Symbol" do
|
6
6
|
it "replaces key with String" do
|
7
|
-
input = { :
|
7
|
+
input = { key: "value" }
|
8
8
|
output = Fog::StringifyKeys.stringify(input)
|
9
9
|
assert(output.key?("key"))
|
10
10
|
end
|
@@ -26,11 +26,11 @@ describe "Fog::StringifyKeys" do
|
|
26
26
|
|
27
27
|
describe "when keys are deeply nested" do
|
28
28
|
it "updates only top level key" do
|
29
|
-
input = { :
|
29
|
+
input = { key1: { key2: { key3: nil }}}
|
30
30
|
|
31
31
|
output = Fog::StringifyKeys.stringify(input)
|
32
32
|
|
33
|
-
expected = { "key1" => { :
|
33
|
+
expected = { "key1" => { key2: { key3: nil }}}
|
34
34
|
assert_equal(expected, output)
|
35
35
|
end
|
36
36
|
end
|
@@ -4,7 +4,7 @@ describe "Fog::WhitelistKeys" do
|
|
4
4
|
describe ".whitelist" do
|
5
5
|
describe "when other keys are present" do
|
6
6
|
it "returns Hash with only allowed keys" do
|
7
|
-
input = { :
|
7
|
+
input = { name: "name", type: "type", size: 80 }
|
8
8
|
valid_keys = %w(name size)
|
9
9
|
|
10
10
|
output = Fog::WhitelistKeys.whitelist(input, valid_keys)
|
@@ -16,7 +16,7 @@ describe "Fog::WhitelistKeys" do
|
|
16
16
|
|
17
17
|
describe "when key is a Symbol" do
|
18
18
|
it "returns a String" do
|
19
|
-
input = { :
|
19
|
+
input = { name: "name" }
|
20
20
|
valid_keys = %w(name)
|
21
21
|
|
22
22
|
output = Fog::WhitelistKeys.whitelist(input, valid_keys)
|