From 6fc3712761665df6ee099dabbead312a87d80f9f Mon Sep 17 00:00:00 2001 From: zhaque44 Date: Wed, 27 Mar 2024 23:12:25 -0500 Subject: [PATCH] adding tests for getExtFromSchema Signed-off-by: zhaque44 --- pkg/update/filter_test.go | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pkg/update/filter_test.go b/pkg/update/filter_test.go index 0cb9d11..3b08950 100644 --- a/pkg/update/filter_test.go +++ b/pkg/update/filter_test.go @@ -53,3 +53,54 @@ func TestSetAllCallbackAccept(t *testing.T) { }) } } + +func TestGetExtFromSchema(t *testing.T) { + tests := []struct { + name string + schema *spec.Schema + expectedExtension *extension + expectedError bool + }{ + { + name: "Extension Present", + schema: &spec.Schema{ + VendorExtensible: spec.VendorExtensible{ + Extensions: map[string]interface{}{ + K8sCliExtensionKey: &extension{ + Setter: &setter{ + Name: "testSetter", + Value: "testValue", + }, + }, + }, + }, + }, + expectedExtension: &extension{ + Setter: &setter{ + Name: "testSetter", + Value: "testValue", + }, + }, + expectedError: false, + }, + { + name: "Extension Not Present", + schema: &spec.Schema{}, + expectedError: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + g := NewWithT(t) + ext, err := getExtFromSchema(test.schema) + + if test.expectedError { + g.Expect(err).To(HaveOccurred()) + } else { + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(ext).To(Equal(test.expectedExtension)) + } + }) + } +}