brightbox-cli 4.3.2 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,342 @@
1
+ require "spec_helper"
2
+ require "tempfile"
3
+
4
+ describe "brightbox configmaps update" do
5
+ let(:output) { FauxIO.new { Brightbox.run(argv) } }
6
+ let(:stdout) { output.stdout }
7
+ let(:stderr) { output.stderr }
8
+
9
+ before do
10
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
11
+
12
+ stub_request(:post, "http://api.brightbox.localhost/token")
13
+ .to_return(
14
+ status: 200,
15
+ body: JSON.dump(
16
+ access_token: "ACCESS-TOKEN",
17
+ refresh_token: "REFRESH_TOKEN"
18
+ )
19
+ )
20
+
21
+ Brightbox.config.reauthenticate
22
+ end
23
+
24
+ context "without arguments" do
25
+ let(:argv) { %w[configmaps update] }
26
+
27
+ it "does not error" do
28
+ expect { output }.to_not raise_error
29
+
30
+ expect(stderr).to eq("ERROR: You must specify the config map ID as the first argument\n")
31
+
32
+ expect(stdout).to match("")
33
+ end
34
+ end
35
+
36
+ context "with new name" do
37
+ let(:argv) { %w[configmaps update --name New cfg-0932s] }
38
+
39
+ before do
40
+ stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-0932s")
41
+ .with(query: hash_including(account_id: "acc-12345"))
42
+ .to_return(
43
+ status: 200,
44
+ body: {
45
+ id: "cfg-0932s",
46
+ name: "Old"
47
+ }.to_json
48
+ )
49
+ .to_return(
50
+ status: 200,
51
+ body: {
52
+ id: "cfg-0932s",
53
+ name: "New",
54
+ data: {}
55
+ }.to_json
56
+ )
57
+
58
+ stub_request(:put, "http://api.brightbox.localhost/1.0/config_maps/cfg-0932s")
59
+ .with(query: hash_including(account_id: "acc-12345"),
60
+ body: {
61
+ name: "New"
62
+ })
63
+ .to_return(
64
+ status: 200,
65
+ body: {
66
+ id: "cfg-0932s",
67
+ name: "New",
68
+ data: {}
69
+ }.to_json
70
+ )
71
+ end
72
+
73
+ it "does not error" do
74
+ expect { output }.to_not raise_error
75
+
76
+ expect(stderr).to eq("Updating cfg-0932s\n")
77
+
78
+ aggregate_failures do
79
+ expect(stdout).to match("cfg-0932s")
80
+ expect(stdout).to match("New")
81
+ end
82
+ end
83
+ end
84
+
85
+ context "with new map from 'data'" do
86
+ let(:argv) { ["configmaps", "update", "--data", payload, "cfg-25hrt"] }
87
+
88
+ context "with valid update" do
89
+ let(:payload) { { new_key: "new value" }.to_json }
90
+
91
+ before do
92
+ stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-25hrt")
93
+ .with(query: hash_including(account_id: "acc-12345"))
94
+ .to_return(
95
+ status: 200,
96
+ body: {
97
+ id: "cfg-25hrt",
98
+ name: "",
99
+ data: {
100
+ old_key: "old value"
101
+ }
102
+ }.to_json
103
+ )
104
+ .to_return(
105
+ status: 200,
106
+ body: {
107
+ id: "cfg-25hrt",
108
+ name: "",
109
+ data: {
110
+ new_key: "new value"
111
+ }
112
+ }.to_json
113
+ )
114
+
115
+ stub_request(:put, "http://api.brightbox.localhost/1.0/config_maps/cfg-25hrt")
116
+ .with(query: hash_including(account_id: "acc-12345"),
117
+ body: {
118
+ data: {
119
+ new_key: "new value"
120
+ }
121
+ })
122
+ .to_return(
123
+ status: 200,
124
+ body: {
125
+ id: "cfg-25hrt",
126
+ name: "",
127
+ data: {
128
+ new_key: "new value"
129
+ }
130
+ }.to_json
131
+ )
132
+ end
133
+
134
+ it "does not error" do
135
+ expect { output }.to_not raise_error
136
+
137
+ expect(stderr).to eq("Updating cfg-25hrt\n")
138
+
139
+ aggregate_failures do
140
+ expect(stdout).to match("cfg-25hrt")
141
+ end
142
+ end
143
+ end
144
+
145
+ context "with invalid update" do
146
+ let(:payload) { "Not JSON!" }
147
+
148
+ it "does not error" do
149
+ expect { output }.to_not raise_error
150
+
151
+ expect(stderr).to eq("ERROR: Config map data was not valid JSON\n")
152
+
153
+ expect(stdout).to eq("")
154
+ end
155
+ end
156
+ end
157
+
158
+ context "with new map from 'data-file'" do
159
+ context "when filename is used" do
160
+ let(:argv) { ["configmaps", "update", "--data-file", data_file.path, "cfg-gr45a"] }
161
+ let(:data_file) { Tempfile.open("config_map_test_data") }
162
+
163
+ around do |example|
164
+ data_file.write(payload)
165
+ data_file.close
166
+
167
+ example.run
168
+
169
+ data_file.unlink
170
+ end
171
+
172
+ context "with valid update" do
173
+ let(:payload) { { new_key: "new setting" }.to_json }
174
+
175
+ before do
176
+ stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-gr45a")
177
+ .with(query: hash_including(account_id: "acc-12345"))
178
+ .to_return(
179
+ status: 200,
180
+ body: {
181
+ id: "cfg-gr45a",
182
+ name: "",
183
+ data: {
184
+ old_key: "old setting"
185
+ }
186
+ }.to_json
187
+ )
188
+ .to_return(
189
+ status: 200,
190
+ body: {
191
+ id: "cfg-gr45a",
192
+ name: "",
193
+ data: {
194
+ new_key: "new setting"
195
+ }
196
+ }.to_json
197
+ )
198
+
199
+ stub_request(:put, "http://api.brightbox.localhost/1.0/config_maps/cfg-gr45a")
200
+ .with(query: hash_including(account_id: "acc-12345"),
201
+ body: {
202
+ data: {
203
+ new_key: "new setting"
204
+ }
205
+ })
206
+ .to_return(
207
+ status: 200,
208
+ body: {
209
+ id: "cfg-gr45a",
210
+ name: "",
211
+ data: {
212
+ new_key: "new setting"
213
+ }
214
+ }.to_json
215
+ )
216
+ end
217
+
218
+ it "does not error" do
219
+ expect { output }.to_not raise_error
220
+
221
+ expect(stderr).to eq("Updating cfg-gr45a\n")
222
+
223
+ aggregate_failures do
224
+ expect(stdout).to match("cfg-gr45a")
225
+ end
226
+ end
227
+
228
+ context "with invalid update" do
229
+ let(:payload) { "Not JSON!" }
230
+
231
+ it "does not error" do
232
+ expect { output }.to_not raise_error
233
+
234
+ expect(stderr).to eq("ERROR: Config map data was not valid JSON\n")
235
+
236
+ expect(stdout).to eq("")
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ context "when '-' is used for STDIN" do
243
+ let(:argv) { ["configmaps", "update", "--data-file", "-", "cfg-stdin"] }
244
+
245
+ before do
246
+ stdin_data = StringIO.new
247
+ stdin_data.puts(payload)
248
+ stdin_data.rewind
249
+
250
+ $stdin = stdin_data
251
+ end
252
+
253
+ after do
254
+ $stdin = STDIN
255
+ end
256
+
257
+ context "with valid update" do
258
+ let(:payload) { { use_stdin: true }.to_json }
259
+
260
+ before do
261
+ stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-stdin")
262
+ .with(query: hash_including(account_id: "acc-12345"))
263
+ .to_return(
264
+ status: 200,
265
+ body: {
266
+ id: "cfg-stdin",
267
+ name: "",
268
+ data: {
269
+ use_stdin: true
270
+ }
271
+ }.to_json
272
+ )
273
+ .to_return(
274
+ status: 200,
275
+ body: {
276
+ id: "cfg-stdin",
277
+ name: "",
278
+ data: {
279
+ use_stdin: true
280
+ }
281
+ }.to_json
282
+ )
283
+
284
+ stub_request(:put, "http://api.brightbox.localhost/1.0/config_maps/cfg-stdin")
285
+ .with(query: hash_including(account_id: "acc-12345"),
286
+ body: {
287
+ data: {
288
+ use_stdin: true
289
+ }
290
+ })
291
+ .to_return(
292
+ status: 200,
293
+ body: {
294
+ id: "cfg-stdin",
295
+ name: "",
296
+ data: {
297
+ use_stdin: true
298
+ }
299
+ }.to_json
300
+ )
301
+ end
302
+
303
+ it "does not error" do
304
+ expect { output }.to_not raise_error
305
+
306
+ expect(stderr).to eq("Updating cfg-stdin\n")
307
+
308
+ aggregate_failures do
309
+ expect(stdout).to match("cfg-stdin")
310
+ end
311
+ end
312
+
313
+ context "with invalid update" do
314
+ let(:payload) { "Not JSON!" }
315
+
316
+ it "does not error" do
317
+ expect { output }.to_not raise_error
318
+
319
+ expect(stderr).to eq("ERROR: Config map data was not valid JSON\n")
320
+
321
+ expect(stdout).to eq("")
322
+ end
323
+ end
324
+ end
325
+ end
326
+
327
+ context "with mutually exclusive data options" do
328
+ let(:argv) { ["configmaps", "update", "--data", payload, "--data-file", "-", "cfg-25hrt"] }
329
+ let(:payload) { { new_key: "new value" }.to_json }
330
+
331
+ context "with invalid update" do
332
+ it "does not error" do
333
+ expect { output }.to_not raise_error
334
+
335
+ expect(stderr).to eq("ERROR: Config map data can only be passed by either 'data' or 'data-file'\n")
336
+
337
+ expect(stdout).to eq("")
338
+ end
339
+ end
340
+ end
341
+ end
342
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbox-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.2
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Leach
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 1.9.1
20
+ version: 1.10.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 1.9.1
27
+ version: 1.10.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: fog-core
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -318,6 +318,7 @@ files:
318
318
  - lib/brightbox-cli/commands/config/client_list.rb
