From 91aa5af1aee62b40fae04d279861c8ab4137afa8 Mon Sep 17 00:00:00 2001 From: Gerd Oberlechner Date: Thu, 19 Dec 2024 14:41:55 +0100 Subject: [PATCH] cleanup unused code (#1010) this code was commited accidentally and is not used -> be gone Signed-off-by: Gerd Oberlechner --- tooling/templatize/pkg/config/config.go | 18 +------- tooling/templatize/pkg/config/config_test.go | 46 -------------------- 2 files changed, 1 insertion(+), 63 deletions(-) diff --git a/tooling/templatize/pkg/config/config.go b/tooling/templatize/pkg/config/config.go index b084731d3..41b2547b0 100644 --- a/tooling/templatize/pkg/config/config.go +++ b/tooling/templatize/pkg/config/config.go @@ -2,7 +2,6 @@ package config import ( "bytes" - "encoding/json" "fmt" "io" "os" @@ -270,10 +269,7 @@ func PreprocessContent(content []byte, vars map[string]any) ([]byte, error) { } func PreprocessContentIntoWriter(content []byte, vars map[string]any, writer io.Writer) error { - funcMap := template.FuncMap{ - "json": jsonEncoder, - } - tmpl, err := template.New("file").Funcs(funcMap).Parse(string(content)) + tmpl, err := template.New("file").Parse(string(content)) if err != nil { return fmt.Errorf("failed to parse template: %w", err) } @@ -283,15 +279,3 @@ func PreprocessContentIntoWriter(content []byte, vars map[string]any, writer io. } return nil } - -func jsonEncoder(value interface{}) (string, error) { - valueType := reflect.TypeOf(value) - if valueType.Kind() == reflect.String { - return value.(string), nil - } - jsonBytes, err := json.Marshal(value) - if err != nil { - return "", err - } - return string(jsonBytes), nil -} diff --git a/tooling/templatize/pkg/config/config_test.go b/tooling/templatize/pkg/config/config_test.go index a73b0f800..e999ec7db 100644 --- a/tooling/templatize/pkg/config/config_test.go +++ b/tooling/templatize/pkg/config/config_test.go @@ -5,7 +5,6 @@ import ( "os" "testing" - "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/Azure/ARO-HCP/tooling/templatize/internal/testutil" @@ -309,48 +308,3 @@ func TestPreprocessContentMissingKey(t *testing.T) { }) } } - -func TestPreprocessContentJson(t *testing.T) { - templateContent := "{{ .variable | json }}" - - testCases := []struct { - name string - value any - expectedResult string - }{ - { - name: "string value", - value: "foo", - expectedResult: "foo", - }, - { - name: "array value", - value: []string{"foo", "bar"}, - expectedResult: "[\"foo\",\"bar\"]", - }, - { - name: "int value", - value: 42, - expectedResult: "42", - }, - { - name: "bool value", - value: true, - expectedResult: "true", - }, - } - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - processed, err := PreprocessContent( - []byte(templateContent), - map[string]any{ - "variable": tc.value, - }, - ) - assert.Nil(t, err) - if diff := cmp.Diff(string(processed), string(tc.expectedResult)); diff != "" { - t.Errorf("got diff between expected and actual result\ndiff:\n%s\n\nIf this is expected, re-run the test with `UPDATE=true go test ./...` to update the fixtures.", diff) - } - }) - } -}