-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
59 lines (53 loc) · 1.45 KB
/
integration_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
package jsonnet_test
import (
"fmt"
"github.com/google/go-jsonnet"
f "github.com/harsimranmaan/go-jsonnet-func"
)
func ExampleParseURL() {
vm := jsonnet.MakeVM()
vm.NativeFunction(f.ParseURL())
output, _ := vm.EvaluateAnonymousSnippet("main.jsonnet", `local a = std.native("parseUrl")("https://example.com/test?param=1#link"); {out:a}`)
fmt.Println(output)
// Output:{
// "out": {
// "fragment": "link",
// "host": "example.com",
// "hostname": "example.com",
// "opaque": "",
// "path": "/test",
// "port": "",
// "query": "param=1",
// "scheme": "https",
// "userinfo": ""
// }
// }
}
func ExampleSHA256() {
vm := jsonnet.MakeVM()
vm.NativeFunction(f.SHA256())
output, _ := vm.EvaluateAnonymousSnippet("main.jsonnet", `local a = std.native("sha256")("test"); {out:a}`)
fmt.Println(output)
// Output: {
// "out": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
// }
}
func ExampleSprigFuncs() {
vm := jsonnet.MakeVM()
for _, f := range f.SprigFuncs() {
vm.NativeFunction(f)
}
output, err := vm.EvaluateAnonymousSnippet("main.jsonnet", `local a = std.native("sprig.hello")();
local b = std.native("sprig.upper")("hSm");
local c = std.native("sprig.decryptAES")("secretkey", "30tEfhuJSVRhpG97XCuWgz2okj7L8vQ1s6V9zVUPeDQ=");
[a,b,c]`)
if err != nil {
fmt.Println(err)
}
fmt.Println(output)
// Output: [
// "Hello!",
// "HSM",
// "plaintext"
// ]
}