-
Notifications
You must be signed in to change notification settings - Fork 4
/
loader_test.go
executable file
·95 lines (75 loc) · 2.02 KB
/
loader_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package go4data
import (
"fmt"
"os"
"testing"
"time"
"github.com/percybolmer/go4data/handlers/files"
)
func generateProcs(t *testing.T) []*Processor {
listDirProc := NewProcessor("listdir", "found_files")
readFileProc := NewProcessor("readfile", "file_data")
listDirProc.SetHandler(files.NewListDirectoryHandler())
readFileProc.SetHandler(files.NewReadFileHandler())
cfg := listDirProc.GetConfiguration()
err := cfg.SetProperty("path", "testing")
if err != nil {
t.Fatal(err)
}
err = cfg.SetProperty("buffertime", 2)
if err != nil {
t.Fatal(err)
}
readFileProc.GetConfiguration().SetProperty("remove_after", false)
readFileProc.Subscribe("found_files")
processors := make([]*Processor, 2)
processors[0] = listDirProc
processors[1] = readFileProc
return processors
}
func TestSave(t *testing.T) {
procs := generateProcs(t)
err := Save("testing/loader/save.yml", procs)
if err != nil {
t.Fatal(err)
}
os.Remove("testing/loader/save.yml")
}
func TestLoad(t *testing.T) {
procs := generateProcs(t)
loaders := make([]*LoaderProccessor, 0)
for _, proc := range procs {
proc.Running = true
loaders = append(loaders, proc.ConvertToLoader())
}
Save("testing/loader/loadthis.yml", loaders)
loaded, err := Load("testing/loader/loadthis.yml")
if err != nil {
t.Fatal(err)
}
// Since we forced Running to be true for the procs, we should now be able to fetch data from file_data topic with stdout proc
time.Sleep(1 * time.Second)
mets := loaded[1].Metric.GetMetrics()
payin := fmt.Sprintf("%s_%d_payloads_in", loaded[1].Name, loaded[1].ID)
if mets[payin] == nil {
t.Fatal("ReadFile proc should have atleast 1 input")
}
_, err = Load("nosuchfile")
if err == nil {
t.Fatal("Should have failed to load this")
}
}
func TestLoadMap(t *testing.T) {
_, err := Load("testing/loader/loadMap.yml")
if err != nil {
t.Fatal(err)
}
///t.Logf("%+v", loaded)
}
func TestLoadSlice(t *testing.T) {
loaded, err := Load("testing/loader/loadSlice.yml")
if err != nil {
t.Fatal(err)
}
t.Logf("%+v", loaded)
}