2023-10-20 12:56:59 +00:00
|
|
|
package yamlloader_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2023-12-22 13:20:45 +00:00
|
|
|
"github.com/databricks/cli/libs/dyn"
|
|
|
|
"github.com/databricks/cli/libs/dyn/yamlloader"
|
2023-10-20 12:56:59 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
2023-12-22 13:20:45 +00:00
|
|
|
func loadYAML(t *testing.T, path string) dyn.Value {
|
2023-10-20 12:56:59 +00:00
|
|
|
input, err := os.ReadFile(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var ref any
|
|
|
|
err = yaml.Unmarshal(input, &ref)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
self, err := yamlloader.LoadYAML(path, bytes.NewBuffer(input))
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, self)
|
|
|
|
|
|
|
|
// Deep-equal the two values to ensure that the loader is producing
|
|
|
|
assert.EqualValues(t, ref, self.AsAny())
|
|
|
|
return self
|
|
|
|
}
|
2023-10-24 11:24:43 +00:00
|
|
|
|
|
|
|
func TestYAMLEmpty(t *testing.T) {
|
|
|
|
self := loadYAML(t, "testdata/empty.yml")
|
2023-12-22 13:20:45 +00:00
|
|
|
assert.Equal(t, dyn.NilValue, self)
|
2023-10-24 11:24:43 +00:00
|
|
|
}
|