forked from AdRoll/baker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopology_test.go
More file actions
73 lines (67 loc) · 1.73 KB
/
topology_test.go
File metadata and controls
73 lines (67 loc) · 1.73 KB
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
package baker
import (
"net/url"
"sync"
"testing"
"time"
)
type dummyInput struct{}
func (d *dummyInput) Run(output chan<- *Data) error {
return nil
}
func (d *dummyInput) Stats() InputStats {
return InputStats{}
}
func (d *dummyInput) Stop() {}
func (d *dummyInput) FreeMem(data *Data) {}
func TestRunFilterChainMetadata(t *testing.T) {
// Test the same metadata provided by Input can be accessed inside the filters,
// a simpler version of t.chain was used since the same LogLine received in the chain
// is passed down to the filters, so we can check there if the same metadata is available.
rawLine := LogLine{FieldSeparator: DefaultLogLineFieldSeparator}
rawLine.Set(0, []byte("test"))
line := rawLine.ToText(nil)
lastModified := time.Unix(1234, 5678)
url := &url.URL{
Scheme: "fake",
Host: "fake",
Path: "fake"}
inch := make(chan *Data)
defer close(inch)
chainCalled := false
topo := &Topology{
// Populate fields needed by runFilterChain
inch: inch,
Input: &dummyInput{},
linePool: sync.Pool{
New: func() interface{} {
return &LogLine{
FieldSeparator: DefaultLogLineFieldSeparator,
}
},
},
// Simpler version
chain: func(l Record) {
if v, _ := l.Meta("last_modified"); v != lastModified {
t.Errorf("missing metadata in logline expected last modified = %s got = %s", lastModified, v)
}
if v, _ := l.Meta("url"); v != url {
t.Errorf("missing metadata in logline; expected url = %#v, got #%v", url, v)
}
chainCalled = true
},
}
go func() {
topo.runFilterChain()
if !chainCalled {
t.Error("expected Topology.chain to be called.")
}
}()
inch <- &Data{
Bytes: line,
Meta: Metadata{
"last_modified": lastModified,
"url": url,
},
}
}