brightbox-cli 5.0.0.alpha → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -1
  3. data/CHANGELOG.md +60 -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/lbs/create.rb +0 -2
  10. data/lib/brightbox-cli/commands/lbs/show.rb +4 -0
  11. data/lib/brightbox-cli/config.rb +10 -4
  12. data/lib/brightbox-cli/database_server.rb +20 -20
  13. data/lib/brightbox-cli/database_snapshot.rb +5 -5
  14. data/lib/brightbox-cli/database_type.rb +4 -8
  15. data/lib/brightbox-cli/detailed_server.rb +26 -28
  16. data/lib/brightbox-cli/detailed_server_group.rb +2 -2
  17. data/lib/brightbox-cli/firewall_policy.rb +5 -9
  18. data/lib/brightbox-cli/firewall_rule.rb +14 -15
  19. data/lib/brightbox-cli/images.rb +22 -21
  20. data/lib/brightbox-cli/indifferent_access_hash.rb +50 -0
  21. data/lib/brightbox-cli/load_balancers.rb +27 -11
  22. data/lib/brightbox-cli/server_groups.rb +4 -8
  23. data/lib/brightbox-cli/servers.rb +22 -16
  24. data/lib/brightbox-cli/types.rb +4 -8
  25. data/lib/brightbox-cli/user_collaboration.rb +1 -1
  26. data/lib/brightbox-cli/users.rb +3 -5
  27. data/lib/brightbox-cli/version.rb +1 -1
  28. data/lib/brightbox-cli/volume.rb +9 -13
  29. data/lib/brightbox-cli/zones.rb +0 -4
  30. data/lib/brightbox_cli.rb +1 -0
  31. data/spec/commands/cloudips/update_spec.rb +7 -5
  32. data/spec/commands/configmaps/create_spec.rb +6 -6
  33. data/spec/commands/configmaps/destroy_spec.rb +1 -1
  34. data/spec/commands/configmaps/list_spec.rb +1 -1
  35. data/spec/commands/configmaps/show_spec.rb +3 -3
  36. data/spec/commands/configmaps/update_spec.rb +9 -9
  37. data/spec/commands/lbs/create_spec.rb +12 -26
  38. data/spec/commands/lbs/show_spec.rb +15 -3
  39. data/spec/commands/lbs/update_spec.rb +4 -4
  40. data/spec/commands/servers/update_spec.rb +7 -7
  41. data/spec/commands/sql/instances/create_spec.rb +8 -8
  42. data/spec/commands/sql/instances/reset_spec.rb +3 -3
  43. data/spec/commands/sql/instances/resize_spec.rb +4 -4
  44. data/spec/commands/sql/instances/show_spec.rb +2 -1
  45. data/spec/commands/sql/instances/update_spec.rb +3 -3
  46. data/spec/commands/sql/snapshots/list_spec.rb +1 -1
  47. data/spec/commands/sql/snapshots/show_spec.rb +50 -7
  48. data/spec/commands/volumes/attach_spec.rb +4 -4
  49. data/spec/commands/volumes/copy_spec.rb +2 -2
  50. data/spec/commands/volumes/destroy_spec.rb +1 -1
  51. data/spec/commands/volumes/detach_spec.rb +1 -1
  52. data/spec/commands/volumes/list_spec.rb +1 -1
  53. data/spec/commands/volumes/resize_spec.rb +3 -3
  54. data/spec/commands/volumes/show_spec.rb +1 -1
  55. data/spec/commands/volumes/update_spec.rb +4 -4
  56. data/spec/spec_helper.rb +14 -10
  57. data/spec/support/shared/api_resource_examples.rb +25 -0
  58. data/spec/unit/brightbox/account/attributes_spec.rb +13 -0
  59. data/spec/unit/brightbox/api/attributes_spec.rb +65 -0
  60. data/spec/unit/brightbox/api/fog_attributes_spec.rb +65 -0
  61. data/spec/unit/brightbox/cloud_ip/attributes_spec.rb +19 -0
  62. data/spec/unit/brightbox/collaborating_account/attributes_spec.rb +13 -0
  63. data/spec/unit/brightbox/database_server/attributes_spec.rb +13 -0
  64. data/spec/unit/brightbox/database_snapshot/attributes_spec.rb +13 -0
  65. data/spec/unit/brightbox/database_type/attributes_spec.rb +20 -0
  66. data/spec/unit/brightbox/detailed_server/attributes_spec.rb +29 -0
  67. data/spec/unit/brightbox/detailed_server_group/attributes_spec.rb +13 -0
  68. data/spec/unit/brightbox/firewall_policy/attributes_spec.rb +21 -0
  69. data/spec/unit/brightbox/firewall_rule/attributes_spec.rb +18 -0
  70. data/spec/unit/brightbox/image/attributes_spec.rb +13 -0
  71. data/spec/unit/brightbox/image/status_spec.rb +67 -0
  72. data/spec/unit/brightbox/load_balancer/acme_cert_spec.rb +75 -0
  73. data/spec/unit/brightbox/load_balancer/attributes_spec.rb +13 -0
  74. data/spec/unit/brightbox/load_balancer/formatted_acme_domains_spec.rb +78 -0
  75. data/spec/unit/brightbox/server/attributes_spec.rb +29 -0
  76. data/spec/unit/brightbox/server_group/attributes_spec.rb +13 -0
  77. data/spec/unit/brightbox/type/attributes_spec.rb +20 -0
  78. data/spec/unit/brightbox/user/attributes_spec.rb +13 -0
  79. data/spec/unit/brightbox/user_collaboration/attributes_spec.rb +13 -0
  80. metadata +47 -4
  81. data/spec/cassettes/brightbox_sql_snapshots/show/when_resource_exists/does_not_output_to_stderr.yml +0 -93
