aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2021-07-19 15:33:42 -0400
committerJulie Qiu <julie@golang.org>2021-07-20 16:01:26 +0000
commitb6fa0ca1ea9909d429c811135ef4dbf901d2d494 (patch)
treec7e15591d6258a583c700278390bd459bef2fae7
parentf471605e911992ffec5634e693b82324eaae3efa (diff)
downloadgo-x-pkgsite-b6fa0ca1ea9909d429c811135ef4dbf901d2d494.tar.xz
internal/postgres/symbolsearch: add TestGenerateQuery
A test is added to ensure that queries are generated as expected. For golang/go#44142 Change-Id: I595d161973582f33009a2d4165fb867711f12b63 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/335750 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
-rw-r--r--internal/postgres/symbolsearch/symbolsearch_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/postgres/symbolsearch/symbolsearch_test.go b/internal/postgres/symbolsearch/symbolsearch_test.go
new file mode 100644
index 00000000..c5ae553b
--- /dev/null
+++ b/internal/postgres/symbolsearch/symbolsearch_test.go
@@ -0,0 +1,30 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package symbolsearch
+
+import (
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+// TestGenerateQuery ensure that go generate was run and the generated queries
+// are up to date with the raw queries.
+func TestGenerateQuery(t *testing.T) {
+ for _, test := range []struct {
+ name, q, want string
+ }{
+ {"querySymbol", RawQuerySymbol, QuerySymbol},
+ {"queryPackageDotSymbol", RawQueryPackageDotSymbol, QueryPackageDotSymbol},
+ {"queryOneDot", RawQueryOneDot, QueryOneDot},
+ {"queryMultiWord", RawQueryMultiWord, QueryMultiWord},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ if diff := cmp.Diff(test.want, test.q); diff != "" {
+ t.Errorf("mismatch (-want, +got):\n%s", diff)
+ }
+ })
+ }
+}