mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-24 01:04:49 -06:00
d71e3bb6c2
There is a new command argument "capabilities". With this, it is possible to print the current capabilities version, show all capabilities versions & print any capabilities version, without the need of a file. Moreover, for the other commands which use the --capabilities flag, it is possible to give only the version number, without specifying a file. However, there are no breaking changes for those who use the capabilities file as an input for the flag. Unit tests were also written, in order to test the new argument and the changes made in ast. Fixes: #4236 Signed-off-by: IoannisMatzaris <matzarisioannis@gmail.com>
77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
// 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)
|
|
}
|
|
})
|
|
|
|
})
|
|
}
|