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,257 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "brightbox configmaps create" do
|
4
|
+
let(:output) { FauxIO.new { Brightbox.run(argv) } }
|
5
|
+
let(:stdout) { output.stdout }
|
6
|
+
let(:stderr) { output.stderr }
|
7
|
+
|
8
|
+
let(:token) { SecureRandom.hex }
|
9
|
+
|
10
|
+
before do
|
11
|
+
config_from_contents(API_CLIENT_CONFIG_CONTENTS)
|
12
|
+
|
13
|
+
stub_request(:post, "http://api.brightbox.localhost/token")
|
14
|
+
.to_return(status: 200, body: JSON.dump(access_token: token))
|
15
|
+
|
16
|
+
Brightbox.config.reauthenticate
|
17
|
+
end
|
18
|
+
|
19
|
+
context "without options" do
|
20
|
+
let(:argv) { %w[configmaps create] }
|
21
|
+
|
22
|
+
it "does not error" do
|
23
|
+
expect { output }.to_not raise_error
|
24
|
+
|
25
|
+
expect(stderr).to match("Config map data is required as 'data' option")
|
26
|
+
|
27
|
+
expect(stdout).to eq("")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with 'name' and 'data'" do
|
32
|
+
let(:argv) { ["configmaps", "create", "--name", "tester", "--data", payload] }
|
33
|
+
let(:payload) { { key: "value" }.to_json }
|
34
|
+
|
35
|
+
before do
|
36
|
+
stub_request(:post, "http://api.brightbox.localhost/1.0/config_maps")
|
37
|
+
.with(headers: { "Content-Type" => "application/json" },
|
38
|
+
query: hash_including(account_id: "acc-12345"),
|
39
|
+
body: {
|
40
|
+
name: "tester",
|
41
|
+
data: {
|
42
|
+
key: "value"
|
43
|
+
}
|
44
|
+
})
|
45
|
+
.to_return(
|
46
|
+
status: 200,
|
47
|
+
body: {
|
48
|
+
id: "cfg-lk342",
|
49
|
+
name: "tester",
|
50
|
+
data: {
|
51
|
+
key: "value"
|
52
|
+
}
|
53
|
+
}.to_json
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "does not error" do
|
58
|
+
expect { output }.to_not raise_error
|
59
|
+
|
60
|
+
expect(stderr).not_to match("ERROR")
|
61
|
+
|
62
|
+
aggregate_failures do
|
63
|
+
expect(stdout).to match("id.*name")
|
64
|
+
|
65
|
+
expect(stdout).to match("cfg-lk342")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with 'data'" do
|
71
|
+
let(:argv) { ["configmaps", "create", "--data", payload] }
|
72
|
+
let(:payload) { { key: "value" }.to_json }
|
73
|
+
|
74
|
+
before do
|
75
|
+
stub_request(:post, "http://api.brightbox.localhost/1.0/config_maps")
|
76
|
+
.with(headers: { "Content-Type" => "application/json" },
|
77
|
+
query: hash_including(account_id: "acc-12345"),
|
78
|
+
body: {
|
79
|
+
data: {
|
80
|
+
key: "value"
|
81
|
+
}
|
82
|
+
}.to_json)
|
83
|
+
.to_return(
|
84
|
+
status: 200,
|
85
|
+
body: {
|
86
|
+
id: "cfg-lk342",
|
87
|
+
data: {
|
88
|
+
key: "value"
|
89
|
+
}
|
90
|
+
}.to_json
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "does not error" do
|
95
|
+
expect { output }.to_not raise_error
|
96
|
+
|
97
|
+
expect(stderr).not_to match("ERROR")
|
98
|
+
|
99
|
+
aggregate_failures do
|
100
|
+
expect(stdout).to match("id.*name")
|
101
|
+
|
102
|
+
expect(stdout).to match("cfg-lk342")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with invalid update" do
|
107
|
+
let(:payload) { "Not JSON!" }
|
108
|
+
|
109
|
+
it "does not error" do
|
110
|
+
expect { output }.to_not raise_error
|
111
|
+
|
112
|
+
expect(stderr).to eq("ERROR: Config map data was not valid JSON\n")
|
113
|
+
|
114
|
+
expect(stdout).to eq("")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with new map from 'data-file'" do
|
120
|
+
context "when filename is used" do
|
121
|
+
let(:argv) { ["configmaps", "create", "--data-file", data_file.path] }
|
122
|
+
let(:data_file) { Tempfile.open("config_map_test_data") }
|
123
|
+
|
124
|
+
around do |example|
|
125
|
+
data_file.write(payload)
|
126
|
+
data_file.close
|
127
|
+
|
128
|
+
example.run
|
129
|
+
|
130
|
+
data_file.unlink
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with valid update" do
|
134
|
+
let(:payload) { { new_key: "new setting" }.to_json }
|
135
|
+
|
136
|
+
before do
|
137
|
+
stub_request(:post, "http://api.brightbox.localhost/1.0/config_maps")
|
138
|
+
.with(query: hash_including(account_id: "acc-12345"),
|
139
|
+
body: {
|
140
|
+
data: {
|
141
|
+
new_key: "new setting"
|
142
|
+
}
|
143
|
+
})
|
144
|
+
.to_return(
|
145
|
+
status: 200,
|
146
|
+
body: {
|
147
|
+
id: "cfg-s432l",
|
148
|
+
name: "",
|
149
|
+
data: {
|
150
|
+
new_key: "new setting"
|
151
|
+
}
|
152
|
+
}.to_json
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "does not error" do
|
157
|
+
expect { output }.to_not raise_error
|
158
|
+
|
159
|
+
expect(stderr).to eq("Creating config map\n")
|
160
|
+
|
161
|
+
aggregate_failures do
|
162
|
+
expect(stdout).to match("cfg-s432l")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "with invalid update" do
|
167
|
+
let(:payload) { "Not JSON!" }
|
168
|
+
|
169
|
+
it "does not error" do
|
170
|
+
expect { output }.to_not raise_error
|
171
|
+
|
172
|
+
expect(stderr).to eq("ERROR: Config map data was not valid JSON\n")
|
173
|
+
|
174
|
+
expect(stdout).to eq("")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "when '-' is used for STDIN" do
|
182
|
+
let(:argv) { ["configmaps", "create", "--data-file", "-", "cfg-stdin"] }
|
183
|
+
|
184
|
+
before do
|
185
|
+
stdin_data = StringIO.new
|
186
|
+
stdin_data.puts(payload)
|
187
|
+
stdin_data.rewind
|
188
|
+
|
189
|
+
$stdin = stdin_data
|
190
|
+
end
|
191
|
+
|
192
|
+
after do
|
193
|
+
$stdin = STDIN
|
194
|
+
end
|
195
|
+
|
196
|
+
context "with valid update" do
|
197
|
+
let(:payload) { { use_stdin: true }.to_json }
|
198
|
+
|
199
|
+
before do
|
200
|
+
stub_request(:post, "http://api.brightbox.localhost/1.0/config_maps")
|
201
|
+
.with(query: hash_including(account_id: "acc-12345"),
|
202
|
+
body: {
|
203
|
+
data: {
|
204
|
+
use_stdin: true
|
205
|
+
}
|
206
|
+
})
|
207
|
+
.to_return(
|
208
|
+
status: 200,
|
209
|
+
body: {
|
210
|
+
id: "cfg-mj53s",
|
211
|
+
name: "",
|
212
|
+
data: {
|
213
|
+
use_stdin: true
|
214
|
+
}
|
215
|
+
}.to_json
|
216
|
+
)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "does not error" do
|
220
|
+
expect { output }.to_not raise_error
|
221
|
+
|
222
|
+
expect(stderr).to eq("Creating config map\n")
|
223
|
+
|
224
|
+
aggregate_failures do
|
225
|
+
expect(stdout).to match("cfg-mj53s")
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
context "with invalid update" do
|
230
|
+
let(:payload) { "Not JSON!" }
|
231
|
+
|
232
|
+
it "does not error" do
|
233
|
+
expect { output }.to_not raise_error
|
234
|
+
|
235
|
+
expect(stderr).to eq("ERROR: Config map data was not valid JSON\n")
|
236
|
+
|
237
|
+
expect(stdout).to eq("")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "with mutually exclusive data options" do
|
244
|
+
let(:argv) { ["configmaps", "create", "--data", payload, "--data-file", "-"] }
|
245
|
+
let(:payload) { { new_key: "new value" }.to_json }
|
246
|
+
|
247
|
+
context "with invalid update" do
|
248
|
+
it "does not error" do
|
249
|
+
expect { output }.to_not raise_error
|
250
|
+
|
251
|
+
expect(stderr).to eq("ERROR: Config map data can only be passed by either 'data' or 'data-file'\n")
|
252
|
+
|
253
|
+
expect(stdout).to eq("")
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "brightbox configmaps destroy" 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 destroy] }
|
25
|
+
|
26
|
+
it "does not error" do
|
27
|
+
expect { output }.to_not raise_error
|
28
|
+
|
29
|
+
expect(stderr).to eq("ERROR: You must specify config map IDs as arguments\n")
|
30
|
+
|
31
|
+
expect(stdout).to match("")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with one argument" do
|
36
|
+
let(:argv) { %w[configmaps destroy cfg-xdwe2] }
|
37
|
+
|
38
|
+
before do
|
39
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-xdwe2")
|
40
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
41
|
+
.to_return(
|
42
|
+
status: 200,
|
43
|
+
body: {
|
44
|
+
id: "cfg-xdwe2"
|
45
|
+
}.to_json
|
46
|
+
)
|
47
|
+
.to_return(
|
48
|
+
status: 200,
|
49
|
+
body: {
|
50
|
+
id: "cfg-xdwe2"
|
51
|
+
}.to_json
|
52
|
+
)
|
53
|
+
|
54
|
+
stub_request(:delete, "http://api.brightbox.localhost/1.0/config_maps/cfg-xdwe2")
|
55
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
56
|
+
.to_return(
|
57
|
+
status: 202,
|
58
|
+
body: {
|
59
|
+
id: "cfg-xdwe2"
|
60
|
+
}.to_json
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "does not error" do
|
65
|
+
expect { output }.to_not raise_error
|
66
|
+
|
67
|
+
expect(stderr).to match("Destroying cfg-xdwe2\n")
|
68
|
+
|
69
|
+
expect(stdout).to eq("")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with multiple arguments" do
|
74
|
+
let(:argv) { %w[configmaps destroy cfg-12ds4 cfg-vf567] }
|
75
|
+
|
76
|
+
before do
|
77
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-12ds4")
|
78
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
79
|
+
.to_return(
|
80
|
+
status: 200,
|
81
|
+
body: {
|
82
|
+
id: "cfg-12ds4"
|
83
|
+
}.to_json
|
84
|
+
)
|
85
|
+
.to_return(
|
86
|
+
status: 200,
|
87
|
+
body: {
|
88
|
+
id: "cfg-12ds4"
|
89
|
+
}.to_json
|
90
|
+
)
|
91
|
+
|
92
|
+
stub_request(:delete, "http://api.brightbox.localhost/1.0/config_maps/cfg-12ds4")
|
93
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
94
|
+
.to_return(
|
95
|
+
status: 200,
|
96
|
+
body: {
|
97
|
+
id: "cfg-12ds4"
|
98
|
+
}.to_json
|
99
|
+
)
|
100
|
+
|
101
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-vf567")
|
102
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
103
|
+
.to_return(
|
104
|
+
status: 200,
|
105
|
+
body: {
|
106
|
+
id: "cfg-vf567"
|
107
|
+
}.to_json
|
108
|
+
)
|
109
|
+
.to_return(
|
110
|
+
status: 200,
|
111
|
+
body: {
|
112
|
+
id: "cfg-vf567"
|
113
|
+
}.to_json
|
114
|
+
)
|
115
|
+
|
116
|
+
stub_request(:delete, "http://api.brightbox.localhost/1.0/config_maps/cfg-vf567")
|
117
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
118
|
+
.to_return(
|
119
|
+
status: 200,
|
120
|
+
body: {
|
121
|
+
id: "cfg-vf567"
|
122
|
+
}.to_json
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not error" do
|
127
|
+
expect { output }.to_not raise_error
|
128
|
+
|
129
|
+
expect(stderr).to match("Destroying cfg-12ds4\n")
|
130
|
+
expect(stderr).to match("Destroying cfg-vf567\n")
|
131
|
+
|
132
|
+
expect(stdout).to eq("")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "with unknown argument" do
|
137
|
+
let(:argv) { %w[configmaps destroy cfg-lk234] }
|
138
|
+
|
139
|
+
before do
|
140
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-lk234")
|
141
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
142
|
+
.to_return(
|
143
|
+
status: 404,
|
144
|
+
body: ""
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "does not error" do
|
149
|
+
expect { output }.to_not raise_error
|
150
|
+
|
151
|
+
expect(stderr).to match("Couldn't find cfg-lk234\n")
|
152
|
+
|
153
|
+
expect(stdout).to eq("")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "brightbox configmaps list" 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 list] }
|
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.*name")
|
42
|
+
|
43
|
+
expect(stdout).to match("cfg-12345")
|
44
|
+
expect(stdout).to match("Test 12345")
|
45
|
+
|
46
|
+
expect(stdout).to match("cfg-abcde")
|
47
|
+
expect(stdout).to match("Test ABCDE")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with identifier" do
|
53
|
+
let(:argv) { %w[configmaps list cfg-312re] }
|
54
|
+
|
55
|
+
before do
|
56
|
+
stub_request(:get, "http://api.brightbox.localhost/1.0/config_maps/cfg-312re")
|
57
|
+
.with(query: hash_including(account_id: "acc-12345"))
|
58
|
+
.to_return(
|
59
|
+
status: 200,
|
60
|
+
body: {
|
61
|
+
id: "cfg-312re",
|
62
|
+
name: "My config",
|
63
|
+
data: {
|
64
|
+
key: "value"
|
65
|
+
}
|
66
|
+
}.to_json
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not error" do
|
71
|
+
expect { output }.to_not raise_error
|
72
|
+
|
73
|
+
expect(stderr).not_to match("ERROR")
|
74
|
+
|
75
|
+
aggregate_failures do
|
76
|
+
expect(stdout).to match("id.*name")
|
77
|
+
|
78
|
+
expect(stdout).to match("cfg-312re")
|
79
|
+
expect(stdout).to match("My config")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def config_maps_response
|
85
|
+
[
|
86
|
+
{
|
87
|
+
id: "cfg-12345",
|
88
|
+
name: "Test 12345"
|
89
|
+
},
|
90
|
+
{
|
91
|
+
id: "cfg-abcde",
|
92
|
+
name: "Test ABCDE"
|
93
|
+
}
|
94
|
+
].to_json
|
95
|
+
end
|
96
|
+
end
|