From 057937db27165ec3f9a6b9cdaf9640ebda039914 Mon Sep 17 00:00:00 2001 From: merlin Date: Sun, 20 Oct 2024 18:00:59 +0300 Subject: [PATCH] add prefix to quoters tests --- internal/sanitize/sanitize_fuzz_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/sanitize/sanitize_fuzz_test.go b/internal/sanitize/sanitize_fuzz_test.go index 74655827..a8f2e779 100644 --- a/internal/sanitize/sanitize_fuzz_test.go +++ b/internal/sanitize/sanitize_fuzz_test.go @@ -7,17 +7,22 @@ import ( ) func FuzzQuoteString(f *testing.F) { - f.Add("") - f.Add("\n") + const prefix = "prefix" + f.Add("new\nline") f.Add("sample text") f.Add("sample q'u'o't'e's") f.Add("select 'quoted $42', $1") f.Fuzz(func(t *testing.T, input string) { - got := sanitize.QuoteString(nil, input) + got := string(sanitize.QuoteString([]byte(prefix), input)) want := oldQuoteString(input) - if want != string(got) { + quoted, ok := strings.CutPrefix(got, prefix) + if !ok { + t.Fatalf("result has no prefix") + } + + if want != quoted { t.Errorf("got %q", got) t.Fatalf("want %q", want) } @@ -25,6 +30,7 @@ func FuzzQuoteString(f *testing.F) { } func FuzzQuoteBytes(f *testing.F) { + const prefix = "prefix" f.Add([]byte(nil)) f.Add([]byte("\n")) f.Add([]byte("sample text")) @@ -32,10 +38,15 @@ func FuzzQuoteBytes(f *testing.F) { f.Add([]byte("select 'quoted $42', $1")) f.Fuzz(func(t *testing.T, input []byte) { - got := sanitize.QuoteBytes(nil, input) + got := string(sanitize.QuoteBytes([]byte(prefix), input)) want := oldQuoteBytes(input) - if want != string(got) { + quoted, ok := strings.CutPrefix(got, prefix) + if !ok { + t.Fatalf("result has no prefix") + } + + if want != quoted { t.Errorf("got %q", got) t.Fatalf("want %q", want) }