mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
test coverage and linting
This commit is contained in:
@@ -12,7 +12,7 @@ type JsonConverter interface {
|
||||
JsonToString(context interface{}) (string, error)
|
||||
}
|
||||
|
||||
type jsonConverter struct {}
|
||||
type jsonConverter struct{}
|
||||
|
||||
func NewJsonConverter() JsonConverter {
|
||||
return &jsonConverter{}
|
||||
|
||||
@@ -2,6 +2,7 @@ package marshal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/test"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package marshal
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
yaml "github.com/mikefarah/yaml/v2"
|
||||
errors "github.com/pkg/errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type YamlConverter interface {
|
||||
YamlToString(context interface{}, trimOutput bool) (string, error)
|
||||
}
|
||||
|
||||
type yamlConverter struct {}
|
||||
type yamlConverter struct{}
|
||||
|
||||
func NewYamlConverter() YamlConverter {
|
||||
return &yamlConverter{}
|
||||
@@ -39,4 +40,4 @@ func (y *yamlConverter) marshalContext(context interface{}, trimOutput bool) (st
|
||||
return strings.Trim(outStr, "\n "), nil
|
||||
}
|
||||
return outStr, nil
|
||||
}
|
||||
}
|
||||
|
||||
52
pkg/marshal/yaml_converter_test.go
Normal file
52
pkg/marshal/yaml_converter_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package marshal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/test"
|
||||
)
|
||||
|
||||
func TestYamlToString(t *testing.T) {
|
||||
var raw = `b:
|
||||
c: 2
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withTrim(t *testing.T) {
|
||||
var raw = `b:
|
||||
c: 2`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, true)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withIntKey(t *testing.T) {
|
||||
var raw = `b:
|
||||
2: c
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withBoolKey(t *testing.T) {
|
||||
var raw = `b:
|
||||
false: c
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withArray(t *testing.T) {
|
||||
var raw = `b:
|
||||
- item: one
|
||||
- item: two
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
Reference in New Issue
Block a user