brightbox-cli 5.0.0.alpha → 5.0.0.rc2

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -1
  3. data/CHANGELOG.md +63 -0
  4. data/Gemfile.lock +1 -1
  5. data/lib/brightbox-cli/accounts.rb +5 -1
  6. data/lib/brightbox-cli/api.rb +34 -1
  7. data/lib/brightbox-cli/cloud_ips.rb +6 -6
  8. data/lib/brightbox-cli/collaboration.rb +3 -7
  9. data/lib/brightbox-cli/commands/images/show.rb +5 -1
  10. data/lib/brightbox-cli/commands/lbs/create.rb +0 -2
  11. data/lib/brightbox-cli/commands/lbs/show.rb +9 -1
  12. data/lib/brightbox-cli/commands/servers/show.rb +5 -1
  13. data/lib/brightbox-cli/commands/users/show.rb +5 -1
  14. data/lib/brightbox-cli/commands/volumes/show.rb +5 -1
  15. data/lib/brightbox-cli/config.rb +10 -4
  16. data/lib/brightbox-cli/database_server.rb +20 -20
  17. data/lib/brightbox-cli/database_snapshot.rb +5 -5
  18. data/lib/brightbox-cli/database_type.rb +4 -8
  19. data/lib/brightbox-cli/detailed_server.rb +26 -28
  20. data/lib/brightbox-cli/detailed_server_group.rb +2 -2
  21. data/lib/brightbox-cli/firewall_policy.rb +5 -9
  22. data/lib/brightbox-cli/firewall_rule.rb +14 -15
  23. data/lib/brightbox-cli/images.rb +22 -21
  24. data/lib/brightbox-cli/indifferent_access_hash.rb +50 -0
  25. data/lib/brightbox-cli/load_balancers.rb +27 -11
  26. data/lib/brightbox-cli/server_groups.rb +4 -8
  27. data/lib/brightbox-cli/servers.rb +22 -16
  28. data/lib/brightbox-cli/types.rb +4 -8
  29. data/lib/brightbox-cli/user_collaboration.rb +1 -1
  30. data/lib/brightbox-cli/users.rb +3 -5
  31. data/lib/brightbox-cli/version.rb +1 -1
  32. data/lib/brightbox-cli/volume.rb +9 -13
  33. data/lib/brightbox-cli/zones.rb +0 -4
  34. data/lib/brightbox_cli.rb +1 -0
  35. data/spec/commands/cloudips/update_spec.rb +7 -5
  36. data/spec/commands/configmaps/create_spec.rb +6 -6
  37. data/spec/commands/configmaps/destroy_spec.rb +1 -1
  38. data/spec/commands/configmaps/list_spec.rb +1 -1
  39. data/spec/commands/configmaps/show_spec.rb +3 -3
  40. data/spec/commands/configmaps/update_spec.rb +9 -9
  41. data/spec/commands/images/show_spec.rb +49 -19
  42. data/spec/commands/lbs/create_spec.rb +12 -26
  43. data/spec/commands/lbs/show_spec.rb +120 -22
  44. data/spec/commands/lbs/update_spec.rb +4 -4
  45. data/spec/commands/servers/show_spec.rb +83 -1
  46. data/spec/commands/servers/update_spec.rb +7 -7
  47. data/spec/commands/sql/instances/create_spec.rb +8 -8
  48. data/spec/commands/sql/instances/reset_spec.rb +3 -3
  49. data/spec/commands/sql/instances/resize_spec.rb +4 -4
  50. data/spec/commands/sql/instances/show_spec.rb +2 -1
  51. data/spec/commands/sql/instances/update_spec.rb +3 -3
  52. data/spec/commands/sql/snapshots/list_spec.rb +1 -1
  53. data/spec/commands/sql/snapshots/show_spec.rb +50 -7
  54. data/spec/commands/users/show_spec.rb +66 -1
  55. data/spec/commands/volumes/attach_spec.rb +4 -4
  56. data/spec/commands/volumes/copy_spec.rb +2 -2
  57. data/spec/commands/volumes/destroy_spec.rb +1 -1
  58. data/spec/commands/volumes/detach_spec.rb +1 -1
  59. data/spec/commands/volumes/list_spec.rb +1 -1
  60. data/spec/commands/volumes/resize_spec.rb +3 -3
  61. data/spec/commands/volumes/show_spec.rb +54 -25
  62. data/spec/commands/volumes/update_spec.rb +4 -4
  63. data/spec/spec_helper.rb +14 -10
  64. data/spec/support/shared/api_resource_examples.rb +25 -0
  65. data/spec/unit/brightbox/account/attributes_spec.rb +13 -0
  66. data/spec/unit/brightbox/api/attributes_spec.rb +65 -0
  67. data/spec/unit/brightbox/api/fog_attributes_spec.rb +65 -0
  68. data/spec/unit/brightbox/cloud_ip/attributes_spec.rb +19 -0
  69. data/spec/unit/brightbox/collaborating_account/attributes_spec.rb +13 -0
  70. data/spec/unit/brightbox/database_server/attributes_spec.rb +13 -0
  71. data/spec/unit/brightbox/database_snapshot/attributes_spec.rb +13 -0
  72. data/spec/unit/brightbox/database_type/attributes_spec.rb +20 -0
  73. data/spec/unit/brightbox/detailed_server/attributes_spec.rb +29 -0
  74. data/spec/unit/brightbox/detailed_server_group/attributes_spec.rb +13 -0
  75. data/spec/unit/brightbox/firewall_policy/attributes_spec.rb +21 -0
  76. data/spec/unit/brightbox/firewall_rule/attributes_spec.rb +18 -0
  77. data/spec/unit/brightbox/image/attributes_spec.rb +13 -0
  78. data/spec/unit/brightbox/image/status_spec.rb +67 -0
  79. data/spec/unit/brightbox/load_balancer/acme_cert_spec.rb +75 -0
  80. data/spec/unit/brightbox/load_balancer/attributes_spec.rb +13 -0
  81. data/spec/unit/brightbox/load_balancer/formatted_acme_domains_spec.rb +78 -0
  82. data/spec/unit/brightbox/server/attributes_spec.rb +29 -0
  83. data/spec/unit/brightbox/server_group/attributes_spec.rb +13 -0
  84. data/spec/unit/brightbox/type/attributes_spec.rb +20 -0
  85. data/spec/unit/brightbox/user/attributes_spec.rb +13 -0
  86. data/spec/unit/brightbox/user_collaboration/attributes_spec.rb +13 -0
  87. metadata +50 -10
  88. data/spec/cassettes/brightbox_sql_snapshots/show/when_resource_exists/does_not_output_to_stderr.yml +0 -93
