mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 22:35:37 +00:00
read: test reading specific document of multidocument
This commit is contained in:
parent
26153b3eb5
commit
da9edc9e31
1
.gitignore
vendored
1
.gitignore
vendored
@ -36,3 +36,4 @@ parts/
|
||||
prime/
|
||||
.snapcraft/
|
||||
yq*.snap
|
||||
*.swp
|
||||
|
||||
9
examples/multidocument.yaml
Normal file
9
examples/multidocument.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
a: Document One
|
||||
b:
|
||||
c: 1
|
||||
---
|
||||
a: Document Two
|
||||
b:
|
||||
c: 2
|
||||
|
||||
@ -60,6 +60,12 @@ func assertResultWithContext(t *testing.T, expectedValue interface{}, actualValu
|
||||
}
|
||||
}
|
||||
|
||||
func assertAnyErr(t *testing.T, actualValue error) {
|
||||
if actualValue == nil {
|
||||
t.Error("Expected error, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func writeTempYamlFile(content string) string {
|
||||
tmpfile, _ := ioutil.TempFile("", "testyaml")
|
||||
defer func() {
|
||||
|
||||
17
yq_test.go
17
yq_test.go
@ -38,6 +38,23 @@ func TestReadString(t *testing.T) {
|
||||
assertResult(t, "hi", result)
|
||||
}
|
||||
|
||||
func TestReadMultipleDocuments(t *testing.T) {
|
||||
t.Run("multiple documents assumes first", func(t *testing.T) {
|
||||
result, _ := read([]string{"examples/multidocument.yaml", "b.c"})
|
||||
assertResult(t, 1, result)
|
||||
})
|
||||
t.Run("multiple documents with leading @n reads from document n", func(t *testing.T) {
|
||||
result, _ := read([]string{"examples/multidocument.yaml", "@0.b.c"})
|
||||
assertResult(t, 1, result)
|
||||
|
||||
result, _ = read([]string{"examples/multidocument.yaml", "@1.b.c"})
|
||||
assertResult(t, 2, result)
|
||||
|
||||
_, err := read([]string{"examples/multidocument.yaml", "@2.b.c"})
|
||||
assertAnyErr(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestOrder(t *testing.T) {
|
||||
result, _ := read([]string{"examples/order.yaml"})
|
||||
formattedResult, _ := yamlToString(result)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user