319
319
  - lib/brightbox-cli/commands/config/client_remove.rb
320
320
  - lib/brightbox-cli/commands/config/user_add.rb
321
+ - lib/brightbox-cli/commands/configmaps.rb
321
322
  - lib/brightbox-cli/commands/firewall/policies_apply.rb
322
323
  - lib/brightbox-cli/commands/firewall/policies_create.rb
323
324
  - lib/brightbox-cli/commands/firewall/policies_destroy.rb
@@ -412,6 +413,7 @@ files:
412
413
  - lib/brightbox-cli/config/two_factor_auth.rb
413
414
  - lib/brightbox-cli/config/two_factor_helper.rb
414
415
  - lib/brightbox-cli/config/user_application.rb
416
+ - lib/brightbox-cli/config_map.rb
415
417
  - lib/brightbox-cli/connection_manager.rb
416
418
  - lib/brightbox-cli/database_server.rb
417
419
  - lib/brightbox-cli/database_snapshot.rb
@@ -598,6 +600,11 @@ files:
598
600
  - spec/commands/config/client_list_spec.rb
599
601
  - spec/commands/config/client_remove_spec.rb
600
602
  - spec/commands/config/user_add_spec.rb
603
+ - spec/commands/configmaps/create_spec.rb
604
+ - spec/commands/configmaps/destroy_spec.rb
605
+ - spec/commands/configmaps/list_spec.rb
606
+ - spec/commands/configmaps/show_spec.rb
607
+ - spec/commands/configmaps/update_spec.rb
601
608
  - spec/commands/firewall_policies/update_spec.rb
602
609
  - spec/commands/groups/add_server_spec.rb
603
610
  - spec/commands/groups/create_spec.rb
@@ -960,6 +967,11 @@ test_files:
960
967
  - spec/commands/config/client_list_spec.rb
961
968
  - spec/commands/config/client_remove_spec.rb
962
969
  - spec/commands/config/user_add_spec.rb
970
+ - spec/commands/configmaps/create_spec.rb
971
+ - spec/commands/configmaps/destroy_spec.rb
972
+ - spec/commands/configmaps/list_spec.rb
973
+ - spec/commands/configmaps/show_spec.rb
974
+ - spec/commands/configmaps/update_spec.rb
963
975
  - spec/commands/firewall_policies/update_spec.rb
964
976
  - spec/commands/groups/add_server_spec.rb
965
977
  - spec/commands/groups/create_spec.rb