@@ -8,21 +8,64 @@ describe "brightbox sql snapshots" do
8
8
 
9
9
  before do
10
10
  config = config_from_contents(USER_APP_CONFIG_CONTENTS)
11
-
12
- # Setup in the VCR recordings
13
11
  cache_access_token(config, "f83da712e6299cda953513ec07f7a754f747d727")
14
12
  end
15
13
 
16
- context "when resource exists", vcr: true do
14
+ context "without arguments" do
15
+ let(:argv) { %w[sql snapshots show] }
16
+
17
+ it "reports error" do
18
+ expect(stderr).to include("You must specify snapshot ids to show")
19
+ expect(stdout).to be_empty
20
+ end
21
+ end
22
+
23
+ context "with identifier argument" do
17
24
  let(:argv) { %w[sql snapshots show dbi-12345] }
25
+ let(:json_response) do
26
+ <<~EOS
27
+ {
28
+ "id": "dbi-12345",
29
+ "resource_type": "database_snapshot",
30
+ "url": "string",
31
+ "name": "string",
32
+ "description": "string",
33
+ "status": "creating",
34
+ "locked": true,
35
+ "database_engine": "string",
36
+ "database_version": "string",
37
+ "source": "string",
38
+ "source_trigger": "manual",
39
+ "size": 0,
40
+ "created_at": "2024-12-17T10:14:38.092Z",
41
+ "updated_at": "2024-12-17T10:14:38.092Z",
42
+ "deleted_at": "2024-12-17T10:14:38.092Z",
43
+ "account": {
44
+ "id": "acc-12345",
45
+ "resource_type": "account",
46
+ "url": "string",
47
+ "name": "string",
48
+ "description": "string",
49
+ "status": "pending"
50
+ },
51
+ "metadata": {
52
+ "labels": {}
53
+ }
54
+ }
55
+ EOS
56
+ end
18
57
 
