internal/postgres: list non-redistributable packages

Currently, non-redistributable packages are not listed in the
directories section, since they won't have a row in the documentation
section. These are now listed with an empty synopsis.

Change-Id: Id787b91cd58c698daf547e9dff8921df5c0f097f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/280094
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 3644d64..3b2f429 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -89,8 +89,7 @@
 		wantu.LicenseContents = sample.Licenses
 		var subdirectories []*internal.PackageMeta
 		for _, u := range want.Units {
-			if u.IsPackage() && (strings.HasPrefix(u.Path, wantu.Path) ||
-				wantu.Path == stdlib.ModulePath) {
+			if u.IsPackage() && (strings.HasPrefix(u.Path, wantu.Path) || wantu.Path == stdlib.ModulePath) {
 				subdirectories = append(subdirectories, sample.PackageMeta(u.Path))
 			}
 		}
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go
index 9081733..a64c172 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -297,11 +297,12 @@
 		FROM modules m
 		INNER JOIN units u
 		ON u.module_id = m.id
-		INNER JOIN documentation d
+		LEFT JOIN documentation d
 		ON d.unit_id = u.id
 		WHERE
 			m.module_path = $1
 			AND m.version = $2
+			AND u.name != ''
 		ORDER BY path;`
 	var packages []*internal.PackageMeta
 	collect := func(rows *sql.Rows) error {
@@ -314,7 +315,7 @@
 			&pkg.Path,
 			&pkg.Name,
 			&pkg.IsRedistributable,
-			&pkg.Synopsis,
+			database.NullIsEmpty(&pkg.Synopsis),
 			pq.Array(&licenseTypes),
 			pq.Array(&licensePaths),
 		); err != nil {
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index bea3c1a..9d11a5b 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -194,6 +194,20 @@
 	}
 }
 
+func TestGetUnit_SubdirectoriesShowNonRedistPackages(t *testing.T) {
+	ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
+	defer cancel()
+
+	defer ResetTestDB(testDB, t)
+
+	m := sample.DefaultModule()
+	m.IsRedistributable = false
+	m.Packages()[0].IsRedistributable = false
+	if err := testDB.InsertModule(ctx, m); err != nil {
+		t.Fatal(err)
+	}
+}
+
 func TestGetUnitFieldSet(t *testing.T) {
 	ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
 	defer cancel()