1#! /bin/bash
2
3lnav_test="${top_builddir}/src/lnav-test"
4unset XDG_CONFIG_HOME
5
6run_test ${lnav_test} -n \
7    -c ";.read nonexistent-file" \
8    ${test_dir}/logfile_empty.0
9
10check_error_output "read worked with a nonexistent file?" <<EOF
11command-option:1: error: unable to read script file: nonexistent-file -- No such file or directory
12EOF
13
14run_test ${lnav_test} -n \
15    -c ";.read ${test_dir}/file_for_dot_read.sql" \
16    -c ':write-csv-to -' \
17    ${test_dir}/logfile_syslog.0
18
19check_output ".read did not work?" <<EOF
20log_line,log_body
211, attempting to mount entry /auto/opt
22EOF
23
24
25run_test ${lnav_test} -n \
26    -c ";SELECT replicate('foobar', 120)" \
27    ${test_dir}/logfile_empty.0
28
29check_output "long lines are not truncated?" <<EOF
30                                                replicate('foobar', 120)
31foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar⋯oobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
32EOF
33
34cp ${srcdir}/logfile_syslog.2 logfile_syslog_test.2
35touch -t 201511030923 logfile_syslog_test.2
36run_test ${lnav_test} -n \
37    -c ";SELECT *, log_msg_schema FROM all_logs" \
38    -c ":write-csv-to -" \
39    logfile_syslog_test.2
40
41check_output "all_logs does not work?" <<EOF
42log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_format,log_msg_format,log_msg_schema
430,<NULL>,2015-11-03 09:23:38.000,0,info,0,<NULL>,<NULL>,<NULL>,syslog_log,# is up,aff2bfc3c61e7b86329b83190f0912b3
441,<NULL>,2015-11-03 09:23:38.000,0,info,0,<NULL>,<NULL>,<NULL>,syslog_log,# is up,aff2bfc3c61e7b86329b83190f0912b3
452,<NULL>,2015-11-03 09:23:38.000,0,info,0,<NULL>,<NULL>,<NULL>,syslog_log,# is down,506560b3c73dee057732e69a3c666718
46EOF
47
48
49run_test ${lnav_test} -n \
50    -c ";SELECT fields FROM logfmt_log" \
51    -c ":write-json-to -" \
52    ${test_dir}/logfile_logfmt.0
53
54check_output "logfmt fields are not handled correctly?" <<EOF
55[
56    {
57        "fields": {
58            "namespace": "inc-1-enh-domain-c14-ns-2",
59            "pod": "hello-inc-1-enh-domain-c14-ns-2-3-d8f465685-k75gp",
60            "reason": "",
61            "status": "Pending"
62        }
63    },
64    {
65        "fields": {
66            "error": "pod inc-1-domain-c14-ns-6/fe-inc-1-domain-c14-ns-6-5-656d9bb695-4584b is not found: PodNotFound",
67            "namespace": "inc-1-domain-c14-ns-6",
68            "pod": "fe-inc-1-domain-c14-ns-6-5-656d9bb695-4584b",
69            "uid": "be2def59-3a08-42fd-8f84-6f64cfcefa93"
70        }
71    },
72    {
73        "fields": {
74            "namespace": "inc-1-domain-c14-ns-6",
75            "pod": "fe-inc-1-domain-c14-ns-6-5-656d9bb695-4584b",
76            "uid": "be2def59-3a08-42fd-8f84-6f64cfcefa93"
77        }
78    },
79    {
80        "fields": {
81            "namespace": "inc-1-domain-c14-ns-6",
82            "pod": "fe-inc-1-domain-c14-ns-6-5-656d9bb695-4584b",
83            "uid": "be2def59-3a08-42fd-8f84-6f64cfcefa93"
84        }
85    },
86    {
87        "fields": {
88            "namespace": "inc-1-enh-domain-c14-ns-2",
89            "pod": "hello-inc-1-enh-domain-c14-ns-2-7-5ddd6bcd69-6rqct",
90            "reason": "",
91            "status": "Pending"
92        }
93    }
94]
95EOF
96
97
98run_test ${lnav_test} -n \
99    -c ";SELECT sc_substatus FROM w3c_log" \
100    -c ":write-json-to -" \
101    ${test_dir}/logfile_w3c.3
102
103check_output "w3c quoted strings are not handled correctly?" <<EOF
104[
105    {
106        "sc_substatus": 0
107    },
108    {
109        "sc_substatus": 0
110    },
111    {
112        "sc_substatus": null
113    }
114]
115EOF
116
117run_test ${lnav_test} -n \
118    -c ";SELECT cs_headers FROM w3c_log" \
119    -c ":write-json-to -" \
120    ${test_dir}/logfile_w3c.3
121
122check_output "w3c headers are not captured?" <<EOF
123[
124    {
125        "cs_headers": {
126            "User-Agent": "Mozilla/5.0 (Linux; Android 4.4.4; SM-G900V Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.59 Mobile Safari/537.36",
127            "Referer": "http://example.com/Search/SearchResults.pg?informationRecipient.languageCode.c=en",
128            "Host": "xzy.example.com"
129        }
130    },
131    {
132        "cs_headers": {
133            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36",
134            "Referer": null,
135            "Host": "example.hello.com"
136        }
137    },
138    {
139        "cs_headers": {
140            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36",
141            "Referer": null,
142            "Host": "hello.example.com"
143        }
144    }
145]
146EOF
147
148run_test ${lnav_test} -n \
149    -c ";SELECT * FROM generate_series()" \
150    ${test_dir}/logfile_access_log.0
151
152check_error_output "generate_series() works without params?" <<EOF
153command-option:1: error: the start parameter is required
154EOF
155
156run_test ${lnav_test} -n \
157    -c ";SELECT * FROM generate_series(1)" \
158    ${test_dir}/logfile_access_log.0
159
160check_error_output "generate_series() works without stop param?" <<EOF
161command-option:1: error: the stop parameter is required
162EOF
163
164run_test ${lnav_test} -n \
165    -c ";SELECT raise_error('oops!')" \
166    ${test_dir}/logfile_access_log.0
167
168check_error_output "raise_error() does not work?" <<EOF
169command-option:1: error: oops!
170EOF
171
172run_test ${lnav_test} -n \
173    -c ";SELECT basename(filepath) as name, content, length(content) FROM lnav_file" \
174    -c ":write-csv-to -" \
175    ${test_dir}/logfile_empty.0
176
177check_output "empty content not handled correctly?" <<EOF
178name,content,length(content)
179logfile_empty.0,,0
180EOF
181
182run_test ${lnav_test} -n \
183    -c ";SELECT distinct xp.node_text FROM lnav_file, xpath('//author', content) as xp" \
184    -c ":write-csv-to -" \
185    ${test_dir}/books.xml
186
187check_output "xpath on file content not working?" <<EOF
188node_text
189"Gambardella, Matthew"
190"Ralls, Kim"
191"Corets, Eva"
192"Randall, Cynthia"
193"Thurman, Paula"
194"Knorr, Stefan"
195"Kress, Peter"
196"O'Brien, Tim"
197"Galos, Mike"
198EOF
199
200gzip -c ${srcdir}/logfile_json.json > logfile_json.json.gz
201dd if=logfile_json.json.gz of=logfile_json-trunc.json.gz bs=64 count=2
202
203# TODO re-enable this
204#run_test ${lnav_test} -n \
205#    -c ";SELECT content FROM lnav_file" \
206#    logfile_json-trunc.json.gz
207
208#check_error_output "invalid gzip file working?" <<EOF
209#command-option:1: error: unable to uncompress: logfile_json-trunc.json.gz -- buffer error
210#EOF
211
212run_test ${lnav_test} -n \
213    -c ";SELECT jget(rc.content, '/ts') AS ts FROM lnav_file, regexp_capture(lnav_file.content, '.*\n') as rc" \
214    -c ":write-csv-to -" \
215    logfile_json.json.gz
216
217check_output "jget on file content not working?" <<EOF
218ts
2192013-09-06T20:00:48.124817Z
2202013-09-06T20:00:49.124817Z
2212013-09-06T22:00:49.124817Z
2222013-09-06T22:00:59.124817Z
2232013-09-06T22:00:59.124817Z
2242013-09-06T22:00:59.124817Z
2252013-09-06T22:00:59.124817Z
2262013-09-06T22:00:59.124817Z
2272013-09-06T22:01:49.124817Z
2282013-09-06T22:01:49.124817Z
2292013-09-06T22:01:49.124817Z
2302013-09-06T22:01:49.124817Z
2312013-09-06T22:01:49.124817Z
232EOF
233
234run_test ${lnav_test} -n \
235    -c ";UPDATE lnav_file SET visible=0" \
236    ${test_dir}/logfile_access_log.0
237
238check_output "file is not hidden?" <<EOF
239EOF
240
241run_test ${lnav_test} -n \
242    -c ";UPDATE lnav_file SET filepath='foo' WHERE endswith(filepath, '_log.0')" \
243    ${test_dir}/logfile_access_log.0
244
245check_error_output "able to change a real file's path?" <<EOF
246command-option:1: error: real file paths cannot be updated, only symbolic ones
247EOF
248
249run_test ${lnav_test} -n \
250    -c "|rename-stdin" \
251    ${test_dir}/logfile_access_log.0 < /dev/null
252
253check_error_output "rename-stdin works without an argument?" <<EOF
254../test/.lnav/formats/default/rename-stdin.lnav:6: error: expecting the new name for stdin as the first argument
255EOF
256
257run_test ${lnav_test} -n \
258    -c "|rename-stdin foo" \
259    ${test_dir}/logfile_access_log.0 < /dev/null
260
261check_error_output "rename-stdin when there is no stdin file?" <<EOF
262../test/.lnav/formats/default/rename-stdin.lnav:7: error: no data was redirected to lnav's standard-input
263EOF
264
265run_test ${lnav_test} -n \
266    -c "|rename-stdin foo" \
267    -c ";SELECT filepath FROM lnav_file" <<EOF
268Hello, World!
269EOF
270
271check_output "rename of stdin did not work?" <<EOF
272filepath
273foo
274EOF
275
276run_test ${lnav_test} -n \
277    -c ";SELECT basename(filepath),format,lines,time_offset FROM lnav_file LIMIT 2" \
278    -c ":write-csv-to -" \
279    ${test_dir}/logfile_access_log.0 \
280    ${test_dir}/logfile_access_log.1
281
282check_output "lnav_file table is not working?" <<EOF
283basename(filepath),format,lines,time_offset
284logfile_access_log.0,access_log,3,0
285logfile_access_log.1,access_log,1,0
286EOF
287
288run_test ${lnav_test} -n \
289    -c ";UPDATE lnav_file SET time_offset = 60 * 1000" \
290    ${test_dir}/logfile_access_log.0 \
291    ${test_dir}/logfile_access_log.1
292
293check_output "time_offset in lnav_file table is not working?" <<EOF
294192.168.202.254 - - [20/Jul/2009:23:00:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
295192.168.202.254 - - [20/Jul/2009:23:00:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
296192.168.202.254 - - [20/Jul/2009:23:00:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
29710.112.81.15 - - [15/Feb/2013:06:01:31 +0000] "-" 400 0 "-" "-"
298EOF
299
300run_test ${lnav_test} -n \
301    -c ";UPDATE lnav_file SET time_offset=14400000 WHERE endswith(filepath, 'logfile_block.1')" \
302    ${test_dir}/logfile_block.1 \
303    ${test_dir}/logfile_block.2
304
305check_output "time_offset in lnav_file table is not reordering?" <<EOF
306Wed May 19 12:00:01  2021 line 1
307Wed May 19 12:00:02 UTC 2021 line 2
308Wed May 19 12:00:03  2021 line 3
309Wed May 19 12:00:04 UTC 2021 line 4
310EOF
311
312run_test ${lnav_test} -n \
313    -c ";SELECT view_name,basename(filepath),visible FROM lnav_view_files" \
314    -c ":write-csv-to -" \
315    ${test_dir}/logfile_access_log.*
316
317check_output "lnav_view_files does not work?" <<EOF
318view_name,basename(filepath),visible
319log,logfile_access_log.0,1
320log,logfile_access_log.1,1
321EOF
322
323run_test ${lnav_test} -n \
324    -c ";UPDATE lnav_view_files SET visible=0 WHERE endswith(filepath, 'log.0')" \
325    ${test_dir}/logfile_access_log.*
326
327check_output "updating lnav_view_files does not work?" <<EOF
32810.112.81.15 - - [15/Feb/2013:06:00:31 +0000] "-" 400 0 "-" "-"
329EOF
330
331run_test ${lnav_test} -n \
332    -c ";DELETE FROM lnav_view_stack" \
333    ${test_dir}/logfile_access_log.0
334
335check_output "deleting the view stack does not work?" <<EOF
336EOF
337
338run_test ${lnav_test} -n \
339    -c ";UPDATE lnav_view_stack SET name = 'foo'" \
340    ${test_dir}/logfile_access_log.0
341
342check_error_output "able to update lnav_view_stack?" <<EOF
343command-option:1: error: The lnav_view_stack table cannot be updated
344EOF
345
346run_test ${lnav_test} -n \
347    -c ";INSERT INTO lnav_view_stack VALUES ('help')" \
348    -c ";DELETE FROM lnav_view_stack WHERE name = 'log'" \
349    ${test_dir}/logfile_access_log.0
350
351check_error_output "able to delete a view in the middle of lnav_view_stack?" <<EOF
352command-option:2: error: Only the top view in the stack can be deleted
353EOF
354
355run_test ${lnav_test} -n \
356    -c ";INSERT INTO lnav_view_filters VALUES ('log', 0, 1, 'out', '')" \
357    ${test_dir}/logfile_access_log.0
358
359check_error_output "inserted filter with an empty pattern?" <<EOF
360command-option:1: error: Expecting an non-empty pattern for column number 4
361EOF
362
363run_test ${lnav_test} -n \
364    -c ";INSERT INTO lnav_view_filters VALUES ('log', 0, 1, 'out', 'abc(')" \
365    ${test_dir}/logfile_access_log.0
366
367check_error_output "inserted filter with an invalid pattern?" <<EOF
368command-option:1: error: Invalid regular expression in column 4: missing ) at offset 4
369EOF
370
371run_test ${lnav_test} -n \
372    -c ";INSERT INTO lnav_view_filters VALUES ('bad', 0, 1, 'out', 'abc')" \
373    ${test_dir}/logfile_access_log.0
374
375check_error_output "inserted filter with an invalid view name?" <<EOF
376command-option:1: error: Expecting an lnav view name for column number 0
377EOF
378
379run_test ${lnav_test} -n \
380    -c ";INSERT INTO lnav_view_filters VALUES (NULL, 0, 1, 'out', 'abc')" \
381    ${test_dir}/logfile_access_log.0
382
383check_error_output "inserted filter with a null view name?" <<EOF
384command-option:1: error: Expecting an lnav view name for column number 0
385EOF
386
387run_test ${lnav_test} -n \
388    -c ";INSERT INTO lnav_view_filters VALUES ('log', 0 , 1, 'bad', 'abc')" \
389    ${test_dir}/logfile_access_log.0
390
391check_error_output "inserted filter with an invalid filter type?" <<EOF
392command-option:1: error: Expecting an filter type for column number 3
393EOF
394
395run_test ${lnav_test} -n \
396    -c ";INSERT INTO lnav_view_filters (view_name, pattern) VALUES ('log', 'vmk')" \
397    ${test_dir}/logfile_access_log.0
398
399check_output "inserted filter-out did not work?" <<EOF
400192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
401EOF
402
403run_test ${lnav_test} -n \
404    -c ";INSERT INTO lnav_view_filters (view_name, pattern, type) VALUES ('log', 'vmk', 'in')" \
405    ${test_dir}/logfile_access_log.0
406
407check_output "inserted filter-in did not work?" <<EOF
408192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
409192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
410EOF
411
412run_test ${lnav_test} -n \
413    -c ":filter-out vmk" \
414    -c ";DELETE FROM lnav_view_filters" \
415    ${test_dir}/logfile_access_log.0
416
417check_output "inserted filter did not work?" <<EOF
418192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
419192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
420192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
421EOF
422
423run_test ${lnav_test} -n \
424    -c ":filter-out vmk" \
425    -c ";UPDATE lnav_view_filters SET pattern = 'vmkboot'" \
426    ${test_dir}/logfile_access_log.0
427
428check_output "inserted filter did not work?" <<EOF
429192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
430192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
431EOF
432
433run_test ${lnav_test} -n \
434    -c ":filter-out vmk" \
435    -c ";SELECT * FROM lnav_view_filter_stats" \
436    -c ":write-csv-to -" \
437    ${test_dir}/logfile_access_log.0
438
439check_output "view filter stats is not working?" <<EOF
440view_name,filter_id,hits
441log,1,2
442EOF
443
444run_test ${lnav_test} -n \
445    -c ";SELECT * FROM access_log LIMIT 0" \
446    -c ':switch-to-view db' \
447    ${test_dir}/logfile_access_log.0
448
449check_output "output generated for empty result set?" <<EOF
450EOF
451
452run_test ${lnav_test} -n \
453    -c ":goto 2" \
454    -c ";SELECT log_top_line()" \
455    ${test_dir}/logfile_uwsgi.0
456
457check_output "log_top_line() not working?" <<EOF
458log_top_line()
459             2
460EOF
461
462run_test ${lnav_test} -n \
463    -c ":goto 2" \
464    -c ";SELECT log_top_line()" \
465    ${test_dir}/logfile_empty.0
466
467check_output "log_top_line() for an empty log file is not working?" <<EOF
468log_top_line()
469        <NULL>
470EOF
471
472run_test ${lnav_test} -n \
473    -c ":goto 2" \
474    -c ";SELECT log_top_datetime()" \
475    ${test_dir}/logfile_uwsgi.0
476
477check_output "log_top_datetime() not working?" <<EOF
478   log_top_datetime()
4792016-03-13 22:49:15.000
480EOF
481
482run_test ${lnav_test} -n \
483    -c ":goto 2" \
484    -c ";SELECT log_top_datetime()" \
485    ${test_dir}/logfile_empty.0
486
487check_output "log_top_datetime() for an empty log file is not working?" <<EOF
488    log_top_datetime()
489            <NULL>
490EOF
491
492run_test ${lnav_test} -n \
493    -c ";SELECT * FROM uwsgi_log LIMIT 1" \
494    -c ':switch-to-view db' \
495    ${test_dir}/logfile_uwsgi.0
496
497check_output "uwsgi not working?" <<EOF
498log_line log_part         log_time        log_idle_msecs log_level log_mark log_comment log_tags log_filters    c_ip   cs_bytes cs_method cs_uri_query   cs_uri_stem   cs_username cs_vars cs_version s_app s_core s_pid s_req s_runtime s_switches s_worker_reqs sc_bytes sc_header_bytes sc_headers sc_status
499       0   <NULL> 2016-03-13 22:49:12.000              0 info             0      <NULL>   <NULL>      <NULL> 127.0.0.1      696 POST            <NULL> /update_metrics                  38 HTTP/1.1   0     3      88185     1     0.129          1             1       47             378          9       200
500EOF
501
502run_test ${lnav_test} -n \
503    -c ";SELECT s_runtime FROM uwsgi_log LIMIT 5" \
504    -c ':write-csv-to -' \
505    ${test_dir}/logfile_uwsgi.0
506
507check_output "uwsgi scaling not working?" <<EOF
508s_runtime
5090.129
5100.035
5116.8e-05
5120.016
5130.01
514EOF
515
516run_test env TZ=UTC ${lnav_test} -n \
517    -c ";SELECT bro_conn_log.bro_duration as duration, bro_conn_log.bro_uid, group_concat( distinct (bro_method || ' ' || bro_host)) as req from bro_http_log, bro_conn_log where bro_http_log.bro_uid = bro_conn_log.bro_uid group by bro_http_log.bro_uid order by duration desc limit 10" \
518    -c ":write-csv-to -" \
519    ${test_dir}/logfile_bro_http.log.0 ${test_dir}/logfile_bro_conn.log.0
520
521check_output "bro logs are not recognized?" <<EOF
522duration,bro_uid,req
523116.438679,CwFs1P2UcUdlSxD2La,GET www.reddit.com
524115.202498,CdZUPH2DKOE7zzCLE3,GET feeds.bbci.co.uk
525115.121914,CdrfXZ1NOFPEawF218,GET c.thumbs.redditmedia.com
526115.121837,CoX7zA3OJKGUOSCBY2,GET e.thumbs.redditmedia.com
527115.12181,CJxSUgkInyKSHiju1,GET e.thumbs.redditmedia.com
528115.121506,CT0JIh479jXIGt0Po1,GET f.thumbs.redditmedia.com
529115.121339,CJwUi9bdB9c1lLW44,GET f.thumbs.redditmedia.com
530115.119217,C6Q4Vm14ZJIlZhsXqk,GET a.thumbs.redditmedia.com
53172.274459,CbNCgO1MzloHRNeY4f,GET www.google.com
53271.658218,CnGze54kQWWpKqrrZ4,GET ajax.googleapis.com
533EOF
534
535run_test env TZ=UTC ${lnav_test} -n \
536    -c ";SELECT * FROM bro_http_log LIMIT 5" \
537    -c ":write-csv-to -" \
538    ${test_dir}/logfile_bro_http.log.0
539
540check_output "bro logs are not recognized?" <<EOF
541log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,bro_ts,bro_uid,bro_id_orig_h,bro_id_orig_p,bro_id_resp_h,bro_id_resp_p,bro_trans_depth,bro_method,bro_host,bro_uri,bro_referrer,bro_version,bro_user_agent,bro_request_body_len,bro_response_body_len,bro_status_code,bro_status_msg,bro_info_code,bro_info_msg,bro_tags,bro_username,bro_password,bro_proxied,bro_orig_fuids,bro_orig_filenames,bro_orig_mime_types,bro_resp_fuids,bro_resp_filenames,bro_resp_mime_types
5420,<NULL>,2011-11-03 00:19:26.452,0,info,0,<NULL>,<NULL>,<NULL>,1320279566.452687,CwFs1P2UcUdlSxD2La,192.168.2.76,52026,132.235.215.119,80,1,GET,www.reddit.com,/,<NULL>,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,109978,200,OK,<NULL>,<NULL>,,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,Ftw3fJ2JJF3ntMTL2,<NULL>,text/html
5431,<NULL>,2011-11-03 00:19:26.831,379,info,0,<NULL>,<NULL>,<NULL>,1320279566.831619,CJxSUgkInyKSHiju1,192.168.2.76,52030,72.21.211.173,80,1,GET,e.thumbs.redditmedia.com,/E-pbDbmiBclPkDaX.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,2300,200,OK,<NULL>,<NULL>,,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,FFTf9Zdgk3YkfCKo3,<NULL>,image/jpeg
5442,<NULL>,2011-11-03 00:19:26.831,0,info,0,<NULL>,<NULL>,<NULL>,1320279566.831563,CJwUi9bdB9c1lLW44,192.168.2.76,52029,72.21.211.173,80,1,GET,f.thumbs.redditmedia.com,/BP5bQfy4o-C7cF6A.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,2272,200,OK,<NULL>,<NULL>,,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,FfXtOj3o7aub4vbs2j,<NULL>,image/jpeg
5453,<NULL>,2011-11-03 00:19:26.831,0,info,0,<NULL>,<NULL>,<NULL>,1320279566.831473,CoX7zA3OJKGUOSCBY2,192.168.2.76,52027,72.21.211.173,80,1,GET,e.thumbs.redditmedia.com,/SVUtep3Rhg5FTRn4.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,2562,200,OK,<NULL>,<NULL>,,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,F21Ybs3PTqS6O4Q2Zh,<NULL>,image/jpeg
5464,<NULL>,2011-11-03 00:19:26.831,0,info,0,<NULL>,<NULL>,<NULL>,1320279566.831643,CT0JIh479jXIGt0Po1,192.168.2.76,52031,72.21.211.173,80,1,GET,f.thumbs.redditmedia.com,/uuy31444rLSyKdHS.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,1595,200,OK,<NULL>,<NULL>,,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,Fdk0MZ1wQmKWAJ4WH4,<NULL>,image/jpeg
547EOF
548
549run_test env TZ=UTC ${lnav_test} -n \
550    -c ";SELECT * FROM bro_http_log WHERE log_level = 'error'" \
551    -c ":write-csv-to -" \
552    ${test_dir}/logfile_bro_http.log.0
553
554check_output "bro logs are not recognized?" <<EOF
555log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,bro_ts,bro_uid,bro_id_orig_h,bro_id_orig_p,bro_id_resp_h,bro_id_resp_p,bro_trans_depth,bro_method,bro_host,bro_uri,bro_referrer,bro_version,bro_user_agent,bro_request_body_len,bro_response_body_len,bro_status_code,bro_status_msg,bro_info_code,bro_info_msg,bro_tags,bro_username,bro_password,bro_proxied,bro_orig_fuids,bro_orig_filenames,bro_orig_mime_types,bro_resp_fuids,bro_resp_filenames,bro_resp_mime_types
556118,<NULL>,2011-11-03 00:19:49.337,18,error,0,<NULL>,<NULL>,<NULL>,1320279589.337053,CBHHuR1xFnm5C5CQBc,192.168.2.76,52074,74.125.225.76,80,1,GET,i4.ytimg.com,/vi/gDbg_GeuiSY/hqdefault.jpg,<NULL>,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,893,404,Not Found,<NULL>,<NULL>,,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,<NULL>,F2GiAw3j1m22R2yIg2,<NULL>,image/jpeg
557EOF
558
559run_test ${lnav_test} -n \
560    -c ';select log_time from access_log where log_line > 100000' \
561    -c ':switch-to-view db' \
562    ${test_dir}/logfile_access_log.0
563
564check_output "out-of-range query failed?" <<EOF
565EOF
566
567run_test ${lnav_test} -n \
568    -c ';select log_time from access_log where log_line > -100000' \
569    ${test_dir}/logfile_access_log.0
570
571check_output "out-of-range query failed?" <<EOF
572        log_time
5732009-07-20 22:59:26.000
5742009-07-20 22:59:29.000
5752009-07-20 22:59:29.000
576EOF
577
578run_test ${lnav_test} -n \
579    -c ';select log_time from access_log where log_line < -10000' \
580    -c ':switch-to-view db' \
581    ${test_dir}/logfile_access_log.0
582
583check_output "out-of-range query failed?" <<EOF
584EOF
585
586run_test ${lnav_test} -n \
587    -c ';select log_time from access_log where log_line > -10000' \
588    ${test_dir}/logfile_access_log.0
589
590check_output "out-of-range query failed?" <<EOF
591        log_time
5922009-07-20 22:59:26.000
5932009-07-20 22:59:29.000
5942009-07-20 22:59:29.000
595EOF
596
597run_test ${lnav_test} -n \
598    -c ';select log_time from access_log where log_line < 0' \
599    -c ':switch-to-view db' \
600    ${test_dir}/logfile_access_log.0
601
602check_output "out-of-range query failed?" <<EOF
603EOF
604
605run_test ${lnav_test} -n \
606    -c ';select log_time from access_log where log_line <= 0' \
607    -c ':switch-to-view db' \
608    ${test_dir}/logfile_access_log.0
609
610check_output "range query failed?" <<EOF
611        log_time
6122009-07-20 22:59:26.000
613EOF
614
615run_test ${lnav_test} -n \
616    -c ';select log_time from access_log where log_line >= 0' \
617    -c ':switch-to-view db' \
618    ${test_dir}/logfile_access_log.0
619
620check_output "range query failed?" <<EOF
621        log_time
6222009-07-20 22:59:26.000
6232009-07-20 22:59:29.000
6242009-07-20 22:59:29.000
625EOF
626
627
628run_test ${lnav_test} -n \
629    -c ';select sc_bytes from access_log' \
630    -c ':spectrogram sc_bytes' \
631    ${test_dir}/logfile_access_log.0
632
633check_error_output "spectrogram worked without log_time?" <<EOF
634command-option:2: error: no 'log_time' column found or not in ascending order, unable to create spectrogram
635EOF
636
637run_test ${lnav_test} -n \
638    -c ';select log_time,sc_bytes from access_log' \
639    -c ':spectrogram sc_byes' \
640    ${test_dir}/logfile_access_log.0
641
642check_error_output "spectrogram worked with bad column?" <<EOF
643command-option:2: error: unknown column -- sc_byes
644EOF
645
646run_test ${lnav_test} -n \
647    -c ';select log_time,c_ip from access_log' \
648    -c ':spectrogram c_ip' \
649    ${test_dir}/logfile_access_log.0
650
651check_error_output "spectrogram worked with non-numeric column?" <<EOF
652command-option:2: error: column is not numeric -- c_ip
653EOF
654
655run_test ${lnav_test} -n \
656    -c ';select log_time,sc_bytes from access_log order by log_time desc' \
657    -c ':spectrogram sc_bytes' \
658    ${test_dir}/logfile_access_log.0
659
660check_error_output "spectrogram worked with unordered log_time?" <<EOF
661command-option:2: error: no 'log_time' column found or not in ascending order, unable to create spectrogram
662EOF
663
664cp ${srcdir}/logfile_syslog_with_mixed_times.0 logfile_syslog_with_mixed_times_test.0
665touch -t 201511030923 logfile_syslog_with_mixed_times_test.0
666run_test ${lnav_test} -n \
667    -c ";select log_time,log_actual_time from syslog_log" \
668    -c ':write-csv-to -' \
669    logfile_syslog_with_mixed_times_test.0
670
671check_output "log_actual_time column not working" <<EOF
672log_time,log_actual_time
6732015-09-13 00:58:45.000,2015-09-13 00:58:45.000
6742015-09-13 00:59:30.000,2015-09-13 00:59:30.000
6752015-09-13 01:23:54.000,2015-09-13 01:23:54.000
6762015-09-13 03:12:04.000,2015-09-13 03:12:04.000
6772015-09-13 03:12:04.000,2015-09-13 03:12:04.000
6782015-09-13 03:12:04.000,2015-09-13 01:25:39.000
6792015-09-13 03:12:04.000,2015-09-13 03:12:04.000
6802015-09-13 03:12:58.000,2015-09-13 03:12:58.000
6812015-09-13 03:46:03.000,2015-09-13 03:46:03.000
6822015-09-13 03:46:03.000,2015-09-13 03:46:03.000
6832015-09-13 03:46:03.000,2015-09-13 03:46:03.000
6842015-09-13 03:46:03.000,2015-09-13 03:13:16.000
6852015-09-13 03:46:03.000,2015-09-13 03:46:03.000
686EOF
687
688
689run_test ${lnav_test} -n \
690    -c ";update access_log set log_part = 'middle' where log_line = 1" \
691    -c ';select log_line, log_part from access_log' \
692    -c ':write-csv-to -' \
693    ${test_dir}/logfile_access_log.0
694
695check_output "setting log_part is not working" <<EOF
696log_line,log_part
6970,<NULL>
6981,middle
6992,middle
700EOF
701
702run_test ${lnav_test} -n \
703    -c ";update access_log set log_part = 'middle' where log_line = 1" \
704    -c ";update access_log set log_part = NULL where log_line = 1" \
705    -c ';select log_line, log_part from access_log' \
706    -c ':write-csv-to -' \
707    ${test_dir}/logfile_access_log.0
708
709check_output "setting log_part is not working" <<EOF
710log_line,log_part
7110,<NULL>
7121,<NULL>
7132,<NULL>
714EOF
715
716run_test ${lnav_test} -n \
717    -c ";update access_log set log_part = 'middle' where log_line = 1" \
718    -c ";update access_log set log_part = NULL where log_line = 2" \
719    -c ';select log_line, log_part from access_log' \
720    -c ':write-csv-to -' \
721    ${test_dir}/logfile_access_log.0
722
723check_output "setting log_part is not working" <<EOF
724log_line,log_part
7250,<NULL>
7261,middle
7272,middle
728EOF
729
730
731run_test ${lnav_test} -n \
732    -I "${top_srcdir}/test" \
733    -c ";select * from web_status" \
734    -c ':write-csv-to -' \
735    ${test_dir}/logfile_access_log.0
736
737check_output "access_log table is not working" <<EOF
738group_concat(cs_uri_stem),sc_status
739"/vmw/cgi/tramp,/vmw/vSphere/default/vmkernel.gz",200
740/vmw/vSphere/default/vmkboot.gz,404
741EOF
742
743
744run_test ${lnav_test} -n \
745    -c ";select * from access_log" \
746    -c ':write-csv-to -' \
747    ${test_dir}/logfile_access_log.0
748
749check_output "access_log table is not working" <<EOF
750log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status,cs_host
7510,<NULL>,2009-07-20 22:59:26.000,0,info,0,<NULL>,<NULL>,<NULL>,192.168.202.254,GET,-,<NULL>,/vmw/cgi/tramp,gPXE/0.9.7,-,HTTP/1.0,134,200,<NULL>
7521,<NULL>,2009-07-20 22:59:29.000,3000,error,0,<NULL>,<NULL>,<NULL>,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404,<NULL>
7532,<NULL>,2009-07-20 22:59:29.000,0,info,0,<NULL>,<NULL>,<NULL>,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkernel.gz,gPXE/0.9.7,-,HTTP/1.0,78929,200,<NULL>
754EOF
755
756
757run_test ${lnav_test} -n \
758    -c ";select * from access_log where log_level >= 'warning'" \
759    -c ':write-csv-to -' \
760    ${test_dir}/logfile_access_log.0
761
762check_output "loglevel collator is not working" <<EOF
763log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status,cs_host
7641,<NULL>,2009-07-20 22:59:29.000,3000,error,0,<NULL>,<NULL>,<NULL>,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404,<NULL>
765EOF
766
767
768# XXX The timestamp on the file is used to determine the year for syslog files.
769touch -t 200711030923 ${test_dir}/logfile_syslog.0
770run_test ${lnav_test} -n \
771    -c ";select * from syslog_log" \
772    -c ':write-csv-to -' \
773    ${test_dir}/logfile_syslog.0
774
775check_output "syslog_log table is not working" <<EOF
776log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version
7770,<NULL>,2007-11-03 09:23:38.000,0,error,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,7998,<NULL>,automount,<NULL>,<NULL>
7781,<NULL>,2007-11-03 09:23:38.000,0,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,16442,<NULL>,automount,<NULL>,<NULL>
7792,<NULL>,2007-11-03 09:23:38.000,0,error,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,7999,<NULL>,automount,<NULL>,<NULL>
7803,<NULL>,2007-11-03 09:47:02.000,1404000,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>
781EOF
782
783
784run_test ${lnav_test} -n \
785    -c ";select * from syslog_log where log_time >= NULL" \
786    -c ':write-csv-to -' \
787    ${test_dir}/logfile_syslog.0
788
789check_output "log_time collation failed on null" <<EOF
790EOF
791
792
793run_test ${lnav_test} -n \
794    -c ";select * from syslog_log where log_time >= datetime('2007-11-03T09:47:02.000')" \
795    -c ':write-csv-to -' \
796    ${test_dir}/logfile_syslog.0
797
798check_output "log_time collation is wrong" <<EOF
799log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version
8003,<NULL>,2007-11-03 09:47:02.000,1404000,info,0,<NULL>,<NULL>,<NULL>,veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>
801EOF
802
803
804run_test ${lnav_test} -n \
805    -c ':filter-in sudo' \
806    -c ";select * from logline" \
807    -c ':write-csv-to -' \
808    ${test_dir}/logfile_syslog.0
809
810check_output "logline table is not working" <<EOF
811log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,log_hostname,log_msgid,log_pid,log_pri,log_procname,log_struct,syslog_version,log_msg_instance,col_0,TTY,PWD,USER,COMMAND
8120,<NULL>,2007-11-03 09:47:02.000,0,info,0,<NULL>,<NULL>,[1],veridian,<NULL>,<NULL>,<NULL>,sudo,<NULL>,<NULL>,0,timstack,pts/6,/auto/wstimstack/rpms/lbuild/test,root,/usr/bin/tail /var/log/messages
813EOF
814
815
816run_test ${lnav_test} -n \
817    -c ':goto 1' \
818    -c ";select log_line, log_pid, col_0 from logline" \
819    -c ':write-csv-to -' \
820    ${test_dir}/logfile_syslog.1
821
822check_output "logline table is not working" <<EOF
823log_line,log_pid,col_0
8241,16442,/auto/opt
825EOF
826
827run_test ${lnav_test} -n \
828    -c ";select sc_bytes from logline" \
829    -c ':write-csv-to -' \
830    ${test_dir}/logfile_access_log.0
831
832check_output "logline table is not working for defined columns" <<EOF
833sc_bytes
834134
83546210
83678929
837EOF
838
839
840run_test ${lnav_test} -n \
841    -c ':goto 1' \
842    -c ":summarize col_0" \
843    -c ':write-csv-to -' \
844    ${test_dir}/logfile_syslog.1
845
846check_output "summarize is not working" <<EOF
847c_col_0,count_col_0
848/auto/opt,1
849EOF
850
851
852run_test ${lnav_test} -n \
853    -c ";update access_log set log_mark = 1 where sc_bytes > 60000" \
854    -c ':write-to -' \
855    ${test_dir}/logfile_access_log.0
856
857check_output "setting log_mark is not working" <<EOF
858192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
859EOF
860
861
862export SQL_ENV_VALUE="foo bar,baz"
863
864run_test ${lnav_test} -n \
865    -c ';select $SQL_ENV_VALUE as val' \
866    -c ':write-csv-to -' \
867    ${test_dir}/logfile_access_log.0
868
869check_output "env vars are not working in SQL" <<EOF
870val
871"foo bar,baz"
872EOF
873
874
875run_test ${lnav_test} -n \
876    -c ';SELECT name,value FROM environ WHERE name = "SQL_ENV_VALUE"' \
877    -c ':write-csv-to -' \
878    ${test_dir}/logfile_access_log.0
879
880check_output "environ table is not working in SQL" <<EOF
881name,value
882SQL_ENV_VALUE,"foo bar,baz"
883EOF
884
885
886run_test ${lnav_test} -n \
887    -c ';INSERT INTO environ (name) VALUES (null)' \
888    ${test_dir}/logfile_access_log.0
889
890check_error_output "insert into environ table works" <<EOF
891command-option:1: error: A non-empty name and value must be provided when inserting an environment variable
892EOF
893
894check_output "insert into environ table works" <<EOF
895EOF
896
897
898run_test ${lnav_test} -n \
899    -c ';INSERT INTO environ (name, value) VALUES (null, null)' \
900    ${test_dir}/logfile_access_log.0
901
902check_error_output "insert into environ table works" <<EOF
903command-option:1: error: A non-empty name and value must be provided when inserting an environment variable
904EOF
905
906check_output "insert into environ table works" <<EOF
907EOF
908
909
910run_test ${lnav_test} -n \
911    -c ';INSERT INTO environ (name, value) VALUES ("", null)' \
912    ${test_dir}/logfile_access_log.0
913
914check_error_output "insert into environ table works" <<EOF
915command-option:1: error: A non-empty name and value must be provided when inserting an environment variable
916EOF
917
918check_output "insert into environ table works" <<EOF
919EOF
920
921
922run_test ${lnav_test} -n \
923    -c ';INSERT INTO environ (name, value) VALUES ("foo=bar", "bar")' \
924    ${test_dir}/logfile_access_log.0
925
926check_error_output "insert into environ table works" <<EOF
927command-option:1: error: Environment variable names cannot contain an equals sign (=)
928EOF
929
930check_output "insert into environ table works" <<EOF
931EOF
932
933
934run_test ${lnav_test} -n \
935    -c ';INSERT INTO environ (name, value) VALUES ("SQL_ENV_VALUE", "bar")' \
936    ${test_dir}/logfile_access_log.0
937
938check_error_output "insert into environ table works" <<EOF
939command-option:1: error: An environment variable with the name 'SQL_ENV_VALUE' already exists
940EOF
941
942check_output "insert into environ table works" <<EOF
943EOF
944
945
946run_test ${lnav_test} -n \
947    -c ';INSERT OR IGNORE INTO environ (name, value) VALUES ("SQL_ENV_VALUE", "bar")' \
948    -c ';SELECT * FROM environ WHERE name = "SQL_ENV_VALUE"' \
949    -c ':write-csv-to -' \
950    ${test_dir}/logfile_access_log.0
951
952check_output "insert into environ table works" <<EOF
953name,value
954SQL_ENV_VALUE,"foo bar,baz"
955EOF
956
957
958run_test ${lnav_test} -n \
959    -c ';REPLACE INTO environ (name, value) VALUES ("SQL_ENV_VALUE", "bar")' \
960    -c ';SELECT * FROM environ WHERE name = "SQL_ENV_VALUE"' \
961    -c ':write-csv-to -' \
962    ${test_dir}/logfile_access_log.0
963
964check_output "replace into environ table works" <<EOF
965name,value
966SQL_ENV_VALUE,bar
967EOF
968
969
970run_test ${lnav_test} -n \
971    -c ';INSERT INTO environ (name, value) VALUES ("foo_env", "bar")' \
972    -c ';SELECT $foo_env as val' \
973    -c ':write-csv-to -' \
974    ${test_dir}/logfile_access_log.0
975
976check_output "insert into environ table does not work" <<EOF
977val
978bar
979EOF
980
981
982run_test ${lnav_test} -n \
983    -c ';UPDATE environ SET name="NEW_ENV_VALUE" WHERE name="SQL_ENV_VALUE"' \
984    -c ";SELECT * FROM environ WHERE name like '%ENV_VALUE'" \
985    -c ':write-csv-to -' \
986    ${test_dir}/logfile_access_log.0
987
988check_output "update environ table does not work" <<EOF
989name,value
990NEW_ENV_VALUE,"foo bar,baz"
991EOF
992
993
994run_test ${lnav_test} -n \
995    -c ';DELETE FROM environ WHERE name="SQL_ENV_VALUE"' \
996    -c ';SELECT * FROM environ WHERE name like "%ENV_VALUE"' \
997    -c ':write-csv-to -' \
998    ${test_dir}/logfile_access_log.0
999
1000check_output "delete from environ table does not work" <<EOF
1001EOF
1002
1003
1004run_test ${lnav_test} -n \
1005    -c ';DELETE FROM environ' \
1006    -c ';SELECT * FROM environ' \
1007    -c ':write-csv-to -' \
1008    ${test_dir}/logfile_access_log.0
1009
1010check_output "delete environ table does not work" <<EOF
1011EOF
1012
1013
1014run_test ${lnav_test} -n \
1015    -c ';DELETE FROM lnav_views' \
1016    -c ';SELECT count(*) FROM lnav_views' \
1017    -c ':write-csv-to -' \
1018    ${test_dir}/logfile_access_log.0
1019
1020check_output "delete from lnav_views table works?" <<EOF
1021count(*)
10228
1023EOF
1024
1025
1026run_test ${lnav_test} -n \
1027    -c ";INSERT INTO lnav_views (name) VALUES ('foo')" \
1028    -c ';SELECT count(*) FROM lnav_views' \
1029    -c ':write-csv-to -' \
1030    ${test_dir}/logfile_access_log.0
1031
1032check_output "insert into lnav_views table works?" <<EOF
1033count(*)
10348
1035EOF
1036
1037
1038run_test ${lnav_test} -n \
1039    -c ";UPDATE lnav_views SET top = 1 WHERE name = 'log'" \
1040    ${test_dir}/logfile_access_log.0
1041
1042check_output "updating lnav_views.top does not work?" <<EOF
1043192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
1044192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
1045EOF
1046
1047
1048run_test ${lnav_test} -n \
1049    -c ";UPDATE lnav_views SET top = inner_height - 1 WHERE name = 'log'" \
1050    ${test_dir}/logfile_access_log.0
1051
1052check_output "updating lnav_views.top using inner_height does not work?" <<EOF
1053192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
1054EOF
1055
1056
1057run_test ${lnav_test} -n \
1058    -c ";UPDATE lnav_views SET top_time = 'bad-time' WHERE name = 'log'" \
1059    ${test_dir}/logfile_access_log.0
1060
1061check_error_output "updating lnav_views.top_time with a bad time works?" <<EOF
1062command-option:1: error: Invalid time: bad-time
1063EOF
1064
1065
1066run_test ${lnav_test} -n \
1067    -c ";UPDATE lnav_views SET top_time = '2014-10-08T00:00:00' WHERE name = 'log'" \
1068    ${test_dir}/logfile_generic.0
1069
1070check_output "updating lnav_views.top_time does not work?" <<EOF
10712014-10-08 16:56:38,344:WARN:foo bar baz
1072EOF
1073
1074run_test ${lnav_test} -n \
1075    -c ";UPDATE lnav_views SET search = 'warn' WHERE name = 'log'" \
1076    -c ";SELECT search FROM lnav_views WHERE name = 'log'" \
1077    ${test_dir}/logfile_generic.0
1078
1079check_output "updating lnav_views.search does not work?" <<EOF
1080search
1081warn
1082EOF
1083
1084run_test ${lnav_test} -n \
1085    -c ";UPDATE lnav_views SET search = 'warn' WHERE name = 'log'" \
1086    -c ":goto 0" \
1087    -c ":next-mark search" \
1088    ${test_dir}/logfile_generic.0
1089
1090check_output "updating lnav_views.search does not work?" <<EOF
10912014-10-08 16:56:38,344:WARN:foo bar baz
1092EOF
1093
1094
1095schema_dump() {
1096    ${lnav_test} -n -c ';.schema' ${test_dir}/logfile_access_log.0 | head -n19
1097}
1098
1099run_test schema_dump
1100
1101check_output "schema view is not working" <<EOF
1102ATTACH DATABASE '' AS 'main';
1103CREATE VIRTUAL TABLE environ USING environ_vtab_impl();
1104CREATE VIRTUAL TABLE lnav_views USING lnav_views_impl();
1105CREATE VIRTUAL TABLE lnav_view_filter_stats USING lnav_view_filter_stats_impl();
1106CREATE VIRTUAL TABLE lnav_view_files USING lnav_view_files_impl();
1107CREATE VIRTUAL TABLE lnav_view_stack USING lnav_view_stack_impl();
1108CREATE VIRTUAL TABLE lnav_view_filters USING lnav_view_filters_impl();
1109CREATE VIRTUAL TABLE lnav_file USING lnav_file_impl();
1110CREATE VIEW lnav_view_filters_and_stats AS
1111  SELECT * FROM lnav_view_filters LEFT NATURAL JOIN lnav_view_filter_stats;
1112CREATE VIRTUAL TABLE regexp_capture USING regexp_capture_impl();
1113CREATE VIRTUAL TABLE xpath USING xpath_impl();
1114CREATE VIRTUAL TABLE fstat USING fstat_impl();
1115CREATE TABLE http_status_codes (
1116    status integer PRIMARY KEY,
1117    message text,
1118
1119    FOREIGN KEY(status) REFERENCES access_log(sc_status)
1120);
1121EOF
1122
1123
1124run_test ${lnav_test} -n \
1125    -c ";select * from nonexistent_table" \
1126    ${test_dir}/logfile_access_log.0
1127
1128check_error_output "errors are not reported" <<EOF
1129command-option:1: error: no such table: nonexistent_table
1130EOF
1131
1132check_output "errors are not reported" <<EOF
1133EOF
1134
1135
1136run_test ${lnav_test} -n \
1137    -c ";delete from access_log" \
1138    ${test_dir}/logfile_access_log.0
1139
1140check_error_output "errors are not reported" <<EOF
1141command-option:1: error: attempt to write a readonly database
1142EOF
1143
1144check_output "errors are not reported" <<EOF
1145EOF
1146
1147
1148touch -t 201504070732 ${test_dir}/logfile_pretty.0
1149run_test ${lnav_test} -n \
1150    -c ":goto 1" \
1151    -c ":partition-name middle" \
1152    -c ":goto 21" \
1153    -c ":partition-name end" \
1154    -c ";select log_line,log_part,log_time from syslog_log" \
1155    -c ":write-csv-to -" \
1156    ${test_dir}/logfile_pretty.0
1157
1158check_output "partition-name does not work" <<EOF
1159log_line,log_part,log_time
11600,<NULL>,2015-04-07 00:49:42.000
11611,middle,2015-04-07 05:49:53.000
116218,middle,2015-04-07 07:31:56.000
116320,middle,2015-04-07 07:31:56.000
116421,end,2015-04-07 07:31:56.000
116522,end,2015-04-07 07:32:56.000
1166EOF
1167
1168run_test ${lnav_test} -n \
1169    -c ":goto 1" \
1170    -c ":partition-name middle" \
1171    -c ":clear-partition" \
1172    -c ";select log_line, log_part from access_log" \
1173    -c ":write-csv-to -" \
1174    ${test_dir}/logfile_access_log.0
1175
1176check_output "clear-partition does not work" <<EOF
1177log_line,log_part
11780,<NULL>
11791,<NULL>
11802,<NULL>
1181EOF
1182
1183run_test ${lnav_test} -n \
1184    -c ":goto 1" \
1185    -c ":partition-name middle" \
1186    -c ":goto 2" \
1187    -c ":clear-partition" \
1188    -c ";select log_line, log_part from access_log" \
1189    -c ":write-csv-to -" \
1190    ${test_dir}/logfile_access_log.0
1191
1192check_output "clear-partition does not work when in the middle of a part" <<EOF
1193log_line,log_part
11940,<NULL>
11951,<NULL>
11962,<NULL>
1197EOF
1198
1199
1200run_test ${lnav_test} -n \
1201    -c ";SELECT * FROM openam_log" \
1202    -c ":write-json-to -" \
1203    ${test_dir}/logfile_openam.0
1204
1205check_output "write-json-to isn't working?" <<EOF
1206[
1207    {
1208        "log_line": 0,
1209        "log_part": null,
1210        "log_time": "2014-06-15 01:04:52.000",
1211        "log_idle_msecs": 0,
1212        "log_level": "info",
1213        "log_mark": 0,
1214        "log_comment": null,
1215        "log_tags": null,
1216        "log_filters": null,
1217        "contextid": "82e87195d704585501",
1218        "data": "http://localhost:8086|/|<samlp:Response xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"s2daac0735bf476f4560aab81104b623bedfb0cbc0\" InResponseTo=\"84cbf2be33f6410bbe55877545a93f02\" Version=\"2.0\" IssueInstant=\"2014-06-15T01:04:52Z\" Destination=\"http://localhost:8086/api/1/rest/admin/org/530e42ccd6f45fd16d0d0717/saml/consume\"><saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">http://openam.vagrant.dev/openam</saml:Issuer><samlp:Status xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">\\\\n<samlp:StatusCode  xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"\\\\nValue=\"urn:oasis:names:tc:SAML:2.0:status:Success\">\\\\n</samlp:StatusCode>\\\\n</samlp:Status><saml:Assertion xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"s2a0bee0da937e236167e99b209802056033816ac2\" IssueInstant=\"2014-06-15T01:04:52Z\" Version=\"2.0\">\\\\n<saml:Issuer>http://openam.vagrant.dev/openam</saml:Issuer><ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\\\\n<ds:SignedInfo>\\\\n<ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\\\\n<ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\\\\n<ds:Reference URI=\"#s2a0bee0da937e236167e99b209802056033816ac2\">\\\\n<ds:Transforms>\\\\n<ds:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\\\\n<ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\\\\n</ds:Transforms>\\\\n<ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\\\\n<ds:DigestValue>4uSmVzjovUdQd3px/RcnoxQBsqE=</ds:DigestValue>\\\\n</ds:Reference>\\\\n</ds:SignedInfo>\\\\n<ds:SignatureValue>\\\\nhm/grge36uA6j1OWif2bTcvVTwESjmuJa27NxepW0AiV5YlcsHDl7RAIk6k/CjsSero3bxGbm56m\\\\nYncOEi9F1Tu7dS0bfx+vhm/kKTPgwZctf4GWn4qQwP+KeoZywbNj9ShsYJ+zPKzXwN4xBSuPjMxP\\\\nNf5szzjEWpOndQO/uDs=\\\\n</ds:SignatureValue>\\\\n<ds:KeyInfo>\\\\n<ds:X509Data>\\\\n<ds:X509Certificate>\\\\nMIICQDCCAakCBEeNB0swDQYJKoZIhvcNAQEEBQAwZzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNh\\\\nbGlmb3JuaWExFDASBgNVBAcTC1NhbnRhIENsYXJhMQwwCgYDVQQKEwNTdW4xEDAOBgNVBAsTB09w\\\\nZW5TU08xDTALBgNVBAMTBHRlc3QwHhcNMDgwMTE1MTkxOTM5WhcNMTgwMTEyMTkxOTM5WjBnMQsw\\\\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEUMBIGA1UEBxMLU2FudGEgQ2xhcmExDDAK\\\\nBgNVBAoTA1N1bjEQMA4GA1UECxMHT3BlblNTTzENMAsGA1UEAxMEdGVzdDCBnzANBgkqhkiG9w0B\\\\nAQEFAAOBjQAwgYkCgYEArSQc/U75GB2AtKhbGS5piiLkmJzqEsp64rDxbMJ+xDrye0EN/q1U5Of+\\\\nRkDsaN/igkAvV1cuXEgTL6RlafFPcUX7QxDhZBhsYF9pbwtMzi4A4su9hnxIhURebGEmxKW9qJNY\\\\nJs0Vo5+IgjxuEWnjnnVgHTs1+mq5QYTA7E6ZyL8CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB3Pw/U\\\\nQzPKTPTYi9upbFXlrAKMwtFf2OW4yvGWWvlcwcNSZJmTJ8ARvVYOMEVNbsT4OFcfu2/PeYoAdiDA\\\\ncGy/F2Zuj8XJJpuQRSE6PtQqBuDEHjjmOQJ0rV/r8mO1ZCtHRhpZ5zYRjhRC9eCbjx9VrFax0JDC\\\\n/FfwWigmrW0Y0Q==\\\\n</ds:X509Certificate>\\\\n</ds:X509Data>\\\\n</ds:KeyInfo>\\\\n</ds:Signature><saml:Subject>\\\\n<saml:NameID Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress\" NameQualifier=\"http://openam.vagrant.dev/openam\">user@example.com</saml:NameID><saml:SubjectConfirmation Method=\"urn:oasis:names:tc:SAML:2.0:cm:bearer\">\\\\n<saml:SubjectConfirmationData InResponseTo=\"84cbf2be33f6410bbe55877545a93f02\" NotOnOrAfter=\"2014-06-15T01:14:52Z\" Recipient=\"http://localhost:8086/api/1/rest/admin/org/530e42ccd6f45fd16d0d0717/saml/consume\"/></saml:SubjectConfirmation>\\\\n</saml:Subject><saml:Conditions NotBefore=\"2014-06-15T00:54:52Z\" NotOnOrAfter=\"2014-06-15T01:14:52Z\">\\\\n<saml:AudienceRestriction>\\\\n<saml:Audience>http://localhost:8086</saml:Audience>\\\\n</saml:AudienceRestriction>\\\\n</saml:Conditions>\\\\n<saml:AuthnStatement AuthnInstant=\"2014-06-15T01:00:25Z\" SessionIndex=\"s2f9b4d4b453d12b40ef3905cc959cdb40579c2301\"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement></saml:Assertion></samlp:Response>",
1219        "domain": "dc=openam",
1220        "hostname": "192.168.33.1\t",
1221        "ipaddr": "Not Available",
1222        "loggedby": "cn=dsameuser,ou=DSAME Users,dc=openam",
1223        "loginid": "id=openamuser,ou=user,dc=openam",
1224        "messageid": "SAML2-37",
1225        "modulename": "SAML2.access",
1226        "nameid": "user@example.com"
1227    },
1228    {
1229        "log_line": 1,
1230        "log_part": null,
1231        "log_time": "2014-06-15 01:04:52.000",
1232        "log_idle_msecs": 0,
1233        "log_level": "trace",
1234        "log_mark": 0,
1235        "log_comment": null,
1236        "log_tags": null,
1237        "log_filters": null,
1238        "contextid": "ec5708a7f199678a01",
1239        "data": "vagrant|/",
1240        "domain": "dc=openam",
1241        "hostname": "127.0.1.1\t",
1242        "ipaddr": "Not Available",
1243        "loggedby": "cn=dsameuser,ou=DSAME Users,dc=openam",
1244        "loginid": "cn=dsameuser,ou=DSAME Users,dc=openam",
1245        "messageid": "COT-22",
1246        "modulename": "COT.access",
1247        "nameid": "Not Available"
1248    }
1249]
1250EOF
1251
1252run_test ${lnav_test} -d "/tmp/lnav.err" -n \
1253    -c ";select log_line, log_msg_instance, col_0 from logline" \
1254    ${test_dir}/logfile_for_join.0
1255
1256check_output "log msg instance is not working" <<EOF
1257log_line log_msg_instance   col_0
1258       0                0 eth0.IPv4
1259       7                1 eth0.IPv4
1260EOF
1261
1262run_test ${lnav_test} -d "/tmp/lnav.err" -n \
1263    -c ";select log_msg_instance, col_0 from logline where log_line > 4" \
1264    ${test_dir}/logfile_for_join.0
1265
1266check_output "log msg instance is not working" <<EOF
1267log_msg_instance   col_0
1268               1 eth0.IPv4
1269EOF
1270
1271run_test ${lnav_test} -d "/tmp/lnav.err" -n \
1272    -c ":goto 1" \
1273    -c ":create-logline-table join_group" \
1274    -c ":goto 2" \
1275    -c ";select logline.log_line as llline, join_group.log_line as jgline from logline, join_group where logline.col_0 = join_group.col_2" \
1276    -c ':write-csv-to -' \
1277    ${test_dir}/logfile_for_join.0
1278
1279check_output "create-logline-table is not working" <<EOF
1280llline,jgline
12812,1
12822,8
12839,1
12849,8
1285EOF
1286
1287
1288run_test ${lnav_test} -n \
1289    -c ";select log_body from syslog_log where log_procname = 'automount'" \
1290    < ${test_dir}/logfile_syslog.0
1291
1292check_output "querying against stdin is not working?" <<EOF
1293                log_body
1294 lookup(file): lookup for foobar failed
1295 attempting to mount entry /auto/opt
1296 lookup(file): lookup for opt failed
1297EOF
1298
1299
1300run_test ${lnav_test} -n \
1301    -c ";select log_body from syslog_log where log_procname = 'sudo'" \
1302    < ${test_dir}/logfile_syslog.0
1303
1304check_output "single result is not working?" <<EOF
1305                                                      log_body
1306 timstack : TTY=pts/6 ; PWD=/auto/wstimstack/rpms/lbuild/test ; USER=root ; COMMAND=/usr/bin/tail /var/log/messages
1307EOF
1308
1309# Create a dummy database for the next couple of tests to consume.
1310touch empty
1311run_test ${lnav_test} -n \
1312    -c ";ATTACH DATABASE 'simple-db.db' as 'db'" \
1313    -c ";CREATE TABLE IF NOT EXISTS db.person ( id integer PRIMARY KEY, first_name text, last_name, age integer )" \
1314    -c ";INSERT INTO db.person(id, first_name, last_name, age) VALUES (0, 'Phil', 'Myman', 30)" \
1315    -c ";INSERT INTO db.person(id, first_name, last_name, age) VALUES (1, 'Lem', 'Hewitt', 35)" \
1316    -c ";DETACH DATABASE 'db'" \
1317    empty
1318
1319check_output "Could not create db?" <<EOF
1320EOF
1321
1322# Test to see if lnav can recognize a sqlite3 db file passed in as an argument.
1323run_test ${lnav_test} -n -c ";select * from person order by age asc" \
1324    simple-db.db
1325
1326check_output "lnav not able to recognize sqlite3 db file?" <<EOF
1327id first_name last_name age
1328 0 Phil       Myman      30
1329 1 Lem        Hewitt     35
1330EOF
1331
1332# Test to see if lnav can recognize a sqlite3 db file passed in as an argument.
1333# XXX: Need to pass in a file, otherwise lnav keeps trying to open syslog
1334# and we might not have sufficient privileges on the system the tests are being
1335# run on.
1336run_test ${lnav_test} -n \
1337    -c ";attach database 'simple-db.db' as 'db'" \
1338    -c ';select * from person order by age asc' \
1339    empty
1340
1341check_output "lnav not able to attach sqlite3 db file?" <<EOF
1342id first_name last_name age
1343 0 Phil       Myman      30
1344 1 Lem        Hewitt     35
1345EOF
1346
1347# Test to see if we can attach a database in LNAVSECURE mode.
1348export LNAVSECURE=1
1349
1350run_test ${lnav_test} -n \
1351    -c ";attach database 'simple-db.db' as 'db'" \
1352    empty
1353
1354check_error_output "LNAVSECURE mode bypassed" <<EOF
1355command-option:1: error: not authorized
1356EOF
1357
1358run_test ${lnav_test} -n \
1359    -c ";attach database ':memdb:' as 'db'" \
1360    empty
1361
1362check_error_output "LNAVSECURE mode bypassed (':' adorned)" <<EOF
1363command-option:1: error: not authorized
1364EOF
1365
1366run_test ${lnav_test} -n \
1367    -c ";attach database '/tmp/memdb' as 'db'" \
1368    empty
1369
1370check_error_output "LNAVSECURE mode bypassed (filepath)" <<EOF
1371command-option:1: error: not authorized
1372EOF
1373
1374run_test ${lnav_test} -n \
1375    -c ";attach database 'file:memdb?cache=shared' as 'db'" \
1376    empty
1377
1378check_error_output "LNAVSECURE mode bypassed (URI)" <<EOF
1379command-option:1: error: not authorized
1380EOF
1381
1382unset LNAVSECURE
1383
1384
1385touch -t 201503240923 ${test_dir}/logfile_syslog_with_access_log.0
1386run_test ${lnav_test} -n -d /tmp/lnav.err \
1387    -c ";select * from access_log" \
1388    -c ':write-csv-to -' \
1389    ${test_dir}/logfile_syslog_with_access_log.0
1390
1391check_output "access_log not found within syslog file" <<EOF
1392log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status,cs_host
13931,<NULL>,2015-03-24 14:02:50.000,6927348000,info,0,<NULL>,<NULL>,<NULL>,127.0.0.1,GET,<NULL>,<NULL>,/includes/js/combined-javascript.js,<NULL>,-,HTTP/1.1,65508,200,<NULL>
13942,<NULL>,2015-03-24 14:02:50.000,0,error,0,<NULL>,<NULL>,<NULL>,127.0.0.1,GET,<NULL>,<NULL>,/bad.foo,<NULL>,-,HTTP/1.1,65508,404,<NULL>
1395EOF
1396
1397
1398run_test ${lnav_test} -n \
1399    -c ";select log_text from generic_log" \
1400    -c ":write-json-to -" \
1401    ${test_dir}/logfile_multiline.0
1402
1403check_output "multiline data is not right?" <<EOF
1404[
1405    {
1406        "log_text": "2009-07-20 22:59:27,672:DEBUG:Hello, World!\n  How are you today?"
1407    },
1408    {
1409        "log_text": "2009-07-20 22:59:30,221:ERROR:Goodbye, World!"
1410    }
1411]
1412EOF
1413
1414run_test ${lnav_test} -n \
1415    -c ";select log_text from generic_log where log_line = 1" \
1416    -c ":write-json-to -" \
1417    ${test_dir}/logfile_multiline.0
1418
1419check_output "able to select a continued line?" <<EOF
1420EOF
1421
1422
1423run_test ${lnav_test} -n \
1424    -c ":create-search-table search_test1 (\w+), world!" \
1425    -c ";select log_msg_instance, col_0 from search_test1" \
1426    -c ":write-csv-to -" \
1427    ${test_dir}/logfile_multiline.0
1428
1429check_output "create-search-table is not working?" <<EOF
1430log_msg_instance,col_0
14310,Hello
14321,Goodbye
1433EOF
1434
1435run_test ${lnav_test} -n \
1436    -c ":create-search-table search_test1 (\w+), World!" \
1437    -c ";select log_msg_instance, col_0 from search_test1 where log_line > 0" \
1438    -c ":write-csv-to -" \
1439    ${test_dir}/logfile_multiline.0
1440
1441check_output "create-search-table is not working with where clause?" <<EOF
1442log_msg_instance,col_0
14431,Goodbye
1444EOF
1445
1446run_test ${lnav_test} -n \
1447    -c ":create-search-table search_test1 (?<word>\w+), World!" \
1448    -c ";select word, typeof(word) from search_test1" \
1449    -c ":write-csv-to -" \
1450    ${test_dir}/logfile_multiline.0
1451
1452check_output "create-search-table is not working?" <<EOF
1453word,typeof(word)
1454Hello,text
1455Goodbye,text
1456EOF
1457
1458run_test ${lnav_test} -n \
1459    -c ":create-search-table search_test1 eth(?<ethnum>\d+)" \
1460    -c ";select typeof(ethnum) from search_test1" \
1461    -c ":write-csv-to -" \
1462    ${test_dir}/logfile_syslog.2
1463
1464check_output "regex type guessing is not working?" <<EOF
1465typeof(ethnum)
1466integer
1467integer
1468integer
1469EOF
1470
1471run_test ${lnav_test} -n \
1472    -c ":delete-search-table search_test1" \
1473    ${test_dir}/logfile_multiline.0
1474
1475check_error_output "able to delete unknown table?" <<EOF
1476command-option:1: error: unknown search table -- search_test1
1477EOF
1478
1479run_test ${lnav_test} -n \
1480    -c ":create-logline-table search_test1" \
1481    -c ":delete-search-table search_test1" \
1482    ${test_dir}/logfile_multiline.0
1483
1484check_error_output "able to delete logline table?" <<EOF
1485command-option:2: error: unknown search table -- search_test1
1486EOF
1487
1488run_test ${lnav_test} -n \
1489    -c ":create-search-table search_test1 bad(" \
1490    ${test_dir}/logfile_multiline.0
1491
1492check_error_output "able to create table with a bad regex?" <<EOF
1493command-option:1: error: missing )
1494EOF
1495
1496NULL_GRAPH_SELECT_1=$(cat <<EOF
1497;SELECT value FROM (
1498              SELECT 10 as value
1499    UNION ALL SELECT null as value)
1500EOF
1501)
1502
1503run_test ${lnav_test} -n \
1504    -c "$NULL_GRAPH_SELECT_1" \
1505    -c ":write-csv-to -" \
1506    ${test_dir}/logfile_multiline.0
1507
1508check_output "number column with null does not work?" <<EOF
1509value
151010
1511<NULL>
1512EOF
1513
1514run_test ${lnav_test} -n \
1515    -c ";SELECT regexp_capture.content FROM access_log, regexp_capture(access_log.cs_version, 'HTTP/(\d+\.\d+)') WHERE regexp_capture.capture_index = 1" \
1516    -c ':write-csv-to -' \
1517    ${test_dir}/logfile_access_log.0
1518
1519check_output "joining log table with regexp_capture is not working?" <<EOF
1520content
15211.0
15221.0
15231.0
1524EOF
1525