brightbox-cli 4.8.0 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +6 -2
  3. data/CHANGELOG.md +60 -0
  4. data/Gemfile.lock +17 -10
  5. data/brightbox-cli.gemspec +3 -7
  6. data/lib/brightbox-cli/accounts.rb +5 -1
  7. data/lib/brightbox-cli/api.rb +34 -1
  8. data/lib/brightbox-cli/cloud_ips.rb +6 -6
  9. data/lib/brightbox-cli/collaboration.rb +3 -7
  10. data/lib/brightbox-cli/commands/cloudips/unmap.rb +1 -1
  11. data/lib/brightbox-cli/commands/firewall/policies_apply.rb +1 -1
  12. data/lib/brightbox-cli/commands/firewall/policies_create.rb +1 -1
  13. data/lib/brightbox-cli/commands/firewall/policies_destroy.rb +1 -1
  14. data/lib/brightbox-cli/commands/firewall/policies_list.rb +1 -1
  15. data/lib/brightbox-cli/commands/firewall/policies_remove.rb +1 -1
  16. data/lib/brightbox-cli/commands/firewall/policies_show.rb +1 -1
  17. data/lib/brightbox-cli/commands/firewall/policies_update.rb +1 -1
  18. data/lib/brightbox-cli/commands/lbs/create.rb +28 -16
  19. data/lib/brightbox-cli/commands/lbs/show.rb +5 -0
  20. data/lib/brightbox-cli/commands/lbs/update.rb +9 -2
  21. data/lib/brightbox-cli/config.rb +12 -5
  22. data/lib/brightbox-cli/database_server.rb +20 -20
  23. data/lib/brightbox-cli/database_snapshot.rb +5 -5
  24. data/lib/brightbox-cli/database_type.rb +4 -8
  25. data/lib/brightbox-cli/detailed_server.rb +26 -28
  26. data/lib/brightbox-cli/detailed_server_group.rb +2 -2
  27. data/lib/brightbox-cli/firewall_policy.rb +5 -9
  28. data/lib/brightbox-cli/firewall_rule.rb +14 -15
  29. data/lib/brightbox-cli/images.rb +21 -20
  30. data/lib/brightbox-cli/indifferent_access_hash.rb +50 -0
  31. data/lib/brightbox-cli/load_balancers.rb +38 -4
  32. data/lib/brightbox-cli/server_groups.rb +4 -8
  33. data/lib/brightbox-cli/servers.rb +22 -16
  34. data/lib/brightbox-cli/types.rb +4 -8
  35. data/lib/brightbox-cli/user_collaboration.rb +1 -1
  36. data/lib/brightbox-cli/users.rb +3 -5
  37. data/lib/brightbox-cli/version.rb +1 -1
  38. data/lib/brightbox-cli/volume.rb +9 -13
  39. data/lib/brightbox-cli/zones.rb +0 -4
  40. data/lib/brightbox_cli.rb +1 -0
  41. data/spec/commands/cloudips/update_spec.rb +7 -5
  42. data/spec/commands/configmaps/create_spec.rb +6 -6
  43. data/spec/commands/configmaps/destroy_spec.rb +1 -1
  44. data/spec/commands/configmaps/list_spec.rb +1 -1
  45. data/spec/commands/configmaps/show_spec.rb +3 -3
  46. data/spec/commands/configmaps/update_spec.rb +9 -9
  47. data/spec/commands/lbs/create_spec.rb +158 -6
  48. data/spec/commands/lbs/show_spec.rb +99 -3
  49. data/spec/commands/lbs/update_spec.rb +50 -6
  50. data/spec/commands/servers/update_spec.rb +7 -7
  51. data/spec/commands/sql/instances/create_spec.rb +8 -8
  52. data/spec/commands/sql/instances/reset_spec.rb +3 -3
  53. data/spec/commands/sql/instances/resize_spec.rb +4 -4
  54. data/spec/commands/sql/instances/show_spec.rb +2 -1
  55. data/spec/commands/sql/instances/update_spec.rb +3 -3
  56. data/spec/commands/sql/snapshots/list_spec.rb +1 -1
  57. data/spec/commands/sql/snapshots/show_spec.rb +50 -7
  58. data/spec/commands/volumes/attach_spec.rb +4 -4
  59. data/spec/commands/volumes/copy_spec.rb +2 -2
  60. data/spec/commands/volumes/destroy_spec.rb +1 -1
  61. data/spec/commands/volumes/detach_spec.rb +1 -1
  62. data/spec/commands/volumes/list_spec.rb +1 -1
  63. data/spec/commands/volumes/resize_spec.rb +3 -3
  64. data/spec/commands/volumes/show_spec.rb +1 -1
  65. data/spec/commands/volumes/update_spec.rb +4 -4
  66. data/spec/spec_helper.rb +16 -0
  67. data/spec/support/shared/api_resource_examples.rb +25 -0
  68. data/spec/unit/brightbox/account/attributes_spec.rb +13 -0
  69. data/spec/unit/brightbox/api/attributes_spec.rb +65 -0
  70. data/spec/unit/brightbox/api/fog_attributes_spec.rb +65 -0
  71. data/spec/unit/brightbox/bb_config/config_directory_spec.rb +23 -3
  72. data/spec/unit/brightbox/cloud_ip/attributes_spec.rb +19 -0
  73. data/spec/unit/brightbox/collaborating_account/attributes_spec.rb +13 -0
  74. data/spec/unit/brightbox/database_server/attributes_spec.rb +13 -0
  75. data/spec/unit/brightbox/database_snapshot/attributes_spec.rb +13 -0
  76. data/spec/unit/brightbox/database_type/attributes_spec.rb +20 -0
  77. data/spec/unit/brightbox/detailed_server/attributes_spec.rb +29 -0
  78. data/spec/unit/brightbox/detailed_server_group/attributes_spec.rb +13 -0
  79. data/spec/unit/brightbox/firewall_policy/attributes_spec.rb +21 -0
  80. data/spec/unit/brightbox/firewall_rule/attributes_spec.rb +18 -0
  81. data/spec/unit/brightbox/image/attributes_spec.rb +13 -0
  82. data/spec/unit/brightbox/image/status_spec.rb +67 -0
  83. data/spec/unit/brightbox/load_balancer/acme_cert_spec.rb +75 -0
  84. data/spec/unit/brightbox/load_balancer/attributes_spec.rb +13 -0
  85. data/spec/unit/brightbox/load_balancer/formatted_acme_domains_spec.rb +78 -0
  86. data/spec/unit/brightbox/server/attributes_spec.rb +29 -0
  87. data/spec/unit/brightbox/server/hostname_spec.rb +27 -0
  88. data/spec/unit/brightbox/server_group/attributes_spec.rb +13 -0
  89. data/spec/unit/brightbox/type/attributes_spec.rb +20 -0
  90. data/spec/unit/brightbox/user/attributes_spec.rb +13 -0
  91. data/spec/unit/brightbox/user_collaboration/attributes_spec.rb +13 -0
  92. metadata +68 -23
  93. data/spec/cassettes/brightbox_sql_snapshots/show/when_resource_exists/does_not_output_to_stderr.yml +0 -93