19
- it "does not output to stderr" do
20
- expect(stderr).to eql("")
58
+ before do
59
+ stub_request(:get, "http://api.brightbox.localhost/1.0/database_snapshots/dbi-12345?account_id=acc-12345")
60
+ .to_return(status: 200, body: json_response)
21
61
  end
22
62
 
23
63
  it "outputs table details to stdout" do
24
- expect(stdout).to_not be_empty
25
- expect(stdout).to match(/dbi-12345/)
64
+ aggregate_failures do
65
+ expect(stderr).to be_empty unless ENV["DEBUG"]
66
+ expect(stdout).to_not be_empty
67
+ expect(stdout).to match(/dbi-12345/)
68
+ end
26
69
  end
27
70
  end
28
71
  end
@@ -6,11 +6,76 @@ describe "brightbox users" do
6
6
  let(:stdout) { output.stdout }
7
7
  let(:stderr) { output.stderr }
8
8
 
9
- context "" do
9
+ before do
10
+ WebMock.reset!
11
+
12
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
13
+ stub_client_token_request
14
+ Brightbox.config.reauthenticate
15
+ end
16
+
17
+ context "without arguments" do
10
18
  let(:argv) { %w[users show] }
11
19
 
12
20
  it "does not error" do
13
21
  expect { output }.to_not raise_error
22
+
23
+ aggregate_failures do
24
+ expect(stderr).to match("ERROR: You must specify user IDs to show")
25
+ expect(stdout).to be_empty
26
+ end
27
+ end
28
+ end
29
+
30
+ context "with identifier argument" do
31
+ let(:argv) { %w[users show usr-90781] }
32
+
33
+ before do
34
+ # FIXME: Two requests, one with the parameter and one without
35
+ # One for ALL tests (with VCR breaking things)
36
+ # One for this test standalone
37
+ stub_request(:get, "#{api_url}/1.0/users/usr-90781")
38
+ .to_return(
39
+ status: 200,
40
+ body: {
41
+ id: "usr-90781",
42
+ email_address: "user@domain.test",
43
+ accounts: [
44
+ {
45
+ id: "acc-12345",
46
+ name: "Test account"
47
+ }
48
+ ]
49
+ }.to_json
50
+ )
51
+
52
+ # Same again but supporting the account_id parameter
53
+ stub_request(:get, "#{api_url}/1.0/users/usr-90781")
54
+ .with(query: hash_including(account_id: "acc-12345"))
55
+ .to_return(
56
+ status: 200,
57
+ body: {
58
+ id: "usr-90781",
59
+ email_address: "user@domain.test",
60
+ accounts: [
61
+ {
62
+ id: "acc-12345",
63
+ name: "Test account"
64
+ }
65
+ ]
66
+ }.to_json
67
+ )
68
+ end
69
+
70
+ it "does not error" do
71
+ expect { output }.to_not raise_error
72
+
73
+ aggregate_failures do
74
+ expect(stderr).to match("")
75
+ expect(stderr).not_to match("ERROR")
76
+ expect(stdout).to match("usr-90781")
77
+ expect(stdout).to match("email_address: user@domain.test")
78
+ end
14
79
  end
15
80
  end
16
81
  end
@@ -28,7 +28,7 @@ describe "brightbox volumes attach" do
28
28
  it "does not error" do
29
29
  expect { output }.to_not raise_error
30
30
 
31
- expect(stderr).to eq("ERROR: You must specify the volume ID as the first argument\n")
31
+ expect(stderr).to include("ERROR: You must specify the volume ID as the first argument\n")
32
32
 
33
33
  expect(stdout).to match("")
