internal/testing/integration: use standard examples

For golang/go#44214

Change-Id: Ibb19ba4480499b1264fb5a4adc70f1ebf95eac48
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/290895
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/testing/integration/fetch_test.go b/internal/testing/integration/fetch_test.go
index 9b44284..51b2ed8 100644
--- a/internal/testing/integration/fetch_test.go
+++ b/internal/testing/integration/fetch_test.go
@@ -11,27 +11,16 @@
 	"testing"
 
 	"golang.org/x/pkgsite/internal/postgres"
-	"golang.org/x/pkgsite/internal/proxy"
-	"golang.org/x/pkgsite/internal/testing/sample"
-	"golang.org/x/pkgsite/internal/testing/testhelper"
 )
 
 func TestFrontendFetchForMasterVersion(t *testing.T) {
 	defer postgres.ResetTestDB(testDB, t)
 
-	// Add sample.ModulePath@sample.VersionString to the database.
-	// Check that GET /sample.ModulePath returns a 200.
-	testModule := &proxy.Module{
-		ModulePath: sample.ModulePath,
-		Version:    "v1.0.0",
-		Files: map[string]string{
-			"found.go":       "package found\nconst Value = 123",
-			"dir/pkg/pkg.go": "package pkg\nconst Value = 321",
-			"LICENSE":        testhelper.MITLicense,
-		},
-	}
+	// Add a module to the database.
+	// Check that GET of the module's path returns a 200.
 	ctx := context.Background()
-	q, teardown := setupQueue(ctx, t, []*proxy.Module{testModule})
+	q, teardown := setupQueue(ctx, t, testModules[:1])
+	const modulePath = "example.com/basic"
 	defer teardown()
 	ts := setupFrontend(ctx, t, q)
 
@@ -39,21 +28,21 @@
 		method, urlPath string
 		status          int
 	}{
-		// Validate that the sample.ModulePath does not exist in the database.
-		{http.MethodGet, sample.ModulePath, http.StatusNotFound},
+		// Validate that the modulePath does not exist in the database.
+		{http.MethodGet, modulePath, http.StatusNotFound},
 		// Insert the latest version of the module using the frontend fetch
 		// endpoint.
-		{http.MethodPost, fmt.Sprintf("fetch/%s", sample.ModulePath), http.StatusOK},
-		// Validate that sample.ModulePath@master does not exist in the
-		// database. GET /sample.ModulePath@master should return a 404.
-		{http.MethodGet, fmt.Sprintf("%s@master", sample.ModulePath), http.StatusNotFound},
+		{http.MethodPost, fmt.Sprintf("fetch/%s", modulePath), http.StatusOK},
+		// Validate that modulePath@master does not exist in the
+		// database. GET /modulePath@master should return a 404.
+		{http.MethodGet, fmt.Sprintf("%s@master", modulePath), http.StatusNotFound},
 		// Insert the master version of the module using the frontend fetch
 		// endpoint.
-		{http.MethodPost, fmt.Sprintf("fetch/%s@master", sample.ModulePath), http.StatusOK},
-		// Check that GET /sample.ModulePath@master now returns a 200.
-		{http.MethodGet, fmt.Sprintf("%s@master", sample.ModulePath), http.StatusOK},
-		// Check that GET /mod/sample.ModulePath@master also returns a 200.
-		{http.MethodGet, fmt.Sprintf("mod/%s@master", sample.ModulePath), http.StatusOK},
+		{http.MethodPost, fmt.Sprintf("fetch/%s@master", modulePath), http.StatusOK},
+		// Check that GET /modulePath@master now returns a 200.
+		{http.MethodGet, fmt.Sprintf("%s@master", modulePath), http.StatusOK},
+		// Check that GET /mod/modulePath@master also returns a 200.
+		{http.MethodGet, fmt.Sprintf("mod/%s@master", modulePath), http.StatusOK},
 	} {
 		testURL := ts.URL + "/" + req.urlPath
 		validateResponse(t, req.method, testURL, req.status, nil)
diff --git a/internal/testing/integration/frontend_doc_render_test.go b/internal/testing/integration/frontend_doc_render_test.go
index 2c61951..053c05a 100644
--- a/internal/testing/integration/frontend_doc_render_test.go
+++ b/internal/testing/integration/frontend_doc_render_test.go
@@ -17,8 +17,6 @@
 	"github.com/google/go-cmp/cmp"
 	"golang.org/x/pkgsite/internal/experiment"
 	"golang.org/x/pkgsite/internal/postgres"
-	"golang.org/x/pkgsite/internal/proxy"
-	"golang.org/x/pkgsite/internal/testing/testhelper"
 )
 
 // Test that the worker saves the information needed to render
