Skip to content

Commit

Permalink
cleanup unused code (#1010)
Browse files Browse the repository at this point in the history
this code was commited accidentally and is not used -> be gone

Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle authored Dec 19, 2024
1 parent 6691eea commit 91aa5af
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 63 deletions.
18 changes: 1 addition & 17 deletions tooling/templatize/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
46 changes: 0 additions & 46 deletions tooling/templatize/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
})
}
}

0 comments on commit 91aa5af

Please sign in to comment.