34
34
  end
@@ -40,7 +40,7 @@ describe "brightbox volumes attach" do
40
40
  it "does not error" do
41
41
  expect { output }.to_not raise_error
42
42
 
43
- expect(stderr).to eq("ERROR: You must specify the server ID to attach to as the second argument\n")
43
+ expect(stderr).to include("ERROR: You must specify the server ID to attach to as the second argument\n")
44
44
 
45
45
  expect(stdout).to match("")
46
46
  end
@@ -94,7 +94,7 @@ describe "brightbox volumes attach" do
94
94
  it "does not error" do
95
95
  expect { output }.to_not raise_error
96
96
 
97
- expect(stderr).to eq("Attaching vol-809s1\n")
97
+ expect(stderr).to include("Attaching vol-809s1\n")
98
98
 
99
99
  aggregate_failures do
100
100
  expect(stdout).to match("vol-809s1")
@@ -153,7 +153,7 @@ describe "brightbox volumes attach" do
153
153
  it "does not error" do
154
154
  expect { output }.to_not raise_error
155
155
 
156
- expect(stderr).to eq("Attaching vol-90328\n")
156
+ expect(stderr).to include("Attaching vol-90328\n")
157
157
 
158
158
  aggregate_failures do
159
159
  expect(stdout).to match("vol-90328")
@@ -28,7 +28,7 @@ describe "brightbox volumes copy" do
28
28
  it "does not error" do
29
29
  expect { output }.to_not raise_error
30
30
 
31
- expect(stderr).to eq("ERROR: You must specify the volume ID as the first argument\n")
31
+ expect(stderr).to include("ERROR: You must specify the volume ID as the first argument\n")
32
32
 
33
33
  expect(stdout).to match("")
34
34
  end
@@ -66,7 +66,7 @@ describe "brightbox volumes copy" do
66
66
  it "does not error" do
67
67
  expect { output }.to_not raise_error
68
68
 
69
- expect(stderr).to eq("Copying vol-909ds\n")
69
+ expect(stderr).to include("Copying vol-909ds\n")
70
70
 
71
71
  expect(stdout).to match("vol-909ds")
72
72
  end
@@ -28,7 +28,7 @@ describe "brightbox volumes destroy" do
28
28
  it "does not error" do
29
29
  expect { output }.to_not raise_error
30
30
 
31
- expect(stderr).to eq("ERROR: You must specify volume IDs as arguments\n")
31
+ expect(stderr).to include("ERROR: You must specify volume IDs as arguments\n")
32
32
 
33
33
  expect(stdout).to match("")
34
34
  end
@@ -28,7 +28,7 @@ describe "brightbox volumes detach" do
28
28
  it "does not error" do
29
29
  expect { output }.to_not raise_error
30
30
 
31
- expect(stderr).to eq("ERROR: You must specify volume IDs as arguments\n")
31
+ expect(stderr).to include("ERROR: You must specify volume IDs as arguments\n")
32
32
 
33
33
  expect(stdout).to match("")
34
34
  end
@@ -37,7 +37,7 @@ describe "brightbox volumes list" do
37
37
  it "does not error" do
38
38
  expect { output }.to_not raise_error
39
39
 
40
- expect(stderr).to eq("")
40
+ expect(stderr).to be_empty unless ENV["DEBUG"]
41
41
 
42
42
  aggregate_failures do
43
43
  expect(stdout).to match("id.*type.*size.*status.*server.*boot")
@@ -28,7 +28,7 @@ describe "brightbox volumes resize" do
28
28
  it "does not error" do
29
29
  expect { output }.to_not raise_error
30
30
 
31
- expect(stderr).to eq("ERROR: You must specify the volume ID as the first argument\n")
31
+ expect(stderr).to include("ERROR: You must specify the volume ID as the first argument\n")
32
32
 
33
33
  expect(stdout).to match("")
34
34
  end
@@ -40,7 +40,7 @@ describe "brightbox volumes resize" do
40
40
  it "does not error" do
41
41
  expect { output }.to_not raise_error
42
42
 