@@ -30,7 +30,7 @@ describe "brightbox sql instances" do
30
30
  end
31
31
 
32
32
  it "sets custom maintenance window settings" do
33
- expect(stderr).to eql("Updating dbs-12345\n")
33
+ expect(stderr).to include("Updating dbs-12345\n")
34
34
  expect(stdout).to include("dbs-12345")
35
35
  end
36
36
  end
@@ -54,7 +54,7 @@ describe "brightbox sql instances" do
54
54
  expect(Brightbox::DatabaseServer).to receive(:find).and_return(dbs)
55
55
  expect(dbs).to receive(:update).with(expected_args).and_call_original
56
56
 
57
- expect(stderr).to eq("Updating dbs-12345\n")
57
+ expect(stderr).to include("Updating dbs-12345\n")
58
58
  expect(stdout).to include("dbs-12345")
59
59
  end
60
60
  end
@@ -78,7 +78,7 @@ describe "brightbox sql instances" do
78
78
  expect(Brightbox::DatabaseServer).to receive(:find).and_return(dbs)
79
79
  expect(dbs).to receive(:update).with(expected_args).and_call_original
80
80
 
81
- expect(stderr).to eq("Updating dbs-432sf\n")
81
+ expect(stderr).to include("Updating dbs-432sf\n")
82
82
  expect(stdout).to include("dbs-432sf")
