aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module_test.go
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2025-10-20 16:30:00 +0800
committerJonathan Amsterdam <jba@google.com>2025-10-23 07:28:57 -0700
commitfe04cb7342faa5af6b014191b12b56d823382fc7 (patch)
treea11c98d144fe00c637e4b7d6b523035b01d83411 /internal/postgres/insert_module_test.go
parent31e4cbb15040258abb9a4e5eb0d5fcef6f8e0562 (diff)
downloadgo-x-pkgsite-fe04cb7342faa5af6b014191b12b56d823382fc7.tar.xz
internal/postgres: add skip-symbols list to saveModule
- Modules in the skip-symbols list will not have symbol information inserted into postgres. Change-Id: Ia52b9eb2d7cab662b967fa4a74c40cced0e44be4 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/713060 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Peter Weinberger <pjw@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
-rw-r--r--internal/postgres/insert_module_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 95df69bc..37dd8b7a 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -786,3 +786,62 @@ func TestPathsToInsert(t *testing.T) {
})
}
}
+
+func TestInsertModuleSkipSymbols(t *testing.T) {
+ t.Parallel()
+ ctx := context.Background()
+
+ checkSymbolsInserted := func(t *testing.T, db *DB, m *internal.Module) bool {
+ t.Helper()
+ var count int
+ err := db.db.QueryRow(ctx, `
+ SELECT count(*) FROM documentation_symbols ds
+ INNER JOIN documentation d ON d.id = ds.documentation_id
+ INNER JOIN units u ON u.id = d.unit_id
+ INNER JOIN modules mod ON mod.id = u.module_id
+ WHERE mod.module_path = $1 AND mod.version = $2`,
+ m.ModulePath, m.Version).Scan(&count)
+ if err != nil && err != sql.ErrNoRows {
+ t.Fatalf("error when checking for symbols: %v", err)
+ }
+ return count > 0
+ }
+
+ for _, test := range []struct {
+ name string
+ modulePath string
+ wantInserted bool
+ }{
+ {
+ name: "skipped",
+ modulePath: "github.com/gardener/gardener",
+ wantInserted: false,
+ },
+ {
+ name: "not skipped",
+ modulePath: "example.com/test-module",
+ wantInserted: true,
+ },
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ testDB, release := acquire(t)
+ defer release()
+
+ m := sample.Module(test.modulePath, "v1.2.3", "pkg")
+ m.Units[1].Documentation[0].API = []*internal.Symbol{
+ {
+ SymbolMeta: internal.SymbolMeta{
+ Name: "Foo",
+ Section: internal.SymbolSectionConstants,
+ Kind: internal.SymbolKindVariable,
+ },
+ },
+ }
+ MustInsertModule(ctx, t, testDB, m)
+
+ if got := checkSymbolsInserted(t, testDB, m); got != test.wantInserted {
+ t.Errorf("symbols inserted: got %t; want %t", got, test.wantInserted)
+ }
+ })
+ }
+}