forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreformat_test.go
64 lines (58 loc) · 1.16 KB
/
reformat_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
package repository
import (
"strings"
"testing"
"github.com/Velocidex/ordereddict"
"github.com/sebdah/goldie/v2"
"github.com/stretchr/testify/assert"
"www.velocidex.com/golang/velociraptor/json"
)
type reformatCases_t struct {
name string
in, out string
}
var reformatCases = []reformatCases_t{
{name: "Simple",
in: `
name: Foo
sources:
- query: |
SELECT A,B,C
FROM info(arg1=Foobar, arg2="XXXXX")
- query: |-
SELECT A,B,C FROM info()
- description: Foo bar
`}, {
name: "Single line queries are not reformatted.",
in: `
name: Single line
sources:
- query: SELECT * FROM info()
- query: |
SELECT A FROM scope()
`}, {
name: "export reformatted",
in: `
name: Exported
export: |
SELECT * FROM scope()
`}, {
name: "preconditions",
in: `
name: Preconditions
precondition: SELECT * FROM info()
sources:
- precondition: |
SELECT * FROM info()
`},
}
func TestReformat(t *testing.T) {
golden := ordereddict.NewDict()
for _, c := range reformatCases {
out, err := reformatVQL(c.in)
assert.NoError(t, err)
golden.Set(c.name, strings.Split(out, "\n"))
}
g := goldie.New(t)
g.Assert(t, "TestReformat", json.MustMarshalIndent(golden))
}