databricks-cli/libs/dyn/yamlloader/yaml_test.go

36 lines
809 B
Go
Raw Permalink Normal View History

2023-10-20 12:56:59 +00:00
package yamlloader_test
import (
"bytes"
"os"
"testing"
"github.com/databricks/cli/libs/dyn"
assert "github.com/databricks/cli/libs/dyn/dynassert"
"github.com/databricks/cli/libs/dyn/yamlloader"
2023-10-20 12:56:59 +00:00
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
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
}
func TestYAMLEmpty(t *testing.T) {
self := loadYAML(t, "testdata/empty.yml")
assert.Equal(t, dyn.NilValue, self)
}