43
- expect(stderr).to eq("ERROR: A 'size' option is required\n")
43
+ expect(stderr).to include("ERROR: A 'size' option is required\n")
44
44
 
45
45
  expect(stdout).to match("")
46
46
  end
@@ -85,7 +85,7 @@ describe "brightbox volumes resize" do
85
85
  it "does not error" do
86
86
  expect { output }.to_not raise_error
87
87
 
88
- expect(stderr).to eq("Resizing vol-op324\n")
88
+ expect(stderr).to include("Resizing vol-op324\n")
89
89
 
90
90
  aggregate_failures do
91
91
  expect(stdout).to match("vol-op324")
@@ -8,45 +8,27 @@ describe "brightbox volumes show" do
8
8
  let(:stderr) { output.stderr }
9
9
 
10
10
  before do
11
- config_from_contents(API_CLIENT_CONFIG_CONTENTS)
12
-
13
- stub_request(:post, "http://api.brightbox.localhost/token")
14
- .to_return(
15
- status: 200,
16
- body: JSON.dump(
17
- access_token: "ACCESS-TOKEN",
18
- refresh_token: "REFRESH_TOKEN"
19
- )
20
- )
11
+ WebMock.reset!
21
12
 
13
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
14
+ stub_client_token_request
22
15
  Brightbox.config.reauthenticate
23
16
  end
24
17
 
25
18
  context "without arguments" do
26
19
  let(:argv) { %w[volumes show] }
27
20
 
28
- before do
29
- stub_request(:get, "http://api.brightbox.localhost/1.0/volumes")
30
- .with(query: hash_including(account_id: "acc-12345"))
31
- .to_return(
32
- status: 200,
33
- body: volumes_response
34
- )
35
- end
36
-
37
- it "does not error" do
21
+ it "reports missing IDs" do
38
22
  expect { output }.to_not raise_error
39
23
 
40
- expect(stderr).to eq("")
41
-
42
24
  aggregate_failures do
43
- expect(stdout).to match("id: vol-12345")
44
- expect(stdout).to match("id: vol-abcde")
25
+ expect(stderr).to match("ERROR: You must specify volume IDs to show")
26
+ expect(stdout).to be_empty
45
27
  end
46
28
  end
47
29
  end
48
30
 
49
- context "with identifier" do
31
+ context "with identifier argument" do
50
32
  let(:argv) { %w[volumes show vol-88878] }
51
33
 
52
34
  before do
@@ -92,4 +74,51 @@ describe "brightbox volumes show" do
92
74
  end
93
75
  end
94
76
  end
77
+
78
+ context "with multiple identifiers" do
79
+ let(:argv) { %w[volumes show vol-88878 vol-99999] }
80
+
81
+ before do
82
+ stub_request(:get, "http://api.brightbox.localhost/1.0/volumes/vol-88878")
83
+ .with(query: hash_including(account_id: "acc-12345"))
84
+ .to_return(
85
+ status: 200,
86
+ body: volume_response(
87
+ id: "vol-88878",
88
+ description: "A volume for testing",
89
+ filesystem_type: "ext4",
90
+ storage_type: "network",
91
+ size: 10_240,
92
+ status: "attached",
93
+ server: nil
94
+ )
95
+ )
96
+
97
+ stub_request(:get, "http://api.brightbox.localhost/1.0/volumes/vol-99999")
98
+ .with(query: hash_including(account_id: "acc-12345"))
99
+ .to_return(
100
+ status: 200,
101
+ body: volume_response(
102
+ id: "vol-99999",
103
+ description: "Another volume for testing",
104
+ filesystem_type: "ext4",
105
+ storage_type: "network",
106
+ size: 10_240,
107
+ status: "attached",
108
+ server: nil
109
+ )
110
+ )
111
+ end
112
+
113
+ it "does not error" do
114
+ expect { output }.to_not raise_error
115
+
116
+ expect(stderr).not_to match("ERROR")
117
+
118
+ aggregate_failures do
119
+ expect(stdout).to match("id: vol-88878")
120
+ expect(stdout).to match("id: vol-99999")
121
+ end
122
+ end
123
+ end
95
124
  end
