Yaml: remove empty-stream workaround in favor of go-yaml fix (#30789)
This commit is contained in:
parent
15aa800e65
commit
8f5983c189
11 changed files with 15 additions and 36 deletions
|
|
@ -1,8 +1,8 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"github.com/evcc-io/evcc/util/yaml"
|
||||
"github.com/spf13/cast"
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
// CustomDevice promotes an embedded yaml type to the top-level type
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ func TestYamlFloat(t *testing.T) {
|
|||
|
||||
func TestYamlEmpty(t *testing.T) {
|
||||
var res map[string]any
|
||||
err := yaml.Unmarshal([]byte(""), &res)
|
||||
require.ErrorContains(t, err, "no documents in stream")
|
||||
require.NoError(t, yaml.Unmarshal([]byte(""), &res))
|
||||
require.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestYamlCommentsOnly(t *testing.T) {
|
||||
|
|
@ -24,8 +24,8 @@ func TestYamlCommentsOnly(t *testing.T) {
|
|||
# another comment
|
||||
`
|
||||
var res map[string]any
|
||||
err := yaml.Unmarshal([]byte(b), &res)
|
||||
require.ErrorContains(t, err, "no documents in stream")
|
||||
require.NoError(t, yaml.Unmarshal([]byte(b), &res))
|
||||
require.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestYamlError(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/evcc-io/evcc/util/yaml"
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
func yamlQuote(value string) string {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/yaml"
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
// Instance is an actual instantiated template
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package yaml
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
goyaml "go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
func Marshal(data any) ([]byte, error) {
|
||||
return goyaml.Marshal(data)
|
||||
}
|
||||
|
||||
// Unmarshal invokes unmarshaler, ignoring empty document errors
|
||||
func Unmarshal(b []byte, res any) error {
|
||||
err := goyaml.Unmarshal(b, res)
|
||||
if err != nil && strings.Contains(err.Error(), "no documents in stream") {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue