-
Notifications
You must be signed in to change notification settings - Fork 8
/
logging_test.go
61 lines (49 loc) · 1.26 KB
/
logging_test.go
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
package vfilter
import (
"context"
"io"
"log"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"www.velocidex.com/golang/vfilter/utils"
)
type logWriter struct {
io.Writer
logs []string
}
func (self *logWriter) Write(b []byte) (int, error) {
self.logs = append(self.logs, string(b))
return self.Writer.Write(b)
}
func (self *logWriter) Contains(t *testing.T, member string) {
for _, line := range self.logs {
if strings.Contains(line, member) {
return
}
}
assert.Fail(t, member)
}
func (self *logWriter) NotContains(t *testing.T, member string) {
for _, line := range self.logs {
if strings.Contains(line, member) {
assert.Fail(t, member)
}
}
}
func TestLogging(t *testing.T) {
scope := makeTestScope()
logger := &logWriter{Writer: os.Stdout}
scope.SetLogger(log.New(logger, "Log: ", log.Ldate|log.Ltime|log.Lshortfile))
vql, err := Parse("SELECT X, X.Foo, Y, Y.Foo FROM foreach(row=[dict(X=1),])")
assert.NoError(t, err)
ctx := context.Background()
for row := range vql.Eval(ctx, scope) {
utils.Debug(row)
}
logger.Contains(t, "Symbol Y not found")
logger.Contains(t, "While resolving Y.Foo Symbol Y not found")
logger.NotContains(t, "Symbol X not found")
logger.NotContains(t, "While resolving X.Foo Symbol X not found")
}