@@ -28,7 +28,7 @@ describe "brightbox volumes update" do
28
28
  it "does not error" do
29
29
  expect { output }.to_not raise_error
30
30
 
31
- expect(stderr).to eq("ERROR: You must specify the volume ID as the first argument\n")
31
+ expect(stderr).to include("ERROR: You must specify the volume ID as the first argument\n")
32
32
 
33
33
  expect(stdout).to match("")
34
34
  end
@@ -82,7 +82,7 @@ describe "brightbox volumes update" do
82
82
  it "does not error" do
83
83
  expect { output }.to_not raise_error
84
84
 
85
- expect(stderr).to eq("Updating vol-908us\n")
85
+ expect(stderr).to include("Updating vol-908us\n")
86
86
 
87
87
  aggregate_failures do
88
88
  expect(stdout).to match("vol-908us")
@@ -129,7 +129,7 @@ describe "brightbox volumes update" do
129
129
  it "does not error" do
130
130
  expect { output }.to_not raise_error
131
131
 
132
- expect(stderr).to eq("Updating vol-kl234\n")
132
+ expect(stderr).to include("Updating vol-kl234\n")
133
133
 
134
134
  aggregate_failures do
135
135
  expect(stdout).to match("vol-kl234")
@@ -176,7 +176,7 @@ describe "brightbox volumes update" do
176
176
  it "does not error" do
177
177
  expect { output }.to_not raise_error
178
178
 
179
- expect(stderr).to eq("Updating vol-sdj2j\n")
179
+ expect(stderr).to include("Updating vol-sdj2j\n")
180
180
 
181
181
  aggregate_failures do
182
182
  expect(stdout).to match("vol-sdj2j")
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,22 @@
1
+ require "simplecov"
2
+
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ add_filter "/config/"
6
+ add_filter "/vendor/"
7
+
8
+ track_files "{lib}/**/*.rb"
9
+
10
+ # Currently just above 75% coverage - don't make it worse
11
+ minimum_coverage 75
12
+ refuse_coverage_drop
13
+ end
14
+
1
15
  LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
2
16
 
3
17
  $LOAD_PATH.unshift LIB_DIR unless
4
18
  $LOAD_PATH.include?(LIB_DIR) || $LOAD_PATH.include?(File.expand_path(LIB_DIR))
5
19
 
6
- require "simplecov"
7
20
  require "brightbox_cli"
8
21
  require "json"
9
22
  require "tmpdir"
@@ -31,15 +44,6 @@ Fog.timeout = 10
31
44
 
32
45
  require "fog/brightbox"
33
46
 
34
- SimpleCov.start do
35
- add_filter "/spec/"
36
- add_filter "/config/"
37
- add_filter "/vendor/"
38
- end
39
-
40
- # Currently just above 80% coverage - don't make it worse
41
- SimpleCov.minimum_coverage 80
42
-
43
47
  RSpec.configure do |config|
44
48
  config.include CommonHelpers
45
49
  config.include ConfigHelpers
@@ -9,7 +9,32 @@ shared_examples "a wrapped API resource" do
9
9
  it { is_expected.to respond_to(:to_row) }
10
10
 
11
11
  it { is_expected.to respond_to(:to_s) }
12
+
12
13
  it "#to_s equals the #id" do
13
14
  expect(subject.to_s).to eql(subject.id)
14
15
  end
16
+
17
+ # describe "#attributes" do
18
+ # subject { described_class.new(fog_model) }
19
+
20
+ # let(:fog_model) do
21
+ # double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
22
+ # end
23
+
24
+ # it "returns an IndifferentAccessHash" do
25
+ # expect(subject.attributes).to be_a(IndifferentAccessHash)
26
+ # end
27
+ # end
28
+
29
+ # describe "#to_row" do
30
+ # subject { described_class.new(fog_model) }
31
+
32
+ # let(:fog_model) do
33
+ # double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
34
+ # end
35
+
36
+ # it "returns a Hash to avoid hirb errors" do
37
+ # expect(subject.to_row).to be_a(Hash)
38
+ # end
39
+ # end
15
40
  end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Account, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Api, "#attributes" do
