-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser_test.go
80 lines (67 loc) · 1.87 KB
/
parser_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
package main
import (
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJSONParser(t *testing.T) {
expected := []*SecretData{
&SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: `{"user": "myuser", "password": "s3cr3t", "host": "localhost:5432"}`,
ContentKey: "host",
ContentValue: "localhost:5432",
},
&SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: `{"user": "myuser", "password": "s3cr3t", "host": "localhost:5432"}`,
ContentKey: "password",
ContentValue: "s3cr3t",
},
&SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: `{"user": "myuser", "password": "s3cr3t", "host": "localhost:5432"}`,
ContentKey: "user",
ContentValue: "myuser",
},
}
s := &SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: `{"user": "myuser", "password": "s3cr3t", "host": "localhost:5432"}`,
}
p := &JSONContentParser{}
ss := p.Parse(s)
// just to ensure the order of the result
// it's only important for the test
sort.Slice(ss, func(i, j int) bool {
return ss[i].ContentKey < ss[j].ContentKey
})
for i := 0; i < len(expected); i++ {
assert.Equal(t, expected[i], ss[i])
}
}
func TestNoParser(t *testing.T) {
expected := []*SecretData{
&SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: `{"user": "myuser", "password": "s3cr3t", "host": "localhost:5432"}`,
ContentKey: "",
ContentValue: "",
},
}
s := &SecretData{
Path: "/project/123/secrets/mysecret",
Name: "mysecret",
Data: `{"user": "myuser", "password": "s3cr3t", "host": "localhost:5432"}`,
}
p := &NoParser{}
ss := p.Parse(s)
for i := 0; i < len(expected); i++ {
assert.Equal(t, expected[i], ss[i])
}
}