mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Fixed compare output, added tests
This commit is contained in:
parent
25293a6894
commit
14ac791eaf
@ -94,6 +94,54 @@ func TestReadCmd(t *testing.T) {
|
||||
test.AssertResult(t, "2", result.Output)
|
||||
}
|
||||
|
||||
func TestCompareCmd(t *testing.T) {
|
||||
cmd := getRootCommand()
|
||||
result := test.RunCmd(cmd, "compare ../examples/data1.yaml ../examples/data3.yaml")
|
||||
if result.Error != nil {
|
||||
t.Error(result.Error)
|
||||
}
|
||||
expectedOutput := `-a: simple # just the best
|
||||
-b: [1, 2]
|
||||
+a: "simple" # just the best
|
||||
+b: [1, 3]
|
||||
c:
|
||||
test: 1
|
||||
`
|
||||
test.AssertResult(t, expectedOutput, result.Output)
|
||||
}
|
||||
|
||||
func TestComparePrettyCmd(t *testing.T) {
|
||||
cmd := getRootCommand()
|
||||
result := test.RunCmd(cmd, "compare -P ../examples/data1.yaml ../examples/data3.yaml")
|
||||
if result.Error != nil {
|
||||
t.Error(result.Error)
|
||||
}
|
||||
expectedOutput := ` a: simple # just the best
|
||||
b:
|
||||
- 1
|
||||
-- 2
|
||||
+- 3
|
||||
c:
|
||||
test: 1
|
||||
`
|
||||
test.AssertResult(t, expectedOutput, result.Output)
|
||||
}
|
||||
|
||||
func TestComparePathsCmd(t *testing.T) {
|
||||
cmd := getRootCommand()
|
||||
result := test.RunCmd(cmd, "compare -P -ppv ../examples/data1.yaml ../examples/data3.yaml **")
|
||||
if result.Error != nil {
|
||||
t.Error(result.Error)
|
||||
}
|
||||
expectedOutput := ` a: simple # just the best
|
||||
b.[0]: 1
|
||||
-b.[1]: 2
|
||||
+b.[1]: 3
|
||||
c.test: 1
|
||||
`
|
||||
test.AssertResult(t, expectedOutput, result.Output)
|
||||
}
|
||||
|
||||
func TestValidateCmd(t *testing.T) {
|
||||
cmd := getRootCommand()
|
||||
result := test.RunCmd(cmd, "validate ../examples/sample.yaml b.c")
|
||||
|
@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"github.com/kylelemons/godebug/diff"
|
||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||
@ -75,6 +76,7 @@ func compareDocuments(cmd *cobra.Command, args []string) error {
|
||||
return errorDoingThings
|
||||
}
|
||||
|
||||
cmd.Print(diff.Diff(dataBufferA.String(), dataBufferB.String()))
|
||||
cmd.Print(diff.Diff(strings.TrimSuffix(dataBufferA.String(), "\n"), strings.TrimSuffix(dataBufferB.String(), "\n")))
|
||||
cmd.Print("\n")
|
||||
return nil
|
||||
}
|
||||
|
@ -1,14 +1,4 @@
|
||||
deep1:
|
||||
hostA:
|
||||
value: 1234
|
||||
notRelevant:
|
||||
value: bananas
|
||||
hostB:
|
||||
value: 5678
|
||||
deep2:
|
||||
hostC:
|
||||
value: 1234
|
||||
notRelevant:
|
||||
value: bananas
|
||||
hostD:
|
||||
value: 5678
|
||||
a: "simple" # just the best
|
||||
b: [1, 3]
|
||||
c:
|
||||
test: 1
|
Loading…
Reference in New Issue
Block a user