brightbox-cli 4.3.2 → 4.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +5 -5
- data/brightbox-cli.gemspec +1 -1
- data/lib/brightbox-cli/commands/configmaps.rb +183 -0
- data/lib/brightbox-cli/commands/sql/instances_reset.rb +33 -0
- data/lib/brightbox-cli/commands/sql/instances_resize.rb +42 -0
- data/lib/brightbox-cli/config_map.rb +53 -0
- data/lib/brightbox-cli/database_server.rb +8 -0
- data/lib/brightbox-cli/version.rb +1 -1
- data/lib/brightbox_cli.rb +1 -0
- data/locales/en.yml +50 -0
- data/spec/commands/configmaps/create_spec.rb +257 -0
- data/spec/commands/configmaps/destroy_spec.rb +156 -0
- data/spec/commands/configmaps/list_spec.rb +96 -0
- data/spec/commands/configmaps/show_spec.rb +236 -0
- data/spec/commands/configmaps/update_spec.rb +342 -0
- data/spec/commands/sql/instances/reset_spec.rb +87 -0
- data/spec/commands/sql/instances/resize_spec.rb +112 -0
- metadata +23 -5
@@ -0,0 +1,236 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "brightbox configmaps show" do
|
4
|
+
let(:output) { FauxIO.new { Brightbox.run(argv) } }
|
5
|
+
let(:stdout) { output.stdout }
|
6
|
+
let(:stderr) { output.stderr }
|
7
|
+
|
8
|
+
before do
|
9
|
+
config_from_contents(API_CLIENT_CONFIG_CONTENTS)
|
10
|
+
|
11
|
+
stub_request(:post, "http://api.brightbox.localhost/token")
|
12
|
+
.to_return(
|
13
|
+
status: 200,
|
14
|
+
body: JSON.dump(
|
15
|
+
access_token: "ACCESS-TOKEN",
|
16
|
+
refresh_token: "REFRESH_TOKEN"
|
17
|
+
)
|
18
|
+
)
|
19
|
+
|
20
|
+
Brightbox.config.reauthenticate
|
21
|
+
end
|
22
|
+
|
23
|
+
context "without arguments" do
|
24
|
+
let(:argv) { %w[configmaps show] }
|
25
|
+
|
26
|
+
before do
|
27
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps")
|
28
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
29
|
+
.to_return(
|
30
|
+
status: 200,
|
31
|
+
body: config_maps_response
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does not error" do
|
36
|
+
expect { output }.to_not raise_error
|
37
|
+
|
38
|
+
expect(stderr).to eq("")
|
39
|
+
|
40
|
+
aggregate_failures do
|
41
|
+
expect(stdout).to match("id: cfg-12345")
|
42
|
+
expect(stdout).to match("id: cfg-abcde")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with identifier" do
|
48
|
+
let(:argv) { %w[configmaps show cfg-lk432] }
|
49
|
+
|
50
|
+
before do
|
51
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-lk432")
|
52
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
53
|
+
.to_return(
|
54
|
+
status: 200,
|
55
|
+
body: {
|
56
|
+
id: "cfg-lk432",
|
57
|
+
name: "Staging Config Example",
|
58
|
+
data: {
|
59
|
+
key: "value"
|
60
|
+
}
|
61
|
+
}.to_json
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "does not error" do
|
66
|
+
expect { output }.to_not raise_error
|
67
|
+
|
68
|
+
expect(stderr).not_to match("ERROR")
|
69
|
+
|
70
|
+
aggregate_failures do
|
71
|
+
expect(stdout).to match("id: cfg-lk432")
|
72
|
+
expect(stdout).to match("name: Staging Config Example")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with '--data' output" do
|
78
|
+
context "with multiple IDs" do
|
79
|
+
let(:argv) { %w[configmaps show --data cfg-m543s cfg-klds4] }
|
80
|
+
|
81
|
+
it "does not error" do
|
82
|
+
expect { output }.to_not raise_error
|
83
|
+
|
84
|
+
expect(stderr).to eq("ERROR: You can only access data for a single config map at a time\n")
|
85
|
+
|
86
|
+
expect(stdout).to eq("")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "without '--format'" do
|
91
|
+
let(:argv) { %w[configmaps show --data cfg-xd3d4] }
|
92
|
+
|
93
|
+
before do
|
94
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-xd3d4")
|
95
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
96
|
+
.to_return(
|
97
|
+
status: 200,
|
98
|
+
body: {
|
99
|
+
id: "cfg-lk432",
|
100
|
+
name: "Staging Config Example",
|
101
|
+
data: {
|
102
|
+
key: "value",
|
103
|
+
name: "key name"
|
104
|
+
}
|
105
|
+
}.to_json
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "does not error" do
|
110
|
+
expect { output }.to_not raise_error
|
111
|
+
|
112
|
+
expect(stderr).not_to match("ERROR")
|
113
|
+
|
114
|
+
expect(stdout).to eq(%({"key":"value","name":"key name"}\n))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "with '--format json'" do
|
119
|
+
let(:argv) { %w[configmaps show --data --format json cfg-xd3d4] }
|
120
|
+
|
121
|
+
before do
|
122
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-xd3d4")
|
123
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
124
|
+
.to_return(
|
125
|
+
status: 200,
|
126
|
+
body: {
|
127
|
+
id: "cfg-lk432",
|
128
|
+
name: "Staging Config Example",
|
129
|
+
data: {
|
130
|
+
key: "value",
|
131
|
+
name: "key name"
|
132
|
+
}
|
133
|
+
}.to_json
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "does not error" do
|
138
|
+
expect { output }.to_not raise_error
|
139
|
+
|
140
|
+
expect(stderr).to eq("")
|
141
|
+
|
142
|
+
expect(stdout).to eq(%({"key":"value","name":"key name"}\n))
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "without '--format text'" do
|
147
|
+
let(:argv) { %w[configmaps show --data --format text cfg-xd3d4] }
|
148
|
+
|
149
|
+
before do
|
150
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-xd3d4")
|
151
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
152
|
+
.to_return(
|
153
|
+
status: 200,
|
154
|
+
body: {
|
155
|
+
id: "cfg-lk432",
|
156
|
+
name: "Staging Config Example",
|
157
|
+
data: {
|
158
|
+
key: "value",
|
159
|
+
name: "key name"
|
160
|
+
}
|
161
|
+
}.to_json
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "does not error" do
|
166
|
+
expect { output }.to_not raise_error
|
167
|
+
|
168
|
+
expect(stderr).not_to match("ERROR")
|
169
|
+
|
170
|
+
aggregate_failures do
|
171
|
+
expect(stdout).to match("^ key: value")
|
172
|
+
expect(stdout).to match("^ name: key name")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "with '--format' without 'data'" do
|
179
|
+
let(:argv) { %w[configmaps show --format json cfg-lk432] }
|
180
|
+
|
181
|
+
it "does not error" do
|
182
|
+
expect { output }.to_not raise_error
|
183
|
+
|
184
|
+
expect(stderr).to match("ERROR: The 'format' option can only be used with 'data'")
|
185
|
+
|
186
|
+
expect(stdout).to eq("")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "with simple output" do
|
191
|
+
let(:argv) { %w[--simple configmaps show cfg-lk432] }
|
192
|
+
|
193
|
+
before do
|
194
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-lk432")
|
195
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
196
|
+
.to_return(
|
197
|
+
status: 200,
|
198
|
+
body: {
|
199
|
+
id: "cfg-lk432",
|
200
|
+
name: "Staging Config Example",
|
201
|
+
data: {
|
202
|
+
key: "value"
|
203
|
+
}
|
204
|
+
}.to_json
|
205
|
+
)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "does not error" do
|
209
|
+
expect { output }.to_not raise_error
|
210
|
+
|
211
|
+
expect(stderr).not_to match("ERROR")
|
212
|
+
|
213
|
+
aggregate_failures do
|
214
|
+
expect(stdout).to match("^id\tcfg-lk432$")
|
215
|
+
expect(stdout).to match("^name\tStaging Config Example$")
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def config_maps_response
|
221
|
+
[
|
222
|
+
{
|
223
|
+
id: "cfg-12345",
|
224
|
+
name: "Test 12345",
|
225
|
+
data: {}
|
226
|
+
},
|
227
|
+
{
|
228
|
+
id: "cfg-abcde",
|
229
|
+
name: "Test ABCDE",
|
230
|
+
data: {
|
231
|
+
key: "value"
|
232
|
+
}
|
233
|
+
}
|
234
|
+
].to_json
|
235
|
+
end
|
236
|
+
end
|
@@ -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
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "brightbox sql instances reset" do
|
4
|
+
let(:output) { FauxIO.new { Brightbox.run(argv) } }
|
5
|
+
let(:stdout) { output.stdout }
|
6
|
+
let(:stderr) { output.stderr }
|
7
|
+
|
8
|
+
before do
|
9
|
+
config_from_contents(API_CLIENT_CONFIG_CONTENTS)
|
10
|
+
|
11
|
+
stub_request(:post, "http://api.brightbox.localhost/token")
|
12
|
+
.to_return(
|
13
|
+
status: 200,
|
14
|
+
body: JSON.dump(
|
15
|
+
access_token: "ACCESS-TOKEN",
|
16
|
+
refresh_token: "REFRESH_TOKEN"
|
17
|
+
)
|
18
|
+
)
|
19
|
+
|
20
|
+
Brightbox.config.reauthenticate
|
21
|
+
end
|
22
|
+
|
23
|
+
context "without arguments" do
|
24
|
+
let(:argv) { %w[sql instances reset] }
|
25
|
+
|
26
|
+
it "does not error" do
|
27
|
+
expect { output }.to_not raise_error
|
28
|
+
|
29
|
+
expect(stderr).to eq("ERROR: You must specify a valid SQL instance ID as the first argument\n")
|
30
|
+
|
31
|
+
expect(stdout).to match("")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with invalid ID" do
|
36
|
+
let(:argv) { %w[sql instances reset dbs-l3kd4] }
|
37
|
+
|
38
|
+
before do
|
39
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/database_servers/dbs-l3kd4")
|
40
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
41
|
+
.to_return(
|
42
|
+
status: 404,
|
43
|
+
body: ""
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not error" do
|
48
|
+
expect { output }.to_not raise_error
|
49
|
+
|
50
|
+
expect(stderr).to eq("ERROR: Couldn't find 'dbs-l3kd4'\n")
|
51
|
+
|
52
|
+
expect(stdout).to match("")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with valid ID" do
|
57
|
+
let(:argv) { %w[sql instances reset dbs-po953] }
|
58
|
+
|
59
|
+
before do
|
60
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/database_servers/dbs-po953")
|
61
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
62
|
+
.to_return(
|
63
|
+
status: 200,
|
64
|
+
body: {
|
65
|
+
id: "dbs-po953"
|
66
|
+
}.to_json
|
67
|
+
)
|
68
|
+
|
69
|
+
stub_request(:post, "http://api.brightbox.localhost/1.0/database_servers/dbs-po953/reset")
|
70
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
71
|
+
.to_return(
|
72
|
+
status: 202,
|
73
|
+
body: {
|
74
|
+
id: "dbs-po953"
|
75
|
+
}.to_json
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does not error" do
|
80
|
+
expect { output }.to_not raise_error
|
81
|
+
|
82
|
+
expect(stderr).to eq("Resetting dbs-po953\n")
|
83
|
+
|
84
|
+
expect(stdout).to match("dbs-po953")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|