brightbox-cli 4.3.2 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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