Skip to content

Commit

Permalink
tests: add tests for go/sqlescape (#14987)
Browse files Browse the repository at this point in the history
Signed-off-by: Manik Rana <[email protected]>
Signed-off-by: Manik Rana <[email protected]>
  • Loading branch information
Maniktherana authored Jan 29, 2024
1 parent 4c23faa commit 68f6922
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions go/sqlescape/ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package sqlescape

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
})
}
}

0 comments on commit 68f6922

Please sign in to comment.