2021-08-26 16:34:52 +02:00
|
|
|
package jsonnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvert(t *testing.T) {
|
|
|
|
testcases := []struct {
|
|
|
|
name string
|
|
|
|
jsonnetFile, yamlFile string
|
|
|
|
stringOutput, format, stream bool
|
|
|
|
extVars []string
|
2022-12-06 13:30:36 +01:00
|
|
|
jpath []string
|
2021-08-26 16:34:52 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Stream + Format",
|
|
|
|
jsonnetFile: "stream_format.jsonnet",
|
|
|
|
yamlFile: "stream_format.yaml",
|
|
|
|
format: true, stream: true,
|
|
|
|
},
|
2022-12-06 13:30:36 +01:00
|
|
|
{
|
|
|
|
name: "Jsonnet Path",
|
|
|
|
jsonnetFile: "stream_format.jsonnet",
|
|
|
|
yamlFile: "stream_format.yaml",
|
|
|
|
format: true, stream: true,
|
|
|
|
jpath: []string{"/path/to/jsonnet/lib"},
|
|
|
|
},
|
2021-08-26 16:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testcases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
expected, err := os.ReadFile(filepath.Join("./testdata", tc.yamlFile))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-12-06 13:30:36 +01:00
|
|
|
result, err := convert(filepath.Join("./testdata", tc.jsonnetFile), tc.stringOutput, tc.format, tc.stream, tc.extVars, tc.jpath)
|
2021-08-26 16:34:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, string(expected), result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|