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

Function TestListBasic

input/list_test.go:89–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestListBasic(t *testing.T) {
90 dir, rmdir := testutil.TempDir(t)
91 defer rmdir()
92
93 makeTestLog(t, dir, "test7.log.gz", 7)
94 makeTestLog(t, dir, "test100.log.gz", 100)
95 makeTestLog(t, dir, "test500.log.gz", 500)
96 makeTestLog(t, dir, "test1233.log.gz", 1233)
97 os.WriteFile(filepath.Join(dir, "testlist600"),
98 []byte(pathToURI(filepath.Join(dir, "test100.log.gz"))+"\n"+
99 pathToURI(filepath.Join(dir, "test500.log.gz"))+"\n"),
100 0777)
101 os.WriteFile(filepath.Join(dir, "buglist"),
102 []byte(pathToURI(filepath.Join(dir, "test100.log.gz"))+"\n"+
103 pathToURI(filepath.Join(dir, "nonesisting.log.gz"))+"\n"),
104 0777)
105
106 var tests = []struct {
107 Files []string
108 Lines int64
109 }{
110 {[]string{"test7.log.gz"}, 7},
111 {[]string{"test1233.log.gz"}, 1233},
112 {[]string{"test100.log.gz", "test500.log.gz"}, 600},
113 {[]string{"@testlist600"}, 600},
114 {[]string{"test100.log.gz", "@testlist600", "test7.log.gz"}, 707},
115 {[]string{"test100.log.gz", "nonexisting.log.gz"}, -1},
116 {[]string{"test100.log.gz", "@buglist"}, -1},
117 {[]string{"@-", "@buglist"}, -1},
118 }
119
120 ch := make(chan *baker.Data)
121 defer close(ch)
122
123 var counter int64
124 go func() {
125 for data := range ch {
126 atomic.AddInt64(&counter, int64(bytes.Count(data.Bytes, []byte{'\n'})))
127 // Check the metadata contains a valid last modified date
128 if v := data.Meta["last_modified"]; !v.(time.Time).After(time.Unix(0, 0)) {
129 t.Errorf("Invalid last modified time in file, it should be after %s.", time.Unix(0, 0))
130 }
131 }
132 }()
133
134 for _, test := range tests {
135 for idx := range test.Files {
136 if test.Files[idx][0] == '@' {
137 test.Files[idx] = "@" + pathToURI(filepath.Join(dir, test.Files[idx][1:]))
138 } else {
139 test.Files[idx] = pathToURI(filepath.Join(dir, test.Files[idx]))
140 }
141 }
142 cfg := baker.InputParams{
143 ComponentParams: baker.ComponentParams{
144 DecodedConfig: &ListConfig{Files: test.Files},
145 },
146 }

Callers

nothing calls this directly

Calls 6

RunMethod · 0.95
TempDirFunction · 0.92
makeTestLogFunction · 0.85
NewListFunction · 0.85
pathToURIFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected