MCPcopy Create free account
hub / github.com/AdRoll/baker / TestRunFilterChainMetadata

Function TestRunFilterChainMetadata

topology_test.go:22–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20func (d *dummyInput) FreeMem(data *Data) {}
21
22func TestRunFilterChainMetadata(t *testing.T) {
23 // Test the same metadata provided by Input can be accessed inside the filters,
24 // a simpler version of t.chain was used since the same LogLine received in the chain
25 // is passed down to the filters, so we can check there if the same metadata is available.
26 rawLine := LogLine{FieldSeparator: DefaultLogLineFieldSeparator}
27 rawLine.Set(0, []byte("test"))
28 line := rawLine.ToText(nil)
29 lastModified := time.Unix(1234, 5678)
30 url := &url.URL{
31 Scheme: "fake",
32 Host: "fake",
33 Path: "fake"}
34
35 inch := make(chan *Data)
36 defer close(inch)
37 chainCalled := false
38 topo := &Topology{
39 // Populate fields needed by runFilterChain
40 inch: inch,
41 Input: &dummyInput{},
42 linePool: sync.Pool{
43 New: func() interface{} {
44 return &LogLine{
45 FieldSeparator: DefaultLogLineFieldSeparator,
46 }
47 },
48 },
49 // Simpler version
50 chain: func(l Record) {
51 if v, _ := l.Meta("last_modified"); v != lastModified {
52 t.Errorf("missing metadata in logline expected last modified = %s got = %s", lastModified, v)
53 }
54 if v, _ := l.Meta("url"); v != url {
55 t.Errorf("missing metadata in logline; expected url = %#v, got #%v", url, v)
56 }
57 chainCalled = true
58 },
59 }
60 go func() {
61 topo.runFilterChain()
62 if !chainCalled {
63 t.Error("expected Topology.chain to be called.")
64 }
65 }()
66
67 inch <- &Data{
68 Bytes: line,
69 Meta: Metadata{
70 "last_modified": lastModified,
71 "url": url,
72 },
73 }
74}
75
76func Test_makeUnivocal(t *testing.T) {
77 tests := []struct {

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
ToTextMethod · 0.95
runFilterChainMethod · 0.95
MetaMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected