internal/postgres: fix GetUnitMeta with experiment flag

getUnitMetaQuery was missing "m.has_go_mod" in the SELECT, due to a
merge conflict. Tests are updated to catch errors with and without the
experiment flag for the future.

Change-Id: I4c8f5db7fb014bd81ff379e3cd93b65831958fd0
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/278753
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>
diff --git a/internal/postgres/path_test.go b/internal/postgres/path_test.go
index fa308d9..8f6f22d 100644
--- a/internal/postgres/path_test.go
+++ b/internal/postgres/path_test.go
@@ -13,6 +13,7 @@
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/google/safehtml"
 	"golang.org/x/pkgsite/internal"
+	"golang.org/x/pkgsite/internal/experiment"
 	"golang.org/x/pkgsite/internal/licenses"
 	"golang.org/x/pkgsite/internal/source"
 	"golang.org/x/pkgsite/internal/testing/sample"
@@ -57,11 +58,28 @@
 		}
 	}
 
-	for _, test := range []struct {
+	type teststruct struct {
 		name                  string
 		path, module, version string
 		want                  *internal.UnitMeta
-	}{
+	}
+
+	checkUnitMeta := func(ctx context.Context, test teststruct) {
+		got, err := testDB.GetUnitMeta(ctx, test.path, test.module, test.version)
+		if err != nil {
+			t.Fatal(err)
+		}
+		opts := []cmp.Option{
+			cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
+			cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod"),
+			cmp.AllowUnexported(source.Info{}, safehtml.HTML{}),
+		}
+		if diff := cmp.Diff(test.want, got, opts...); diff != "" {
+			t.Errorf("mismatch (-want +got):\n%s", diff)
+		}
+	}
+
+	for _, test := range []teststruct{
 		{
 			name:    "known module and version",
 			path:    "m.com/a",
@@ -205,18 +223,13 @@
 				test.want.IsRedistributable,
 			)
 			test.want.CommitTime = sample.CommitTime
-			got, err := testDB.GetUnitMeta(ctx, test.path, test.module, test.version)
-			if err != nil {
-				t.Fatal(err)
-			}
-			opts := []cmp.Option{
-				cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
-				cmpopts.IgnoreFields(internal.UnitMeta{}, "HasGoMod"),
-				cmp.AllowUnexported(source.Info{}, safehtml.HTML{}),
-			}
-			if diff := cmp.Diff(test.want, got, opts...); diff != "" {
-				t.Errorf("mismatch (-want +got):\n%s", diff)
-			}
+			t.Run("no experiment", func(t *testing.T) {
+				checkUnitMeta(ctx, test)
+			})
+			t.Run("with experiment", func(t *testing.T) {
+				ctx := experiment.NewContext(ctx, internal.ExperimentGetUnitMetaQuery)
+				checkUnitMeta(ctx, test)
+			})
 		})
 	}
 }
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go
index 4c56e79..9081733 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -86,6 +86,7 @@
 		"m.version",
 		"m.commit_time",
 		"m.source_info",
+		"m.has_go_mod",
 		"u.name",
 		"u.redistributable",
 		"u.license_types",
@@ -114,6 +115,7 @@
 		"m.version",
 		"m.commit_time",
 		"m.source_info",
+		"m.has_go_mod",
 		"u.id AS unit_id",
 	).From("modules m").
 		Join("units u ON u.module_id = m.id").
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index 3ac4539..bea3c1a 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -161,7 +161,13 @@
 				test.want.IsRedistributable,
 			)
 			test.want.CommitTime = um.CommitTime
-			checkUnit(ctx, t, um, test.want)
+			t.Run("no experiment", func(t *testing.T) {
+				checkUnit(ctx, t, um, test.want)
+			})
+			t.Run("with experiment", func(t *testing.T) {
+				ctx := experiment.NewContext(ctx, internal.ExperimentGetUnitMetaQuery)
+				checkUnit(ctx, t, um, test.want)
+			})
 		})
 	}
 }