From fa1b32780216ee7e1d900895207c728e418fd74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20Henriquez?= Date: Tue, 12 Dec 2023 16:13:04 +0100 Subject: [PATCH] feat: log schema metadata (#574) --- pkg/annotator/annotator.go | 1 + pkg/annotator/annotator_test.go | 33 +++++++++++++++++++++++++++++++++ pkg/annotator/test_annotator.go | 1 - 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pkg/annotator/annotator_test.go delete mode 100644 pkg/annotator/test_annotator.go diff --git a/pkg/annotator/annotator.go b/pkg/annotator/annotator.go index 6e81824e..bf4904c4 100644 --- a/pkg/annotator/annotator.go +++ b/pkg/annotator/annotator.go @@ -25,6 +25,7 @@ func getSchemaMetadata(schema []byte) schemaMetadata { namespace := schemaContents.Get("self.namespace").String() version := schemaContents.Get("self.version").String() disableValidation := schemaContents.Get("disableValidation").Bool() + log.Debug().Msgf("🟡 vendor: %s, namespace: %s, version: %s, disableValidation: %t", vendor, namespace, version, disableValidation) return schemaMetadata{ Vendor: vendor, Namespace: namespace, diff --git a/pkg/annotator/annotator_test.go b/pkg/annotator/annotator_test.go new file mode 100644 index 00000000..68085eb1 --- /dev/null +++ b/pkg/annotator/annotator_test.go @@ -0,0 +1,33 @@ +package annotator + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetSchemaMetadata(t *testing.T) { + testData := []struct { + name string + input []byte + expected schemaMetadata + }{ + { + name: "Valid JSON", + input: []byte(`{"self":{"vendor":"testVendor","namespace":"testNamespace","version":"testVersion"},"disableValidation":true}`), + expected: schemaMetadata{ + Vendor: "testVendor", + Namespace: "testNamespace", + Version: "testVersion", + DisableValidation: true, + }, + }, + } + + for _, tc := range testData { + t.Run(tc.name, func(t *testing.T) { + result := getSchemaMetadata(tc.input) + assert.Equal(t, tc.expected, result) + }) + } +} diff --git a/pkg/annotator/test_annotator.go b/pkg/annotator/test_annotator.go deleted file mode 100644 index e4e7075b..00000000 --- a/pkg/annotator/test_annotator.go +++ /dev/null @@ -1 +0,0 @@ -package annotator