-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubeutil_test.go
101 lines (90 loc) · 1.78 KB
/
kubeutil_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/format"
"log"
"testing"
)
func TestDecodeSecret(t *testing.T) {
v := ctx.CompileString(`
kind: "Secret"
apiVersion: "v1"
metadata: {
name: "my-secret"
namespace: "default"
creationTimestamp: null
ownerReferences: [{
apiVersion: "bitnami.com/v1alpha1"
kind: "SealedSecret"
name: "my-secret"
uid: ""
controller: true
}]
}
data: foo: "aGVsbG8gd29ybGQ="
data: bar: "aGVsbG8gd29ybGQ="
data: empty: null
`)
decoded, err := DecodeSecret(&v)
if err != nil {
panic(err)
}
file := BuildFile(nil, "", decoded)
v = ctx.BuildFile(file)
path := cue.MakePath(cue.Hid("_data", "_"), cue.Str("foo"))
got := v.LookupPath(path)
expect := "hello world"
if bytes, _ := got.Bytes(); "hello world" != string(bytes) {
t.Fatalf("expect %v, got %v", expect, got)
}
bytes, err := format.Node(decoded, format.Simplify())
if err != nil {
panic(err)
}
log.Println(string(bytes))
}
func TestBuildFile(t *testing.T) {
v := ctx.CompileString(`
d1: 1
d2: 2
`)
s := v.Syntax().(*ast.StructLit)
testCases := []struct {
labels *stringArray
pkgName string
expect string
}{
{&stringArray{"foo"}, "myPackage", `package myPackage
foo: {
d1: 1
d2: 2
}
`},
{&stringArray{"foo", "bar", "baz"}, "myPackage", `package myPackage
foo: bar: baz: {
d1: 1
d2: 2
}
`},
{&stringArray{}, "myPackage", `package myPackage
{
d1: 1
d2: 2
}
`},
{nil, "myPackage", `package myPackage
{
d1: 1
d2: 2
}
`},
}
for _, testCase := range testCases {
f := BuildFile(testCase.labels, testCase.pkgName, s)
bytes, _ := format.Node(f, format.Simplify())
if got := string(bytes); got != testCase.expect {
t.Fatalf("expect %v, got %v", testCase.expect, got)
}
}
}