@@ -26,44 +24,15 @@
 func TestFrontendDocRender(t *testing.T) {
 	defer postgres.ResetTestDB(testDB, t)
 
-	m := &proxy.Module{
-		ModulePath: "github.com/foo/fdoc",
-		Version:    "v1.2.3",
-		Files: map[string]string{
-			"go.mod":  "module github.com/foo/fdoc",
-			"LICENSE": testhelper.MITLicense,
-			"file.go": `
-					// Package fdoc is a test of frontend doc rendering.
-					package fdoc
-
-					import 	"time"
-
-					// C is a constant.
-					const C = 123
-
-					// F is a function.
-					func F(t time.Time, s string) (T, u) {
-						x := 3
-						x = C
-					}
-			`,
-			"file2.go": `
-					package fdoc
-
-					var V = C
-					type T int
-					type u int
-			`,
-		},
-	}
-
 	// Process with saving the source.
 	processVersions(
 		experiment.NewContext(context.Background()),
-		t, []*proxy.Module{m})
+		t, testModules)
 
-	workerDoc := getDoc(t, m.ModulePath)
-	frontendDoc := getDoc(t, m.ModulePath)
+	const modulePath = "example.com/basic"
+
+	workerDoc := getDoc(t, modulePath)
+	frontendDoc := getDoc(t, modulePath)
 	if diff := cmp.Diff(workerDoc, frontendDoc); diff != "" {
 		t.Errorf("mismatch (-worker, +frontend):\n%s", diff)
 	}
diff --git a/internal/testing/integration/integration_test.go b/internal/testing/integration/integration_test.go
index 20d5bc5..569fda3 100644
--- a/internal/testing/integration/integration_test.go
+++ b/internal/testing/integration/integration_test.go
@@ -25,14 +25,17 @@
 	"golang.org/x/pkgsite/internal/proxy"
 	"golang.org/x/pkgsite/internal/queue"
 	"golang.org/x/pkgsite/internal/source"
-	"golang.org/x/pkgsite/internal/testing/testhelper"
 	"golang.org/x/pkgsite/internal/worker"
 )
 
-var testDB *postgres.DB
+var (
+	testDB      *postgres.DB
+	testModules []*proxy.Module
+)
 
 func TestMain(m *testing.M) {
 	dochtml.LoadTemplates(template.TrustedSourceFromConstant("../../../content/static/html/doc"))
+	testModules = proxy.LoadTestModules("../../proxy/testdata")
 	postgres.RunDBTests("discovery_integration_test", m, &testDB)
 }
 
@@ -42,24 +45,7 @@
 
 	defer postgres.ResetTestDB(testDB, t)
 
-	var (
-		modulePath = "github.com/my/module"
-		version    = "v1.0.0"
-		moduleData = map[string]string{
-			"go.mod":     "module " + modulePath,
-			"foo/foo.go": "package foo\n\nconst Foo = 525600",
-			"README.md":  "This is a readme",
-			"LICENSE":    testhelper.MITLicense,
-		}
-	)
-	testModules := []*proxy.Module{
-		{
-			ModulePath: modulePath,
-			Version:    version,
-			Files:      moduleData,
-		},
-	}
-	proxyClient, indexClient, teardownClients := setupProxyAndIndex(t, testModules...)
+	proxyClient, indexClient, teardownClients := setupProxyAndIndex(t)
 	defer teardownClients()
 
 	redisCache, err := miniredis.Run()
@@ -117,12 +103,12 @@
 	time.Sleep(100 * time.Millisecond)
 	queue.WaitForTesting(ctx)
 
-	body, err := doGet(frontendHTTP.URL + "/github.com/my/module/foo")
+	body, err := doGet(frontendHTTP.URL + "/example.com/basic")
 	if err != nil {
 		t.Fatal(err)
 	}
-	if idx := strings.Index(string(body), "525600"); idx < 0 {
-		t.Error("Documentation constant 525600 not found in body")
+	if idx := strings.Index(string(body), "v1.1.0"); idx < 0 {
+		t.Error("Documentation constant v1.1.0 not found in body")
 	}
 }
 
@@ -144,11 +130,11 @@
 	return body, nil
 }
 
-func setupProxyAndIndex(t *testing.T, modules ...*proxy.Module) (*proxy.Client, *index.Client, func()) {
+func setupProxyAndIndex(t *testing.T) (*proxy.Client, *index.Client, func()) {
 	t.Helper()
-	proxyClient, teardownProxy := proxy.SetupTestClient(t, modules)
+	proxyClient, teardownProxy := proxy.SetupTestClient(t, testModules)
 	var indexVersions []*internal.IndexVersion
-	for _, m := range modules {
+	for _, m := range testModules {
 		indexVersions = append(indexVersions, &internal.IndexVersion{
 			Path:      m.ModulePath,
 			Version:   m.Version,
diff --git a/internal/testing/testhelper/testhelper.go b/internal/testing/testhelper/testhelper.go
index 6b5aa1f..89cec1c 100644
--- a/internal/testing/testhelper/testhelper.go
+++ b/internal/testing/testhelper/testhelper.go
@@ -36,7 +36,7 @@
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`
 
 	// BSD0License is the contents of the BSD-0-Clause license. It is detectable
-	// by the licensecheck package, but not considered redistributable.
+	// by the licensecheck package, and is considered redistributable.
 	BSD0License = `Copyright 2019 Google Inc
 
 Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.