4
+ subject(:model_attributes) { api_model.attributes }
5
+
6
+ let(:api_model) { Brightbox::Api.new(fog_model) }
7
+ let(:fog_model) do
8
+ double(
9
+ "Fog::Compute::Brightbox::Api",
10
+ id: "res-12345",
11
+ attributes: attributes
12
+ )
13
+ end
14
+
15
+ context "when attributes are not set" do
16
+ let(:attributes) { nil }
17
+
18
+ it "returns an indifferent access hash" do
19
+ expect(model_attributes).to be_instance_of(IndifferentAccessHash)
20
+ end
21
+ end
22
+
23
+ context "when attributes are set with a mix of string and symbols" do
24
+ let(:attributes) do
25
+ {
26
+ id: "res-12345",
27
+ name: "test",
28
+ acme: acme_details
29
+ }
30
+ end
31
+ let(:acme_details) do
32
+ {
33
+ "domains" => [
34
+ {
35
+ "identifier" => "example.test",
36
+ "status" => "pending"
37
+ }
38
+ ]
39
+ }
40
+ end
41
+
42
+ it "transforms the keys with deep symbolize" do
43
+ expect(model_attributes).to eq(
44
+ id: "res-12345",
45
+ name: "test",
46
+ acme: {
47
+ domains: [
48
+ {
49
+ identifier: "example.test",
50
+ status: "pending"
51
+ }
52
+ ]
53
+ }
54
+ )
55
+ end
56
+
57
+ it "can accessed by string keys" do
58
+ expect(model_attributes["acme"]["domains"].first["identifier"]).to eq("example.test")
59
+ end
60
+
61
+ it "can accessed by symbol keys" do
62
+ expect(model_attributes[:acme][:domains].first[:identifier]).to eq("example.test")
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Api, "#fog_attributes" do
4
+ subject(:model_attributes) { api_model.fog_attributes }
5
+
6
+ let(:api_model) { Brightbox::Api.new(fog_model) }
7
+ let(:fog_model) do
8
+ double(
9
+ "Fog::Compute::Brightbox::Api",
10
+ id: "res-12345",
11
+ attributes: attributes
12
+ )
13
+ end
14
+
15
+ context "when attributes are not set" do
16
+ let(:attributes) { nil }
17
+
18
+ it "returns an indifferent access hash" do
19
+ expect(model_attributes).to be_instance_of(IndifferentAccessHash)
20
+ end
21
+ end
22
+
23
+ context "when attributes are set with a mix of string and symbols" do
24
+ let(:attributes) do
25
+ {
26
+ id: "res-12345",
27
+ name: "test",
28
+ acme: acme_details
29
+ }
30
+ end
31
+ let(:acme_details) do
32
+ {
33
+ "domains" => [
34
+ {
35
+ "identifier" => "example.test",
36
+ "status" => "pending"
37
+ }
38
+ ]
39
+ }
40
+ end
41
+
42
+ it "transforms the keys with deep symbolize" do
43
+ expect(model_attributes).to eq(
44
+ id: "res-12345",
45
+ name: "test",
46
+ acme: {
47
+ domains: [
48
+ {
49
+ identifier: "example.test",
50
+ status: "pending"
51
+ }
52
+ ]
53
+ }
54
+ )
55
+ end
56
+
57
+ it "can not accessed by string keys" do
58
+ expect(model_attributes["acme"]["domains"].first["identifier"]).to eq("example.test")
59
+ end
60
+
61
+ it "can accessed by symbol keys" do
62
+ expect(model_attributes[:acme][:domains].first[:identifier]).to eq("example.test")
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::CloudIP, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "cip-12345",
10
+ destination_id: nil,
11
+ attributes: model_attributes
12
+ )
13
+ end
14
+ let(:model_attributes) { { id: "cip-12345" } }
15
+
16
+ it "returns an IndifferentAccessHash" do
17
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::CollaboratingAccount, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::DatabaseServer, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::DatabaseSnapshot, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end