Skip to content

Commit

Permalink
Add test case where from or to is null
Browse files Browse the repository at this point in the history
Add test case to check branch that deals with changes where one of the
from or to item is null.
  • Loading branch information
HeavyWombat committed Oct 14, 2023
1 parent e79693e commit badc1b5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pkg/dyff/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/gonvenience/ytbx"

"github.com/homeport/dyff/pkg/dyff"

"github.com/gonvenience/ytbx"
yamlv3 "gopkg.in/yaml.v3"
)

var nullNode = &yamlv3.Node{
Kind: yamlv3.ScalarNode,
Tag: "!!null",
Value: "null",
}

var _ = Describe("Core/Compare", func() {
Describe("Difference between YAMLs", func() {
Context("Given two simple YAML structures", func() {
Expand Down Expand Up @@ -605,6 +612,21 @@ listY: [ Yo, Yo, Yo ]
}))
})

It("should return changes where one of the items is null", func() {
from := yml(`foo: null`)
to := yml(`foo: "bar"`)
results, err := compare(from, to)
Expect(err).To(BeNil())
Expect(results).NotTo(BeNil())
Expect(results).To(HaveLen(1))
Expect(results[0]).To(BeSameDiffAs(singleDiff(
"/foo",
dyff.MODIFICATION,
nullNode,
"bar",
)))
})

It("should not return order changes in named entry lists in case the ignore option is enabled", func() {
results, err := compare(
yml(`list: [ {name: A}, {name: C}, {name: B}, {name: D}, {name: E} ]`),
Expand Down

0 comments on commit badc1b5

Please sign in to comment.