@@ -26,7 +26,7 @@ describe "brightbox servers update" do
26
26
  it "does not error" do
27
27
  expect { output }.to_not raise_error
28
28
 
29
- expect(stderr).to eq("ERROR: You must specify a valid server id as the first argument\n")
29
+ expect(stderr).to include("ERROR: You must specify a valid server id as the first argument\n")
30
30
 
31
31
  expect(stdout).to match("")
32
32
  end
@@ -66,7 +66,7 @@ describe "brightbox servers update" do
66
66
  it "does not error" do
67
67
  expect { output }.to_not raise_error
68
68
 
69
- expect(stderr).to eq("Updating server srv-klfkd\n")
69
+ expect(stderr).to include("Updating server srv-klfkd\n")
70
70
 
71
71
  expect(stdout).to match("srv-klfkd")
72
72
  end
@@ -104,7 +104,7 @@ describe "brightbox servers update" do
104
104
  it "does not error" do
105
105
  expect { output }.to_not raise_error
106
106
 
107
- expect(stderr).to eq("Updating server srv-ds321\n")
107
+ expect(stderr).to include("Updating server srv-ds321\n")
108
108
 
109
109
  expect(stdout).to match("srv-ds321")
110
110
  end
@@ -144,7 +144,7 @@ describe "brightbox servers update" do
144
144
  it "does not error" do
145
145
  expect { output }.to_not raise_error
146
146
 
147
- expect(stderr).to eq("Updating server srv-ds321\n")
147
+ expect(stderr).to include("Updating server srv-ds321\n")
148
148
 
149
149
  expect(stdout).to match("srv-ds321")
150
150
  end
@@ -184,7 +184,7 @@ describe "brightbox servers update" do
184
184
  it "does not error" do
185
185
  expect { output }.to_not raise_error
186
186
 
187
- expect(stderr).to eq("Updating server srv-ds321\n")
187
+ expect(stderr).to include("Updating server srv-ds321\n")
188
188
 
189
189
  expect(stdout).to match("srv-ds321")
190
190
  end
@@ -224,7 +224,7 @@ describe "brightbox servers update" do
224
224
  it "does not error" do
225
225
  expect { output }.to_not raise_error
226
226
 
227
- expect(stderr).to eq("Updating server srv-ds321 with 0.01k of user data\n")
227
+ expect(stderr).to include("Updating server srv-ds321 with 0.01k of user data\n")
228
228
 
229
229
  expect(stdout).to match("srv-ds321")
230
230
  end
@@ -264,7 +264,7 @@ describe "brightbox servers update" do
264
264
  it "does not error" do
265
265
  expect { output }.to_not raise_error
266
266
 
267
- expect(stderr).to eq("Updating server srv-ds321 with 0.00k of user data\n")
267
+ expect(stderr).to include("Updating server srv-ds321 with 0.00k of user data\n")
268
268
 
269
269
  expect(stdout).to match("srv-ds321")
270
270
  end
@@ -39,7 +39,7 @@ describe "brightbox sql instances" do
39
39
 
40
40
  it "correctly sends API parameters" do
41
41
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
42
- expect(stderr).to eq("")
42
+ expect(stderr).to be_empty unless ENV["DEBUG"]
43
43
  end
44
44
  end
45
45
 
@@ -55,7 +55,7 @@ describe "brightbox sql instances" do
55
55
 
56
56
  it "correctly sends API parameters" do
57
57
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
58
- expect(stderr).to eq("")
58
+ expect(stderr).to be_empty unless ENV["DEBUG"]
59
59
  end
60
60
 
61
61
  after do
@@ -69,7 +69,7 @@ describe "brightbox sql instances" do
69
69
 
70
70
  it "correctly sends API parameters" do
71
71
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
72
- expect(stderr).to eq("")
72
+ expect(stderr).to be_empty unless ENV["DEBUG"]
73
73
  expect(stdout).to include("version: 8.0")
74
74
  end
75
75
  end
@@ -80,7 +80,7 @@ describe "brightbox sql instances" do
80
80
 
81
81
  it "correctly sends API parameters" do
82
82
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
83
- expect(stderr).to eq("")
83
+ expect(stderr).to be_empty unless ENV["DEBUG"]
84
84
  expect(stdout).to include("version: 8.0")
85
85
  end
86
86
  end
