-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathfile_base.go
60 lines (51 loc) · 1.3 KB
/
file_base.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
package test
import (
"os"
"path/filepath"
"testing"
"github.com/ozonru/file.d/pipeline"
"github.com/stretchr/testify/assert"
)
// The file_base contains helpers function for testing file base output plugins
// output/file and output/s3
type Msg []byte
func SendPack(t *testing.T, p *pipeline.Pipeline, msgs []Msg) int64 {
t.Helper()
var sent int64 = 0
for _, m := range msgs {
p.In(0, "test", 0, m, false)
// count \n
sent += int64(len(m)) + 1
}
return sent
}
func ClearDir(t *testing.T, dir string) {
t.Helper()
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("could not delete dirs and files after tests, error: %s", err.Error())
}
}
func GetMatches(t *testing.T, pattern string) []string {
t.Helper()
matches, err := filepath.Glob(pattern)
assert.NoError(t, err)
return matches
}
func CheckZero(t *testing.T, target string, msg string) int64 {
t.Helper()
info, err := os.Stat(target)
assert.NoErrorf(t, err, "there is no target: %s", target, msg)
assert.NotNil(t, info, msg)
assert.Zero(t, info.Size(), msg)
return info.Size()
}
func CheckNotZero(t *testing.T, target string, msg string) int64 {
t.Helper()
info, err := os.Stat(target)
assert.NoError(t, err, msg)
assert.NotNil(t, info, msg)
if info.Size() == 0 {
assert.NotZero(t, info.Size(), msg)
}
return info.Size()
}