File: Testing.md

package info (click to toggle)
mtail 3.2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,384 kB
  • sloc: yacc: 647; makefile: 226; sh: 78; lisp: 77; awk: 17
file content (65 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download
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
# Testing `mtail` programmes

## Introduction

By default any compile errors are logged to the standard log `/tmp/mtail.INFO`
unless otherwise redirected.  (You can emit to standard out with
`--logtostderr` flag.)  Program errors are also printed on the HTTP status
handler, by default at port 3903.

If you want more debugging information, `mtail` provides a few flags to assist with testing your program in standalone mode.

# Details

## Compilation errors

The `compile_only` flag will run the `mtail` compiler, print any error messages, and then exit.

You can use this to check your programs are syntactically valid during the development process.

```
mtail --compile_only --progs ./progs
```

This could be added as a pre-commit hook to your source code repository.

## Testing programs

The `one_shot` flag will compile and run the `mtail` programs, then feed in any
logs specified from the beginning of the file (instead of tailing them), then
print to the log all metrics collected.

You can use this to check that your programs are giving the expected output
against some gold standard log file samples.

```
mtail --one_shot --progs ./progs --logs testdata/foo.log
```

### Continuous Testing

If you wish, send a PR containing your program, some sample input, and a golden
output to be run as a test in
http://github.com/jaqx0r/mtail/blob/main/ex_test.go to ensure that mtail
never breaks your program (or that your program gets any updates if the
language changes.)

To have a syntax-only compile test, merely send in a PR with the program in the
examples directory.

The `TestExamplePrograms` behaves like the `one_shot` flag, and
`TestCompileExamplePrograms` tests that program syntax is correct.

# Test writing

Use the `testutil` module where possible.

Do not use time.Sleep; poll for events.  The `TestServer` provides a `PollWatched()` method for this purpose.  Even integration tests which write to disk can be fast and not require sleeps to synchronise.

Use the `if testing.Short()` signal in tests with disk access so that the `make smoke` command is fast.

Do not comment out tests, prefer to use the t.Skip() method indicating why it's not working if a test needs to be disabled.  This keeps them visible and compilable.

# Troubleshooting

For more information about debugging mtail programs, see the tips under [Troubleshooting](Troubleshooting.md)