From bb9e71bb1a7cc0ccec53308b1f209914d23d8873 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 28 Apr 2020 13:39:07 -0700 Subject: [PATCH 1/7] =?UTF-8?q?Replace=20cppforlife=20=E2=86=92=20SUSE=20t?= =?UTF-8?q?o=20create=20an=20independent=20fork?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/test | 2 +- patch/array_index_test.go | 2 +- patch/array_insertion_test.go | 2 +- patch/diff_test.go | 2 +- patch/find_op_test.go | 2 +- patch/integration_test.go | 2 +- patch/op_definition_test.go | 2 +- patch/ops_test.go | 2 +- patch/pointer_test.go | 2 +- patch/remove_op_test.go | 2 +- patch/replace_op_test.go | 2 +- patch/test_op_test.go | 2 +- patch/yaml_compat_test.go | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/test b/bin/test index 011b587..c187fda 100755 --- a/bin/test +++ b/bin/test @@ -2,6 +2,6 @@ set -e -go fmt github.com/cppforlife/go-patch/... +go fmt github.com/SUSE/go-patch/... ginkgo -trace -r patch/ diff --git a/patch/array_index_test.go b/patch/array_index_test.go index c8b7fb7..ff8c6f4 100644 --- a/patch/array_index_test.go +++ b/patch/array_index_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("ArrayIndex", func() { diff --git a/patch/array_insertion_test.go b/patch/array_insertion_test.go index a987d36..08debcc 100644 --- a/patch/array_insertion_test.go +++ b/patch/array_insertion_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("ArrayInsertion", func() { diff --git a/patch/diff_test.go b/patch/diff_test.go index df8b009..8537a03 100644 --- a/patch/diff_test.go +++ b/patch/diff_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("Diff.Calculate", func() { diff --git a/patch/find_op_test.go b/patch/find_op_test.go index 7aa0d13..230e06c 100644 --- a/patch/find_op_test.go +++ b/patch/find_op_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("FindOp.Apply", func() { diff --git a/patch/integration_test.go b/patch/integration_test.go index a4e8ae6..7c04a31 100644 --- a/patch/integration_test.go +++ b/patch/integration_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/gomega" "gopkg.in/yaml.v2" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("Integration", func() { diff --git a/patch/op_definition_test.go b/patch/op_definition_test.go index 062bd9d..29211d9 100644 --- a/patch/op_definition_test.go +++ b/patch/op_definition_test.go @@ -7,7 +7,7 @@ import ( . "github.com/onsi/gomega" "gopkg.in/yaml.v2" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("NewOpsFromDefinitions", func() { diff --git a/patch/ops_test.go b/patch/ops_test.go index 1e4ac93..8f4a1a1 100644 --- a/patch/ops_test.go +++ b/patch/ops_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("Ops.Apply", func() { diff --git a/patch/pointer_test.go b/patch/pointer_test.go index 36c4aa2..4994097 100644 --- a/patch/pointer_test.go +++ b/patch/pointer_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) type PointerTestCase struct { diff --git a/patch/remove_op_test.go b/patch/remove_op_test.go index fa8081c..ab6b2f1 100644 --- a/patch/remove_op_test.go +++ b/patch/remove_op_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("RemoveOp.Apply", func() { diff --git a/patch/replace_op_test.go b/patch/replace_op_test.go index c3f628f..9e2f046 100644 --- a/patch/replace_op_test.go +++ b/patch/replace_op_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("ReplaceOp.Apply", func() { diff --git a/patch/test_op_test.go b/patch/test_op_test.go index c57bbe5..4aff1a3 100644 --- a/patch/test_op_test.go +++ b/patch/test_op_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("TestOp.Apply", func() { diff --git a/patch/yaml_compat_test.go b/patch/yaml_compat_test.go index 2e7e267..f873a88 100644 --- a/patch/yaml_compat_test.go +++ b/patch/yaml_compat_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/gomega" "gopkg.in/yaml.v2" - . "github.com/cppforlife/go-patch/patch" + . "github.com/SUSE/go-patch/patch" ) var _ = Describe("YAML compatibility", func() { From 6a31612274e8693c70efa0a58b104e2fc295c45a Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 28 Apr 2020 13:40:41 -0700 Subject: [PATCH 2/7] Add go.mod (and go.sum) --- go.mod | 9 +++++++++ go.sum | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..99684b8 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/SUSE/go-patch + +go 1.14 + +require ( + github.com/onsi/ginkgo v1.12.0 + github.com/onsi/gomega v1.9.0 + gopkg.in/yaml.v2 v2.2.8 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..89fbe64 --- /dev/null +++ b/go.sum @@ -0,0 +1,32 @@ +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU= +github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= +github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 8111be4c3333802a8a233028cedc02b9fbb181b1 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Mon, 16 Jul 2018 10:51:40 -0400 Subject: [PATCH 3/7] Add basic copy operation. Rebased by Jan Dubois on 2020-04-28 --- patch/copy_op.go | 15 +++++++++ patch/copy_op_test.go | 41 ++++++++++++++++++++++++ patch/op_definition.go | 33 ++++++++++++++++++++ patch/op_definition_test.go | 62 ++++++++++++++++++++++++++++++++++++- 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 patch/copy_op.go create mode 100644 patch/copy_op_test.go diff --git a/patch/copy_op.go b/patch/copy_op.go new file mode 100644 index 0000000..ae4a4b3 --- /dev/null +++ b/patch/copy_op.go @@ -0,0 +1,15 @@ +package patch + +type CopyOp struct { + Path Pointer + From Pointer +} + +func (op CopyOp) Apply(doc interface{}) (interface{}, error) { + value, err := FindOp{Path: op.From}.Apply(doc) + if err != nil { + return nil, err + } + + return ReplaceOp{Path: op.Path, Value: value}.Apply(doc) +} diff --git a/patch/copy_op_test.go b/patch/copy_op_test.go new file mode 100644 index 0000000..efc833b --- /dev/null +++ b/patch/copy_op_test.go @@ -0,0 +1,41 @@ +package patch_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + . "github.com/SUSE/go-patch/patch" +) + +var _ = Describe("CopyOp.Apply", func() { + Describe("array item", func() { + It("replaces array item", func() { + res, err := CopyOp{ + Path: MustNewPointerFromString("/-"), + From: MustNewPointerFromString("/0"), + }.Apply([]interface{}{1, 2, 3}) + Expect(err).ToNot(HaveOccurred()) + Expect(res).To(Equal([]interface{}{1, 2, 3, 1})) + }) + }) + + Describe("map key", func() { + It("copies map key", func() { + doc := map[interface{}]interface{}{ + "abc": "abc", + "xyz": "xyz", + } + + res, err := CopyOp{ + From: MustNewPointerFromString("/abc"), + Path: MustNewPointerFromString("/def?"), + }.Apply(doc) + Expect(err).ToNot(HaveOccurred()) + Expect(res).To(Equal(map[interface{}]interface{}{ + "abc": "abc", + "def": "abc", + "xyz": "xyz", + })) + }) + }) +}) diff --git a/patch/op_definition.go b/patch/op_definition.go index 3b165fc..42a578c 100644 --- a/patch/op_definition.go +++ b/patch/op_definition.go @@ -10,6 +10,7 @@ import ( type OpDefinition struct { Type string `json:",omitempty" yaml:",omitempty"` Path *string `json:",omitempty" yaml:",omitempty"` + From *string `json:",omitempty" yaml:",omitempty"` Value *interface{} `json:",omitempty" yaml:",omitempty"` Absent *bool `json:",omitempty" yaml:",omitempty"` Error *string `json:",omitempty" yaml:",omitempty"` @@ -46,6 +47,12 @@ func NewOpsFromDefinitions(opDefs []OpDefinition) (Ops, error) { return nil, fmt.Errorf("Test operation [%d]: %s within\n%s", i, err, opFmt) } + case "copy": + op, err = p.newCopyOp(opDef) + if err != nil { + return nil, fmt.Errorf("Copy operation [%d]: %s within\n%s", i, err, opFmt) + } + default: return nil, fmt.Errorf("Unknown operation [%d] with type '%s' within\n%s", i, opDef.Type, opFmt) } @@ -121,6 +128,32 @@ func (parser) newTestOp(opDef OpDefinition) (TestOp, error) { return op, nil } +func (parser) newCopyOp(opDef OpDefinition) (CopyOp, error) { + if opDef.Path == nil { + return CopyOp{}, fmt.Errorf("Missing path") + } + + if opDef.From == nil { + return CopyOp{}, fmt.Errorf("Missing from") + } + + if opDef.Value != nil { + return CopyOp{}, fmt.Errorf("Cannot specify value") + } + + pathPtr, err := NewPointerFromString(*opDef.Path) + if err != nil { + return CopyOp{}, fmt.Errorf("Invalid path: %s", err) + } + + fromPtr, err := NewPointerFromString(*opDef.From) + if err != nil { + return CopyOp{}, fmt.Errorf("Invalid from: %s", err) + } + + return CopyOp{Path: pathPtr, From: fromPtr}, nil +} + func (parser) fmtOpDef(opDef OpDefinition) string { var ( redactedVal interface{} = "" diff --git a/patch/op_definition_test.go b/patch/op_definition_test.go index 29211d9..4c286bd 100644 --- a/patch/op_definition_test.go +++ b/patch/op_definition_test.go @@ -13,19 +13,22 @@ import ( var _ = Describe("NewOpsFromDefinitions", func() { var ( path = "/abc" + from = "/abc" invalidPath = "abc" + invalidFrom = "abc" errorMsg = "error" val interface{} = 123 complexVal interface{} = map[interface{}]interface{}{123: 123} trueBool = true ) - It("supports 'replace', 'remove', 'test' operations", func() { + It("supports 'replace', 'remove', 'test', 'copy' operations", func() { opDefs := []OpDefinition{ {Type: "replace", Path: &path, Value: &val}, {Type: "remove", Path: &path}, {Type: "test", Path: &path, Value: &val}, {Type: "test", Path: &path, Absent: &trueBool}, + {Type: "copy", Path: &path, From: &from}, } ops, err := NewOpsFromDefinitions(opDefs) @@ -36,6 +39,7 @@ var _ = Describe("NewOpsFromDefinitions", func() { RemoveOp{Path: MustNewPointerFromString("/abc")}, TestOp{Path: MustNewPointerFromString("/abc"), Value: 123}, TestOp{Path: MustNewPointerFromString("/abc"), Absent: true}, + CopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, }))) }) @@ -199,6 +203,62 @@ var _ = Describe("NewOpsFromDefinitions", func() { "Type": "test", "Path": "abc", "Value": "" +}`)) + }) + }) + + Describe("copy", func() { + It("requires path", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", From: &from}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Copy operation [0]: Missing path within +{ + "Type": "copy", + "From": "/abc" +}`)) + }) + + It("requires from", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &path}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Copy operation [0]: Missing from within +{ + "Type": "copy", + "Path": "/abc" +}`)) + }) + + It("does not allow value", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &path, From: &from, Value: &val}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Copy operation [0]: Cannot specify value within +{ + "Type": "copy", + "Path": "/abc", + "From": "/abc", + "Value": "" +}`)) + }) + + It("requires valid path", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &invalidPath, From: &from}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Copy operation [0]: Invalid path: Expected to start with '/' within +{ + "Type": "copy", + "Path": "abc", + "From": "/abc" +}`)) + }) + + It("requires valid from", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &path, From: &invalidFrom}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Copy operation [0]: Invalid from: Expected to start with '/' within +{ + "Type": "copy", + "Path": "/abc", + "From": "abc" }`)) }) }) From b5686cbf2b4ea2ababd6091f6bfde093c4b85ac8 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 28 Apr 2020 16:03:19 -0700 Subject: [PATCH 4/7] Implement simple move op This is mostly a copy of the copy op, and the implementation is just running a 'copy' followed by a 'remove' of the 'from' location. --- patch/move_op.go | 19 ++++++++++++ patch/move_op_test.go | 40 +++++++++++++++++++++++++ patch/op_definition.go | 32 ++++++++++++++++++++ patch/op_definition_test.go | 60 ++++++++++++++++++++++++++++++++++++- 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 patch/move_op.go create mode 100644 patch/move_op_test.go diff --git a/patch/move_op.go b/patch/move_op.go new file mode 100644 index 0000000..20adcbc --- /dev/null +++ b/patch/move_op.go @@ -0,0 +1,19 @@ +package patch + +type MoveOp struct { + Path Pointer + From Pointer +} + +func (op MoveOp) Apply(doc interface{}) (interface{}, error) { + value, err := FindOp{Path: op.From}.Apply(doc) + if err != nil { + return nil, err + } + + doc, err = ReplaceOp{Path: op.Path, Value: value}.Apply(doc) + if err != nil { + return nil, err + } + return RemoveOp{Path: op.From}.Apply(doc) +} diff --git a/patch/move_op_test.go b/patch/move_op_test.go new file mode 100644 index 0000000..7aa588a --- /dev/null +++ b/patch/move_op_test.go @@ -0,0 +1,40 @@ +package patch_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + . "github.com/SUSE/go-patch/patch" +) + +var _ = Describe("MoveOp.Apply", func() { + Describe("array item", func() { + It("moves array item", func() { + res, err := MoveOp{ + Path: MustNewPointerFromString("/-"), + From: MustNewPointerFromString("/0"), + }.Apply([]interface{}{1, 2, 3}) + Expect(err).ToNot(HaveOccurred()) + Expect(res).To(Equal([]interface{}{2, 3, 1})) + }) + }) + + Describe("map key", func() { + It("renames map key", func() { + doc := map[interface{}]interface{}{ + "abc": "abc", + "xyz": "xyz", + } + + res, err := MoveOp{ + From: MustNewPointerFromString("/abc"), + Path: MustNewPointerFromString("/def?"), + }.Apply(doc) + Expect(err).ToNot(HaveOccurred()) + Expect(res).To(Equal(map[interface{}]interface{}{ + "def": "abc", + "xyz": "xyz", + })) + }) + }) +}) diff --git a/patch/op_definition.go b/patch/op_definition.go index 42a578c..4840e97 100644 --- a/patch/op_definition.go +++ b/patch/op_definition.go @@ -53,6 +53,12 @@ func NewOpsFromDefinitions(opDefs []OpDefinition) (Ops, error) { return nil, fmt.Errorf("Copy operation [%d]: %s within\n%s", i, err, opFmt) } + case "move": + op, err = p.newMoveOp(opDef) + if err != nil { + return nil, fmt.Errorf("Move operation [%d]: %s within\n%s", i, err, opFmt) + } + default: return nil, fmt.Errorf("Unknown operation [%d] with type '%s' within\n%s", i, opDef.Type, opFmt) } @@ -154,6 +160,32 @@ func (parser) newCopyOp(opDef OpDefinition) (CopyOp, error) { return CopyOp{Path: pathPtr, From: fromPtr}, nil } +func (parser) newMoveOp(opDef OpDefinition) (MoveOp, error) { + if opDef.Path == nil { + return MoveOp{}, fmt.Errorf("Missing path") + } + + if opDef.From == nil { + return MoveOp{}, fmt.Errorf("Missing from") + } + + if opDef.Value != nil { + return MoveOp{}, fmt.Errorf("Cannot specify value") + } + + pathPtr, err := NewPointerFromString(*opDef.Path) + if err != nil { + return MoveOp{}, fmt.Errorf("Invalid path: %s", err) + } + + fromPtr, err := NewPointerFromString(*opDef.From) + if err != nil { + return MoveOp{}, fmt.Errorf("Invalid from: %s", err) + } + + return MoveOp{Path: pathPtr, From: fromPtr}, nil +} + func (parser) fmtOpDef(opDef OpDefinition) string { var ( redactedVal interface{} = "" diff --git a/patch/op_definition_test.go b/patch/op_definition_test.go index 4c286bd..caff48d 100644 --- a/patch/op_definition_test.go +++ b/patch/op_definition_test.go @@ -22,13 +22,14 @@ var _ = Describe("NewOpsFromDefinitions", func() { trueBool = true ) - It("supports 'replace', 'remove', 'test', 'copy' operations", func() { + It("supports 'replace', 'remove', 'test', 'copy', 'move' operations", func() { opDefs := []OpDefinition{ {Type: "replace", Path: &path, Value: &val}, {Type: "remove", Path: &path}, {Type: "test", Path: &path, Value: &val}, {Type: "test", Path: &path, Absent: &trueBool}, {Type: "copy", Path: &path, From: &from}, + {Type: "move", Path: &path, From: &from}, } ops, err := NewOpsFromDefinitions(opDefs) @@ -40,6 +41,7 @@ var _ = Describe("NewOpsFromDefinitions", func() { TestOp{Path: MustNewPointerFromString("/abc"), Value: 123}, TestOp{Path: MustNewPointerFromString("/abc"), Absent: true}, CopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, + MoveOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, }))) }) @@ -259,6 +261,62 @@ var _ = Describe("NewOpsFromDefinitions", func() { "Type": "copy", "Path": "/abc", "From": "abc" +}`)) + }) + }) + + Describe("move", func() { + It("requires path", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", From: &from}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Move operation [0]: Missing path within +{ + "Type": "move", + "From": "/abc" +}`)) + }) + + It("requires from", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &path}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Move operation [0]: Missing from within +{ + "Type": "move", + "Path": "/abc" +}`)) + }) + + It("does not allow value", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &path, From: &from, Value: &val}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Move operation [0]: Cannot specify value within +{ + "Type": "move", + "Path": "/abc", + "From": "/abc", + "Value": "" +}`)) + }) + + It("requires valid path", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &invalidPath, From: &from}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Move operation [0]: Invalid path: Expected to start with '/' within +{ + "Type": "move", + "Path": "abc", + "From": "/abc" +}`)) + }) + + It("requires valid from", func() { + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &path, From: &invalidFrom}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(`Move operation [0]: Invalid from: Expected to start with '/' within +{ + "Type": "move", + "Path": "/abc", + "From": "abc" }`)) }) }) From 3984b8d48ef56181353bde033702fb083241f58c Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 28 Apr 2020 16:17:34 -0700 Subject: [PATCH 5/7] Add CopyOp and MoveOp to NewOpDefinitionsFromOps --- patch/op_definition.go | 20 ++++++++++++++++++++ patch/op_definition_test.go | 23 +++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/patch/op_definition.go b/patch/op_definition.go index 4840e97..66b97f6 100644 --- a/patch/op_definition.go +++ b/patch/op_definition.go @@ -245,6 +245,26 @@ func NewOpDefinitionsFromOps(ops Ops) ([]OpDefinition, error) { opDefs = append(opDefs, opDef) + case CopyOp: + path := typedOp.Path.String() + from := typedOp.From.String() + + opDefs = append(opDefs, OpDefinition{ + Type: "copy", + Path: &path, + From: &from, + }) + + case MoveOp: + path := typedOp.Path.String() + from := typedOp.From.String() + + opDefs = append(opDefs, OpDefinition{ + Type: "move", + Path: &path, + From: &from, + }) + default: return nil, fmt.Errorf("Unknown operation [%d] with type '%t'", i, op) } diff --git a/patch/op_definition_test.go b/patch/op_definition_test.go index caff48d..7f20d41 100644 --- a/patch/op_definition_test.go +++ b/patch/op_definition_test.go @@ -5,6 +5,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/onsi/gomega/format" "gopkg.in/yaml.v2" . "github.com/SUSE/go-patch/patch" @@ -323,12 +324,14 @@ var _ = Describe("NewOpsFromDefinitions", func() { }) var _ = Describe("NewOpDefinitionsFromOps", func() { - It("supports 'replace', 'remove', 'test' operations serialized", func() { + It("supports 'replace', 'remove', 'test', 'copy', 'move' operations serialized", func() { ops := Ops([]Op{ ReplaceOp{Path: MustNewPointerFromString("/abc"), Value: 123}, RemoveOp{Path: MustNewPointerFromString("/abc")}, TestOp{Path: MustNewPointerFromString("/abc"), Value: 123}, TestOp{Path: MustNewPointerFromString("/abc"), Absent: true}, + CopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, + MoveOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, }) opDefs, err := NewOpDefinitionsFromOps(ops) @@ -336,7 +339,7 @@ var _ = Describe("NewOpDefinitionsFromOps", func() { bs, err := yaml.Marshal(opDefs) Expect(err).ToNot(HaveOccurred()) - + format.TruncatedDiff = false Expect("\n" + string(bs)).To(Equal(` - type: replace path: /abc @@ -349,6 +352,12 @@ var _ = Describe("NewOpDefinitionsFromOps", func() { - type: test path: /abc absent: true +- type: copy + path: /abc + from: /abc +- type: move + path: /abc + from: /abc `)) bs, err = json.MarshalIndent(opDefs, "", " ") @@ -371,6 +380,16 @@ var _ = Describe("NewOpDefinitionsFromOps", func() { "Type": "test", "Path": "/abc", "Absent": true + }, + { + "Type": "copy", + "Path": "/abc", + "From": "/abc" + }, + { + "Type": "move", + "Path": "/abc", + "From": "/abc" } ]`)) }) From 59dcd328780b3fb5febf7604a932edb90063b3a1 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 28 Apr 2020 16:26:33 -0700 Subject: [PATCH 6/7] =?UTF-8?q?Rename=20copy=20and=20move=20=E2=86=92=20qc?= =?UTF-8?q?opy=20and=20qmove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid conflicts of upstream ever implements copy/move ops with incompatible semantics. The Q variants are for internal usage of Quarks (and kubecf) for now. --- patch/copy_op.go | 4 +- patch/copy_op_test.go | 6 +-- patch/move_op.go | 4 +- patch/move_op_test.go | 6 +-- patch/op_definition.go | 48 ++++++++++---------- patch/op_definition_test.go | 88 ++++++++++++++++++------------------- 6 files changed, 78 insertions(+), 78 deletions(-) diff --git a/patch/copy_op.go b/patch/copy_op.go index ae4a4b3..e1945f5 100644 --- a/patch/copy_op.go +++ b/patch/copy_op.go @@ -1,11 +1,11 @@ package patch -type CopyOp struct { +type QCopyOp struct { Path Pointer From Pointer } -func (op CopyOp) Apply(doc interface{}) (interface{}, error) { +func (op QCopyOp) Apply(doc interface{}) (interface{}, error) { value, err := FindOp{Path: op.From}.Apply(doc) if err != nil { return nil, err diff --git a/patch/copy_op_test.go b/patch/copy_op_test.go index efc833b..618dcc6 100644 --- a/patch/copy_op_test.go +++ b/patch/copy_op_test.go @@ -7,10 +7,10 @@ import ( . "github.com/SUSE/go-patch/patch" ) -var _ = Describe("CopyOp.Apply", func() { +var _ = Describe("QCopyOp.Apply", func() { Describe("array item", func() { It("replaces array item", func() { - res, err := CopyOp{ + res, err := QCopyOp{ Path: MustNewPointerFromString("/-"), From: MustNewPointerFromString("/0"), }.Apply([]interface{}{1, 2, 3}) @@ -26,7 +26,7 @@ var _ = Describe("CopyOp.Apply", func() { "xyz": "xyz", } - res, err := CopyOp{ + res, err := QCopyOp{ From: MustNewPointerFromString("/abc"), Path: MustNewPointerFromString("/def?"), }.Apply(doc) diff --git a/patch/move_op.go b/patch/move_op.go index 20adcbc..1bd8ee8 100644 --- a/patch/move_op.go +++ b/patch/move_op.go @@ -1,11 +1,11 @@ package patch -type MoveOp struct { +type QMoveOp struct { Path Pointer From Pointer } -func (op MoveOp) Apply(doc interface{}) (interface{}, error) { +func (op QMoveOp) Apply(doc interface{}) (interface{}, error) { value, err := FindOp{Path: op.From}.Apply(doc) if err != nil { return nil, err diff --git a/patch/move_op_test.go b/patch/move_op_test.go index 7aa588a..c7dd158 100644 --- a/patch/move_op_test.go +++ b/patch/move_op_test.go @@ -7,10 +7,10 @@ import ( . "github.com/SUSE/go-patch/patch" ) -var _ = Describe("MoveOp.Apply", func() { +var _ = Describe("QMoveOp.Apply", func() { Describe("array item", func() { It("moves array item", func() { - res, err := MoveOp{ + res, err := QMoveOp{ Path: MustNewPointerFromString("/-"), From: MustNewPointerFromString("/0"), }.Apply([]interface{}{1, 2, 3}) @@ -26,7 +26,7 @@ var _ = Describe("MoveOp.Apply", func() { "xyz": "xyz", } - res, err := MoveOp{ + res, err := QMoveOp{ From: MustNewPointerFromString("/abc"), Path: MustNewPointerFromString("/def?"), }.Apply(doc) diff --git a/patch/op_definition.go b/patch/op_definition.go index 66b97f6..d143388 100644 --- a/patch/op_definition.go +++ b/patch/op_definition.go @@ -47,16 +47,16 @@ func NewOpsFromDefinitions(opDefs []OpDefinition) (Ops, error) { return nil, fmt.Errorf("Test operation [%d]: %s within\n%s", i, err, opFmt) } - case "copy": - op, err = p.newCopyOp(opDef) + case "qcopy": + op, err = p.newQCopyOp(opDef) if err != nil { - return nil, fmt.Errorf("Copy operation [%d]: %s within\n%s", i, err, opFmt) + return nil, fmt.Errorf("QCopy operation [%d]: %s within\n%s", i, err, opFmt) } - case "move": - op, err = p.newMoveOp(opDef) + case "qmove": + op, err = p.newQMoveOp(opDef) if err != nil { - return nil, fmt.Errorf("Move operation [%d]: %s within\n%s", i, err, opFmt) + return nil, fmt.Errorf("QMove operation [%d]: %s within\n%s", i, err, opFmt) } default: @@ -134,56 +134,56 @@ func (parser) newTestOp(opDef OpDefinition) (TestOp, error) { return op, nil } -func (parser) newCopyOp(opDef OpDefinition) (CopyOp, error) { +func (parser) newQCopyOp(opDef OpDefinition) (QCopyOp, error) { if opDef.Path == nil { - return CopyOp{}, fmt.Errorf("Missing path") + return QCopyOp{}, fmt.Errorf("Missing path") } if opDef.From == nil { - return CopyOp{}, fmt.Errorf("Missing from") + return QCopyOp{}, fmt.Errorf("Missing from") } if opDef.Value != nil { - return CopyOp{}, fmt.Errorf("Cannot specify value") + return QCopyOp{}, fmt.Errorf("Cannot specify value") } pathPtr, err := NewPointerFromString(*opDef.Path) if err != nil { - return CopyOp{}, fmt.Errorf("Invalid path: %s", err) + return QCopyOp{}, fmt.Errorf("Invalid path: %s", err) } fromPtr, err := NewPointerFromString(*opDef.From) if err != nil { - return CopyOp{}, fmt.Errorf("Invalid from: %s", err) + return QCopyOp{}, fmt.Errorf("Invalid from: %s", err) } - return CopyOp{Path: pathPtr, From: fromPtr}, nil + return QCopyOp{Path: pathPtr, From: fromPtr}, nil } -func (parser) newMoveOp(opDef OpDefinition) (MoveOp, error) { +func (parser) newQMoveOp(opDef OpDefinition) (QMoveOp, error) { if opDef.Path == nil { - return MoveOp{}, fmt.Errorf("Missing path") + return QMoveOp{}, fmt.Errorf("Missing path") } if opDef.From == nil { - return MoveOp{}, fmt.Errorf("Missing from") + return QMoveOp{}, fmt.Errorf("Missing from") } if opDef.Value != nil { - return MoveOp{}, fmt.Errorf("Cannot specify value") + return QMoveOp{}, fmt.Errorf("Cannot specify value") } pathPtr, err := NewPointerFromString(*opDef.Path) if err != nil { - return MoveOp{}, fmt.Errorf("Invalid path: %s", err) + return QMoveOp{}, fmt.Errorf("Invalid path: %s", err) } fromPtr, err := NewPointerFromString(*opDef.From) if err != nil { - return MoveOp{}, fmt.Errorf("Invalid from: %s", err) + return QMoveOp{}, fmt.Errorf("Invalid from: %s", err) } - return MoveOp{Path: pathPtr, From: fromPtr}, nil + return QMoveOp{Path: pathPtr, From: fromPtr}, nil } func (parser) fmtOpDef(opDef OpDefinition) string { @@ -245,22 +245,22 @@ func NewOpDefinitionsFromOps(ops Ops) ([]OpDefinition, error) { opDefs = append(opDefs, opDef) - case CopyOp: + case QCopyOp: path := typedOp.Path.String() from := typedOp.From.String() opDefs = append(opDefs, OpDefinition{ - Type: "copy", + Type: "qcopy", Path: &path, From: &from, }) - case MoveOp: + case QMoveOp: path := typedOp.Path.String() from := typedOp.From.String() opDefs = append(opDefs, OpDefinition{ - Type: "move", + Type: "qmove", Path: &path, From: &from, }) diff --git a/patch/op_definition_test.go b/patch/op_definition_test.go index 7f20d41..2625ff9 100644 --- a/patch/op_definition_test.go +++ b/patch/op_definition_test.go @@ -23,14 +23,14 @@ var _ = Describe("NewOpsFromDefinitions", func() { trueBool = true ) - It("supports 'replace', 'remove', 'test', 'copy', 'move' operations", func() { + It("supports 'replace', 'remove', 'test', 'qcopy', 'qmove' operations", func() { opDefs := []OpDefinition{ {Type: "replace", Path: &path, Value: &val}, {Type: "remove", Path: &path}, {Type: "test", Path: &path, Value: &val}, {Type: "test", Path: &path, Absent: &trueBool}, - {Type: "copy", Path: &path, From: &from}, - {Type: "move", Path: &path, From: &from}, + {Type: "qcopy", Path: &path, From: &from}, + {Type: "qmove", Path: &path, From: &from}, } ops, err := NewOpsFromDefinitions(opDefs) @@ -41,8 +41,8 @@ var _ = Describe("NewOpsFromDefinitions", func() { RemoveOp{Path: MustNewPointerFromString("/abc")}, TestOp{Path: MustNewPointerFromString("/abc"), Value: 123}, TestOp{Path: MustNewPointerFromString("/abc"), Absent: true}, - CopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, - MoveOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, + QCopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, + QMoveOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, }))) }) @@ -210,33 +210,33 @@ var _ = Describe("NewOpsFromDefinitions", func() { }) }) - Describe("copy", func() { + Describe("qcopy", func() { It("requires path", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", From: &from}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qcopy", From: &from}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Copy operation [0]: Missing path within + Expect(err.Error()).To(Equal(`QCopy operation [0]: Missing path within { - "Type": "copy", + "Type": "qcopy", "From": "/abc" }`)) }) It("requires from", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &path}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qcopy", Path: &path}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Copy operation [0]: Missing from within + Expect(err.Error()).To(Equal(`QCopy operation [0]: Missing from within { - "Type": "copy", + "Type": "qcopy", "Path": "/abc" }`)) }) It("does not allow value", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &path, From: &from, Value: &val}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qcopy", Path: &path, From: &from, Value: &val}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Copy operation [0]: Cannot specify value within + Expect(err.Error()).To(Equal(`QCopy operation [0]: Cannot specify value within { - "Type": "copy", + "Type": "qcopy", "Path": "/abc", "From": "/abc", "Value": "" @@ -244,55 +244,55 @@ var _ = Describe("NewOpsFromDefinitions", func() { }) It("requires valid path", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &invalidPath, From: &from}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qcopy", Path: &invalidPath, From: &from}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Copy operation [0]: Invalid path: Expected to start with '/' within + Expect(err.Error()).To(Equal(`QCopy operation [0]: Invalid path: Expected to start with '/' within { - "Type": "copy", + "Type": "qcopy", "Path": "abc", "From": "/abc" }`)) }) It("requires valid from", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "copy", Path: &path, From: &invalidFrom}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qcopy", Path: &path, From: &invalidFrom}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Copy operation [0]: Invalid from: Expected to start with '/' within + Expect(err.Error()).To(Equal(`QCopy operation [0]: Invalid from: Expected to start with '/' within { - "Type": "copy", + "Type": "qcopy", "Path": "/abc", "From": "abc" }`)) }) }) - Describe("move", func() { + Describe("qmove", func() { It("requires path", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", From: &from}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qmove", From: &from}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Move operation [0]: Missing path within + Expect(err.Error()).To(Equal(`QMove operation [0]: Missing path within { - "Type": "move", + "Type": "qmove", "From": "/abc" }`)) }) It("requires from", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &path}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qmove", Path: &path}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Move operation [0]: Missing from within + Expect(err.Error()).To(Equal(`QMove operation [0]: Missing from within { - "Type": "move", + "Type": "qmove", "Path": "/abc" }`)) }) It("does not allow value", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &path, From: &from, Value: &val}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qmove", Path: &path, From: &from, Value: &val}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Move operation [0]: Cannot specify value within + Expect(err.Error()).To(Equal(`QMove operation [0]: Cannot specify value within { - "Type": "move", + "Type": "qmove", "Path": "/abc", "From": "/abc", "Value": "" @@ -300,22 +300,22 @@ var _ = Describe("NewOpsFromDefinitions", func() { }) It("requires valid path", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &invalidPath, From: &from}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qmove", Path: &invalidPath, From: &from}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Move operation [0]: Invalid path: Expected to start with '/' within + Expect(err.Error()).To(Equal(`QMove operation [0]: Invalid path: Expected to start with '/' within { - "Type": "move", + "Type": "qmove", "Path": "abc", "From": "/abc" }`)) }) It("requires valid from", func() { - _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "move", Path: &path, From: &invalidFrom}}) + _, err := NewOpsFromDefinitions([]OpDefinition{{Type: "qmove", Path: &path, From: &invalidFrom}}) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(`Move operation [0]: Invalid from: Expected to start with '/' within + Expect(err.Error()).To(Equal(`QMove operation [0]: Invalid from: Expected to start with '/' within { - "Type": "move", + "Type": "qmove", "Path": "/abc", "From": "abc" }`)) @@ -324,14 +324,14 @@ var _ = Describe("NewOpsFromDefinitions", func() { }) var _ = Describe("NewOpDefinitionsFromOps", func() { - It("supports 'replace', 'remove', 'test', 'copy', 'move' operations serialized", func() { + It("supports 'replace', 'remove', 'test', 'qcopy', 'qmove' operations serialized", func() { ops := Ops([]Op{ ReplaceOp{Path: MustNewPointerFromString("/abc"), Value: 123}, RemoveOp{Path: MustNewPointerFromString("/abc")}, TestOp{Path: MustNewPointerFromString("/abc"), Value: 123}, TestOp{Path: MustNewPointerFromString("/abc"), Absent: true}, - CopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, - MoveOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, + QCopyOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, + QMoveOp{Path: MustNewPointerFromString("/abc"), From: MustNewPointerFromString("/abc")}, }) opDefs, err := NewOpDefinitionsFromOps(ops) @@ -352,10 +352,10 @@ var _ = Describe("NewOpDefinitionsFromOps", func() { - type: test path: /abc absent: true -- type: copy +- type: qcopy path: /abc from: /abc -- type: move +- type: qmove path: /abc from: /abc `)) @@ -382,12 +382,12 @@ var _ = Describe("NewOpDefinitionsFromOps", func() { "Absent": true }, { - "Type": "copy", + "Type": "qcopy", "Path": "/abc", "From": "/abc" }, { - "Type": "move", + "Type": "qmove", "Path": "/abc", "From": "/abc" } From bb4d1d688d1fd1a96fa668c851df1ef5613e93f0 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 28 Apr 2020 16:47:18 -0700 Subject: [PATCH 7/7] Remove vestigial debugging code --- patch/op_definition_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/patch/op_definition_test.go b/patch/op_definition_test.go index 2625ff9..023de7e 100644 --- a/patch/op_definition_test.go +++ b/patch/op_definition_test.go @@ -5,7 +5,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/onsi/gomega/format" "gopkg.in/yaml.v2" . "github.com/SUSE/go-patch/patch" @@ -339,7 +338,6 @@ var _ = Describe("NewOpDefinitionsFromOps", func() { bs, err := yaml.Marshal(opDefs) Expect(err).ToNot(HaveOccurred()) - format.TruncatedDiff = false Expect("\n" + string(bs)).To(Equal(` - type: replace path: /abc