From bdf15b93b8edf0adb6a01cf9ca8ede59f57a7e5a Mon Sep 17 00:00:00 2001 From: Matthias Diester Date: Sat, 14 Oct 2023 22:23:53 +0200 Subject: [PATCH] Add test case where from or to is null Add test case to check branch that deals with changes where one of the from or to item is null. --- pkg/dyff/compare_test.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/dyff/compare_test.go b/pkg/dyff/compare_test.go index 65ba56a..dfe4eea 100644 --- a/pkg/dyff/compare_test.go +++ b/pkg/dyff/compare_test.go @@ -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() { @@ -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} ]`),