forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapabilities_test.go
76 lines (67 loc) · 1.4 KB
/
capabilities_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
// Copyright 2022 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package cmd
import (
"path"
"testing"
"github.com/open-policy-agent/opa/util/test"
)
func TestCapabilitiesNoArgs(t *testing.T) {
t.Run("test with no arguments", func(t *testing.T) {
_, err := doCapabilities(capabilitiesParams{})
if err != nil {
t.Fatal("expected success", err)
}
})
}
func TestCapabilitiesVersion(t *testing.T) {
t.Run("test with version", func(t *testing.T) {
params := capabilitiesParams{
version: "v0.39.0",
}
_, err := doCapabilities(params)
if err != nil {
t.Fatal("expected success", err)
}
})
}
func TestCapabilitiesFile(t *testing.T) {
t.Run("test with file", func(t *testing.T) {
files := map[string]string{
"test-capabilities.json": `
{
"builtins": [
{
"name": "plus",
"infix": "+",
"decl": {
"type": "function",
"args": [
{
"type": "number"
},
{
"type": "number"
}
],
"result": {
"type": "number"
}
}
}
]
}
`,
}
test.WithTempFS(files, func(root string) {
params := capabilitiesParams{
file: path.Join(root, "test-capabilities.json"),
}
_, err := doCapabilities(params)
if err != nil {
t.Fatal("expected success", err)
}
})
})
}