@@ -91,7 +91,7 @@ describe "brightbox sql instances" do
91
91
 
92
92
  it "correctly sends API parameters" do
93
93
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
94
- expect(stderr).to eq("")
94
+ expect(stderr).to be_empty unless ENV["DEBUG"]
95
95
  end
96
96
  end
97
97
 
@@ -101,7 +101,7 @@ describe "brightbox sql instances" do
101
101
 
102
102
  it "correctly sends API parameters" do
103
103
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
104
- expect(stderr).to eq("")
104
+ expect(stderr).to be_empty unless ENV["DEBUG"]
105
105
  end
106
106
  end
107
107
 
@@ -124,7 +124,7 @@ describe "brightbox sql instances" do
124
124
  it "includes schedule fields in response" do
125
125
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
126
126
  expect(stdout).to include("id: #{sql_instance.id}")
127
- expect(stderr).to eq("")
127
+ expect(stderr).to be_empty unless ENV["DEBUG"]
128
128
  end
129
129
  end
130
130
 
@@ -136,7 +136,7 @@ describe "brightbox sql instances" do
136
136
  expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
137
137
  expect(stdout).to include("snapshots_schedule: 0 12 * * 4")
138
138
  expect(stdout).to match(/snapshots_schedule_next_at: 20\d{2}-\d{2}-\d{2}T12:\d{2}Z/)
139
- expect(stderr).to eq("")
139
+ expect(stderr).to be_empty unless ENV["DEBUG"]
140
140
  end
141
141
  end
142
142
  end
@@ -26,7 +26,7 @@ describe "brightbox sql instances reset" do
26
26
  it "does not error" do
27
27
  expect { output }.to_not raise_error
28
28
 
29
- expect(stderr).to eq("ERROR: You must specify a valid SQL instance ID as the first argument\n")
29
+ expect(stderr).to include("ERROR: You must specify a valid SQL instance ID as the first argument\n")
30
30
 
31
31
  expect(stdout).to match("")
32
32
  end
@@ -47,7 +47,7 @@ describe "brightbox sql instances reset" do
47
47
  it "does not error" do
48
48
  expect { output }.to_not raise_error
49
49
 
50
- expect(stderr).to eq("ERROR: Couldn't find 'dbs-l3kd4'\n")
50
+ expect(stderr).to include("ERROR: Couldn't find 'dbs-l3kd4'\n")
51
51
 
52
52
  expect(stdout).to match("")
53
53
  end
@@ -79,7 +79,7 @@ describe "brightbox sql instances reset" do
79
79
  it "does not error" do
80
80
  expect { output }.to_not raise_error
81
81
 
82
- expect(stderr).to eq("Resetting dbs-po953\n")
82
+ expect(stderr).to include("Resetting dbs-po953\n")
83
83
 
84
84
  expect(stdout).to match("dbs-po953")
85
85
  end
@@ -26,7 +26,7 @@ describe "brightbox sql instances resize" do
26
26
  it "does not error" do
27
27
  expect { output }.to_not raise_error
28
28
 
29
- expect(stderr).to eq("ERROR: You must specify a valid SQL instance ID as the first argument\n")
29
+ expect(stderr).to include("ERROR: You must specify a valid SQL instance ID as the first argument\n")
30
30
 
31
31
  expect(stdout).to match("")
32
32
  end
@@ -47,7 +47,7 @@ describe "brightbox sql instances resize" do
47
47
  it "does not error" do
48
48
  expect { output }.to_not raise_error
49
49
 
50
- expect(stderr).to eq("ERROR: Couldn't find 'dbs-xsd23'\n")
50
+ expect(stderr).to include("ERROR: Couldn't find 'dbs-xsd23'\n")
51
51
 
52
52
  expect(stdout).to match("")
53
53
  end
@@ -59,7 +59,7 @@ describe "brightbox sql instances resize" do
59
59
  it "does not error" do
60
60
  expect { output }.to_not raise_error
61
61
 
62
- expect(stderr).to eq("ERROR: Cloud SQL type format is invalid\n")
62
+ expect(stderr).to include("ERROR: Cloud SQL type format is invalid\n")
63
63
 
64
64
  expect(stdout).to match("")
65
65
  end
@@ -104,7 +104,7 @@ describe "brightbox sql instances resize" do
104
104
  it "does not error" do
105
105
  expect { output }.to_not raise_error
106
106
 
107
- expect(stderr).to eq("Resizing dbs-zzasa\n")
107
+ expect(stderr).to include("Resizing dbs-zzasa\n")
108
108
 
109
109
  expect(stdout).to match("dbs-zzasa")
110
110
  end
@@ -66,8 +66,9 @@ describe "brightbox sql instances" do
66
66
  end
67
67
 
68
68
  it "simplifies the maintenance window" do
69
+ expect(stderr).to be_empty unless ENV["DEBUG"]
70
+
69
71
  expect(stdout).to include("maintenance_window: Sunday 06:00 UTC")
70
- expect(stderr).to be_empty
71
72
  end
72
73
 
73
74
  it "includes snapshots schedule fields" do
@@ -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,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