From cd988f19bef0fc9841d5f27f624f01c81e7bc7ba Mon Sep 17 00:00:00 2001 From: zhaque44 Date: Fri, 2 Feb 2024 08:53:56 -0600 Subject: [PATCH] adding tests for accept function Signed-off-by: zhaque44 --- pkg/update/filter_test.go | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pkg/update/filter_test.go diff --git a/pkg/update/filter_test.go b/pkg/update/filter_test.go new file mode 100644 index 00000000..0cb9d118 --- /dev/null +++ b/pkg/update/filter_test.go @@ -0,0 +1,55 @@ +package update + +import ( + "testing" + + "github.com/go-logr/logr" + . "github.com/onsi/gomega" + "k8s.io/kube-openapi/pkg/validation/spec" + "sigs.k8s.io/kustomize/kyaml/yaml" +) + +func TestSetAllCallbackAccept(t *testing.T) { + tests := []struct { + name string + object *yaml.RNode + settersSchema *spec.Schema + expectedError bool + }{ + { + name: "Accept - Scalar Node", + object: yaml.NewRNode(&yaml.Node{ + Kind: yaml.ScalarNode, + Value: "test", + }), + settersSchema: &spec.Schema{}, + expectedError: false, + }, + { + name: "Accept - Scalar Node - Error", + object: yaml.NewRNode(&yaml.Node{ + Kind: yaml.ScalarNode, + Value: "test", + }), + settersSchema: nil, + expectedError: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + callbackInstance := SetAllCallback{ + SettersSchema: test.settersSchema, + Trace: logr.Discard(), + } + + err := accept(&callbackInstance, test.object, "", test.settersSchema) + g := NewWithT(t) + if test.expectedError { + g.Expect(err).To(HaveOccurred()) + } else { + g.Expect(err).ToNot(HaveOccurred()) + } + }) + } +}