From 68f69221b4a8fe50f0cc3b52e2f1e657c4973901 Mon Sep 17 00:00:00 2001 From: Manik Rana Date: Mon, 29 Jan 2024 16:50:17 +0530 Subject: [PATCH] tests: add tests for `go/sqlescape` (#14987) Signed-off-by: Manik Rana Signed-off-by: Manik Rana --- go/sqlescape/ids_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/go/sqlescape/ids_test.go b/go/sqlescape/ids_test.go index 37b14206416..230befe15d6 100644 --- a/go/sqlescape/ids_test.go +++ b/go/sqlescape/ids_test.go @@ -14,6 +14,7 @@ limitations under the License. package sqlescape import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -214,6 +215,7 @@ func BenchmarkEscapeID(b *testing.B) { testcases := []string{ "aa", "a`a", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", } + for _, tc := range testcases { name := tc if len(name) > 10 { @@ -226,3 +228,30 @@ func BenchmarkEscapeID(b *testing.B) { }) } } + +func TestEscapeIDs(t *testing.T) { + testCases := []struct { + input []string + expected []string + }{ + { + input: []string{"abc", "def", "ghi"}, + expected: []string{"`abc`", "`def`", "`ghi`"}, + }, + { + input: []string{"abc", "a`a", "`ghi`"}, + expected: []string{"`abc`", "`a``a`", "```ghi```"}, + }, + { + input: []string{}, + expected: []string{}, + }, + } + + for _, tt := range testCases { + t.Run(fmt.Sprintf("%v", tt.input), func(t *testing.T) { + out := EscapeIDs(tt.input) + assert.Equal(t, tt.expected, out) + }) + } +}