-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
test_demo.tcl
341 lines (283 loc) · 7.66 KB
/
test_demo.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#! /usr/bin/env expect -f
source [file join [file dirname $argv0] common.tcl]
start_test "Check that demo insecure says hello properly, multitenant"
spawn $argv demo --no-line-editor --insecure=true --multitenant=true --log-dir=logs
# Be polite.
eexpect "Welcome"
# Warn the user that they won't get persistence.
eexpect "your changes to data stored in the demo session will not be saved!"
# Check that the connection URL is printed.
eexpect "(webui)"
eexpect "http://127.0.0.1:8080"
eexpect "(sql)"
eexpect "root"
eexpect ":26257/movr"
# Ensure same messages as cockroach sql.
eexpect "Server version"
eexpect "Cluster ID"
eexpect "brief introduction"
# Ensure user is root.
eexpect root@
# Ensure db is movr.
eexpect "movr>"
send_eof
eexpect eof
end_test
start_test "Check that demo insecure says hello properly, singletenant"
spawn $argv demo --no-line-editor --insecure=true --multitenant=false --log-dir=logs
# Check that the connection URL is printed; and that we're still
# using default ports.
eexpect "(webui)"
eexpect "http://127.0.0.1:8080"
eexpect "(sql)"
eexpect "root"
eexpect ":26257/movr"
# Check that the system tenant's name is not printed in the prompt since we
# don't have any application tenants.
eexpect ":26257/movr>"
send_eof
eexpect eof
end_test
start_test "Check that demo insecure, env var, says hello properly"
# With env var.
set ::env(COCKROACH_INSECURE) "true"
spawn $argv demo --no-line-editor --no-example-database --log-dir=logs --multitenant=true
eexpect "Welcome"
eexpect "defaultdb>"
end_test
start_test "Check the detailed URLs, insecure mode"
# Show the URLs.
# Also check that the default port is used.
send "\\demo ls\r"
eexpect "(webui)"
eexpect "http://"
eexpect ":8080"
eexpect "Application tenant"
eexpect "(sql)"
eexpect "root@"
eexpect ":26257"
eexpect "sslmode=disable"
eexpect "System tenant"
eexpect "(sql)"
eexpect "root@"
eexpect ":26257"
eexpect "sslmode=disable"
eexpect "(sql/unix)"
eexpect "root:unused@"
eexpect "=26257"
eexpect "defaultdb>"
end_test
send_eof
eexpect eof
# With command-line override.
set ::env(COCKROACH_INSECURE) "false"
spawn $argv demo --no-line-editor --insecure=true --no-example-database --log-dir=logs
eexpect "Welcome"
eexpect "defaultdb>"
# Show the URLs.
send "\\demo ls\r"
eexpect "(webui)"
eexpect "http://"
eexpect "(sql)"
eexpect "root@"
eexpect "sslmode=disable"
eexpect "(sql/unix)"
eexpect "root:unused@"
eexpect "defaultdb>"
send_eof
eexpect eof
end_test
start_test "Check that demo secure says hello properly"
# With env var.
set ::env(COCKROACH_INSECURE) "false"
spawn $argv demo --no-line-editor --no-example-database --log-dir=logs --multitenant=true
eexpect "Welcome"
eexpect "(webui)"
eexpect "http://127.0.0.1:8080/demologin"
eexpect "(sql)"
eexpect "postgresql://demo:"
eexpect "sslmode=require"
eexpect "Username: \"demo\", password"
eexpect "Directory with certificate files"
eexpect "defaultdb>"
# Show the URLs.
# Also check that the default port is used.
send "\\demo ls\r"
eexpect "(webui)"
eexpect "http://127.0.0.1:8080/demologin"
eexpect "Application tenant"
eexpect "(sql)"
eexpect "postgresql://demo:"
eexpect ":26257"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "System tenant"
eexpect "(sql)"
eexpect "postgresql://demo:"
eexpect ":26257"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "(sql/unix)"
eexpect "demo:"
eexpect "=26257"
eexpect "defaultdb>"
send_eof
eexpect eof
# With command-line override.
set ::env(COCKROACH_INSECURE) "true"
spawn $argv demo --no-line-editor --insecure=false --no-example-database --log-dir=logs
eexpect "Welcome"
eexpect "Username: \"demo\", password"
eexpect "defaultdb>"
# Show the URLs.
send "\\demo ls\r"
eexpect "(webui)"
eexpect "http://"
eexpect "(sql)"
eexpect "demo:"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "(sql/unix)"
eexpect "demo:"
eexpect "defaultdb>"
send_eof
eexpect eof
end_test
start_test "Check that the user can override the password."
set ::env(COCKROACH_DEMO_PASSWORD) "hunter2"
spawn $argv demo --no-line-editor --insecure=false --no-example-database --log-dir=logs
eexpect "Connection parameters"
eexpect "(sql)"
eexpect "postgresql://demo:hunter2@"
eexpect "defaultdb>"
send_eof
eexpect eof
end_test
# Test that demo displays connection URLs for nodes in the cluster.
start_test "Check that node URLs are displayed"
spawn $argv demo --no-line-editor --insecure --no-example-database --log-dir=logs
# Check that we see our message.
eexpect "Connection parameters"
eexpect "(webui)"
eexpect "(sql)"
expect "root@"
send_eof
eexpect eof
# Start the test again with a multi node cluster.
spawn $argv demo --no-line-editor --insecure --nodes 3 --no-example-database --log-dir=logs
# Check that we get a message for each node.
eexpect "Connection parameters"
eexpect "(webui)"
eexpect "(sql)"
eexpect "defaultdb>"
send "\\demo ls\r"
eexpect "node 1"
eexpect "(webui)"
eexpect "(sql)"
eexpect "(sql/unix)"
eexpect "node 2"
eexpect "(webui)"
eexpect "(sql)"
eexpect "(sql/unix)"
eexpect "node 3"
eexpect "(webui)"
eexpect "(sql)"
eexpect "(sql/unix)"
eexpect "defaultdb>"
send_eof
eexpect eof
spawn $argv demo --no-line-editor --insecure=false --no-example-database --log-dir=logs
# Expect that security related tags are part of the connection URL.
eexpect "(sql)"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "defaultdb>"
end_test
start_test "Check that the info output includes demo node details"
send "\\info\r"
eexpect "Server version:"
eexpect "Cluster ID:"
eexpect "You are connected to database \"defaultdb\""
eexpect "You are connected to a demo cluster"
eexpect "Connection parameters"
eexpect "(webui)"
eexpect "(sql)"
eexpect "defaultdb>"
end_test
start_test "Check that invalid URL is rejected"
# Regression test for 83598
send "\\connect postgresql://foo:123/\r"
eexpect "using new connection URL"
eexpect "failed to connect"
eexpect " ?>"
send_eof
eexpect eof
end_test
start_test "Check that the port numbers can be overridden from the command line."
spawn $argv demo --no-line-editor --no-example-database --nodes 3 --http-port 8000 --log-dir=logs
eexpect "Welcome"
eexpect "defaultdb>"
# Show the URLs.
send "\\demo ls\r"
eexpect "http://"
eexpect ":8000"
eexpect "http://"
eexpect ":8001"
eexpect "http://"
eexpect ":8002"
eexpect "defaultdb>"
send_eof
eexpect eof
spawn $argv demo --no-line-editor --no-example-database --nodes 3 --sql-port 23000 --log-dir=logs --multitenant=true
eexpect "Welcome"
eexpect "defaultdb>"
# Show the URLs.
send "\\demo ls\r"
eexpect "node 1"
eexpect "Application tenant"
eexpect "(sql)"
eexpect ":23000"
eexpect "System tenant"
eexpect "(sql)"
eexpect ":23000"
eexpect "(sql/unix)"
eexpect "=23000"
eexpect "node 2"
eexpect "Application tenant"
eexpect "(sql)"
eexpect ":23001"
eexpect "System tenant"
eexpect "(sql)"
eexpect ":23001"
eexpect "(sql/unix)"
eexpect "=23001"
eexpect "node 3"
eexpect "Application tenant"
eexpect "(sql)"
eexpect ":23002"
eexpect "System tenant"
eexpect "(sql)"
eexpect ":23002"
eexpect "(sql/unix)"
eexpect "=23002"
eexpect "defaultdb>"
send_eof
eexpect eof
end_test
start_test "Check that demo populates the connection URL in a configured file"
spawn $argv demo --no-line-editor --no-example-database --listening-url-file=test.url --log-dir=logs
eexpect "Welcome"
eexpect "defaultdb>"
# Check the URL is valid. If the connection fails, the system command will fail too.
system "$argv sql --url `cat test.url` -e 'select 1'"
send_eof
eexpect eof
# Ditto, insecure
spawn $argv demo --no-line-editor --no-example-database --listening-url-file=test.url --insecure --log-dir=logs
eexpect "Welcome"
eexpect "defaultdb>"
# Check the URL is valid. If the connection fails, the system command will fail too.
system "$argv sql --url `cat test.url` -e 'select 1'"
send_eof
eexpect eof
end_test