forked from camptocamp/helm-sops
-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils_test.go
43 lines (38 loc) · 839 Bytes
/
utils_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
package main
import (
"testing"
"io/ioutil"
"os"
)
func TestDetectSopsFile(t *testing.T) {
tmp, err := ioutil.TempFile("", "utils_test.*.yaml")
if err != nil {
t.Errorf("Error creating temp file")
}
defer os.Remove(tmp.Name())
// Test negative case
tmp.WriteString(`---
secret: hello
`)
res, err := DetectSopsYaml(tmp.Name())
if res != false || err != nil {
t.Errorf("DetectSopsYaml(tmp) = %t, %v; want false, <nil>", res, err)
}
// Test positive case
tmp.Seek(0, 0)
tmp.WriteString(`---
secret: ENC[AES256_GCM,...]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
lastmodified: '2020-11-03T01:45:48Z'
pgp: []
version: 3.6.1
`)
res, err = DetectSopsYaml(tmp.Name())
if res != true || err != nil {
t.Errorf("DetectSopsYaml(tmp) = %t, %v; want true, <nil>", res, err)
}
}