forked from AlexMarco7/aclow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaclow-testgen.go
83 lines (58 loc) · 1.39 KB
/
aclow-testgen.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
package aclow
import (
"bufio"
"encoding/json"
"os"
"html/template"
)
func GenerateTests(src string, dest string) {
fileHandle, _ := os.Open(src)
defer fileHandle.Close()
destFile, err := os.Create(dest)
check(err)
writer := bufio.NewWriter(destFile)
defer destFile.Close()
fileScanner := bufio.NewScanner(fileHandle)
dict := map[string][]interface{}{}
for fileScanner.Scan() {
line := fileScanner.Text()
if len(line) > 9 && line[0:9] == "aclow:>>>" {
line = line[10:len(line)]
} else if len(line) > 29 && line[20:29] == "aclow:>>>" {
line = line[29:len(line)]
} else {
continue
}
var obj interface{}
json.Unmarshal([]byte(line), &obj)
if obj == nil {
continue
}
executionID := obj.(map[string]interface{})["execution_id"].(string)
if dict[executionID] != nil {
dict[executionID] = append(dict[executionID], obj)
} else {
dict[executionID] = []interface{}{obj}
}
}
for _, v := range dict {
buildTest(v, writer)
}
destFile.Sync()
writer.Flush()
check(fileScanner.Err())
}
func buildTest(events []interface{}, writer *bufio.Writer) {
fn := template.FuncMap{
"noescape": noescape,
}
tmpl := template.Must(template.New("template.tmpl").Funcs(fn).Parse("teste"))
t := TestResource{}
err := tmpl.Execute(writer, t)
check(err)
}
func noescape(str string) template.HTML {
return template.HTML(str)
}
type TestResource struct {
}