-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml_test.go
60 lines (50 loc) · 1.33 KB
/
yaml_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
package keycloak
import (
"io/ioutil"
"testing"
"filippo.io/age"
"github.com/nsf/jsondiff"
"github.com/stretchr/testify/assert"
k8syaml "sigs.k8s.io/yaml"
)
func TestYAMLBasic(t *testing.T) {
yamls := []struct {
file string
path []string
}{
{
file: "testdata/creds1.yaml",
path: []string{"secrets"},
},
}
for _, test := range yamls {
runTestYAMLBasic(t, test.file, test.path)
}
}
func runTestYAMLBasic(t *testing.T, file string, path []string) {
bites, err := ioutil.ReadFile(file)
assert.Nil(t, err)
yStore, err := newYAMLStore(bites)
assert.Nil(t, err)
ageIdentity, err := age.GenerateX25519Identity()
assert.Nil(t, err)
ageRecipient := ageIdentity.Recipient()
err = yStore.EncryptSubtree(ageRecipient.String(), path...)
assert.Nil(t, err)
err = yStore.DecryptSubtree(ageIdentity.String(), path...)
assert.Nil(t, err)
fd, err := ioutil.TempFile("", "TestYAMLBasic-")
assert.Nil(t, err)
defer fd.Close()
err = yStore.ToFile(fd.Name())
assert.Nil(t, err)
bites2, err := ioutil.ReadFile(fd.Name())
assert.Nil(t, err)
jsonBites, err := k8syaml.YAMLToJSONStrict(bites)
assert.Nil(t, err)
jsonBites2, err := k8syaml.YAMLToJSONStrict(bites2)
assert.Nil(t, err)
opts := jsondiff.DefaultConsoleOptions()
diff, _ := jsondiff.Compare(jsonBites, jsonBites2, &opts)
assert.Equal(t, jsondiff.FullMatch, diff)
}