83
83
  end
84
84
  end
@@ -17,7 +17,7 @@ describe "brightbox sql snapshots" do
17
17
  let(:argv) { %w[sql snapshots list] }
18
18
 
19
19
  it "does not output to stderr" do
20
- expect(stderr).to eql("")
20
+ expect(stderr).to be_empty unless ENV["DEBUG"]
21
21
  end
22
22
 
23
23
  it "outputs table details to stdout" do
@@ -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
@@ -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")
@@ -37,7 +37,7 @@ describe "brightbox volumes show" 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: vol-12345")
@@ -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,3 +1,17 @@
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
@@ -28,6 +42,8 @@ TEST_RUNNER_HOME = ENV.fetch("HOME", nil)
28
42
  # Reduce the default fog timeout
29
43
  Fog.timeout = 10
30
44
 
45
+ require "fog/brightbox"
46
+
31
47
  RSpec.configure do |config|
32
48
  config.include CommonHelpers
33
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
@@ -2,25 +2,45 @@ require "spec_helper"
2
2
 
3
3
  describe Brightbox::BBConfig do
4
4
  describe "#config_directory" do
5
+ context "when HOME is not set" do
6
+ let(:working_dir) { Dir.mktmpdir("working") }
7
+
8
+ before do
9
+ allow(Dir).to receive(:pwd).and_return(working_dir)
10
+ allow(ENV).to receive(:fetch).with("HOME", nil).and_return(nil)
11
+ end
12
+
13
+ it "returns current directory" do
14
+ config = Brightbox::BBConfig.new
15
+
16
+ expect(config.config_directory).to start_with(working_dir)
17
+ expect(config.config_directory).to end_with(".brightbox")
18
+ end
19
+ end
20
+
5
21
  context "when default location is used" do
6
22
  it "returns a String of the users `.brightbox` directory" do
7
23
  config = Brightbox::BBConfig.new
8
24
 
9
25
  expanded_path = File.expand_path("~/.brightbox")
10
- expect(config.config_directory).to eql(expanded_path)
26
+ expect(config.config_directory).to eq(expanded_path)
11
27
  end
12
28
  end
13
29
 
14
30
  context "when absolute custom location is set" do
15
31
  let(:custom_dir) { Dir.mktmpdir("custom") }
16
32
 
33
+ after do
34
+ FileUtils.rm_rf(custom_dir)
35
+ end
36
+
17
37
  it "returns a String of the expanded directory" do
18
38
  config_options = {
19
39
  :directory => custom_dir
20
40
  }
21
41
  config = Brightbox::BBConfig.new(config_options)
22
42
 
23
- expect(config.config_directory).to eql(custom_dir)
43
+ expect(config.config_directory).to eq(custom_dir)
24
44
  end
25
45
  end
26
46
 
@@ -32,7 +52,7 @@ describe Brightbox::BBConfig do
32
52
  config = Brightbox::BBConfig.new(config_options)
33
53
 
34
54
  expanded_path = File.expand_path("~/.cli_config")
35
- expect(config.config_directory).to eql(expanded_path)
55
+ expect(config.config_directory).to eq(expanded_path)
36
56
  end
37
57
  end
38
58
  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
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::DatabaseType, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "typ-12345",
10
+ attributes: model_attributes,
11
+ ram: 1024,
12
+ disk: 10_240,
13
+ )
14
+ end
15
+ let(:model_attributes) { { id: "typ-12345" } }
16
+
17
+ it "returns an IndifferentAccessHash" do
18
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::DetailedServer, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "srv-12345",
10
+ attributes: model_attributes,
11
+ cloud_ips: [],
12
+ created_at: Time.parse("2025-01-01T12:00:00Z"),
13
+ created_on: "2025-01-01",
14
+ hostname: "srv-12345.gb1.brightbox.com",
15
+ image_id: "img-12345",
16
+ interfaces: [],
17
+ locked?: false,
18
+ type: "typ-12345",
19
+ state: "active",
20
+ server_type: "typ-12345",
21
+ zone: { id: "zon-12345", handle: "gb1-a" }
22
+ )
23
+ end
24
+ let(:model_attributes) { { id: "srv-12345" } }
25
+
26
+ it "returns an IndifferentAccessHash" do
27
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::DetailedServerGroup, "#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