Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao committed Dec 11, 2024
1 parent a790dc3 commit 2997c76
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 94 deletions.
26 changes: 0 additions & 26 deletions internal/controller/atlasschema_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,32 +453,6 @@ func TestConfigTemplate(t *testing.T) {
require.EqualValues(t, expected, buf.String())
}

func TestTemplate_Func_RemoveSpecialChars(t *testing.T) {
var buf bytes.Buffer
tmpl, err := tmpl.New("specialChars").Parse(`
{{- removeSpecialChars .Text -}}
{{- removeSpecialChars .URL -}}
`)
require.NoError(t, err)
var textWithSpecialChars = "a\tb\rc\n"
err = tmpl.ExecuteTemplate(&buf, `specialChars`, struct {
Text string
URL *url.URL
}{
Text: textWithSpecialChars,
URL: &url.URL{},
})
require.NoError(t, err)
require.EqualValues(t, "abc", buf.String())
// invalid data type
err = tmpl.ExecuteTemplate(&buf, `specialChars`, struct {
Text int
}{
Text: 0,
})
require.ErrorContains(t, err, "unsupported type int")
}

func conditionReconciling() *dbv1alpha1.AtlasSchema {
return &dbv1alpha1.AtlasSchema{
ObjectMeta: objmeta(),
Expand Down
38 changes: 0 additions & 38 deletions internal/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ package controller

import (
"context"
"embed"
"errors"
"fmt"
"regexp"
"strings"
"text/template"
"time"

"ariga.io/atlas-go-sdk/atlasexec"
Expand Down Expand Up @@ -96,42 +94,6 @@ func NewAtlasExec(dir string, c *Cloud) (AtlasExec, error) {
}

var (
//go:embed templates
tmpls embed.FS
tmpl = template.Must(template.New("operator").
Funcs(template.FuncMap{
"hclValue": func(s string) string {
if s == "" {
return s
}
return strings.ReplaceAll(strings.ToUpper(s), "-", "_")
},
"slides": func(s []string) string {
b := &strings.Builder{}
b.WriteRune('[')
for i, v := range s {
if i > 0 {
b.WriteRune(',')
}
fmt.Fprintf(b, "%q", v)
}
b.WriteRune(']')
return b.String()
},
"removeSpecialChars": func(s interface{}) (string, error) {
r := regexp.MustCompile("[\t\r\n]")
switch s := s.(type) {
case string:
return r.ReplaceAllString(s, ""), nil
case fmt.Stringer:
return r.ReplaceAllString(s.String(), ""), nil
default:
return "", fmt.Errorf("unsupported type %T", s)
}
},
}).
ParseFS(tmpls, "templates/*.tmpl"),
)
sqlErrRegex = regexp.MustCompile(`sql/migrate: (execute: )?executing statement`)
)

Expand Down
30 changes: 0 additions & 30 deletions internal/controller/templates/atlas_migration.tmpl

This file was deleted.

0 comments on commit 2997c76

Please sign in to comment.