go/analysis/passes/httpresponse: add typeparams test

testdata/src/typeparams is similar to testdata/src/a but
uses type parameters.

For golang/go#48704

Change-Id: I91b101bda6e1da5b2de6830896a4b13508f31322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358696
Trust: Guodong Li <guodongli@google.com>
Run-TryBot: Guodong Li <guodongli@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/go/analysis/passes/httpresponse/httpresponse_test.go b/go/analysis/passes/httpresponse/httpresponse_test.go
index dac3ed6..a2b6815 100644
--- a/go/analysis/passes/httpresponse/httpresponse_test.go
+++ b/go/analysis/passes/httpresponse/httpresponse_test.go
@@ -5,13 +5,17 @@
 package httpresponse_test
 
 import (
-	"testing"
-
 	"golang.org/x/tools/go/analysis/analysistest"
 	"golang.org/x/tools/go/analysis/passes/httpresponse"
+	"golang.org/x/tools/internal/typeparams"
+	"testing"
 )
 
 func Test(t *testing.T) {
 	testdata := analysistest.TestData()
-	analysistest.Run(t, testdata, httpresponse.Analyzer, "a")
+	tests := []string{"a"}
+	if true || typeparams.Enabled {
+		tests = append(tests, "typeparams")
+	}
+	analysistest.Run(t, testdata, httpresponse.Analyzer, tests...)
 }
diff --git a/go/analysis/passes/httpresponse/testdata/src/typeparams/typeparams.go b/go/analysis/passes/httpresponse/testdata/src/typeparams/typeparams.go
new file mode 100644
index 0000000..65dd58c
--- /dev/null
+++ b/go/analysis/passes/httpresponse/testdata/src/typeparams/typeparams.go
@@ -0,0 +1,52 @@
+// 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.
+
+// This file contains tests for the httpresponse checker.
+
+//go:build go1.18
+
+package typeparams
+
+import (
+	"log"
+	"net/http"
+)
+
+func badHTTPGet[T any](url string) {
+	res, err := http.Get(url)
+	defer res.Body.Close() // want "using res before checking for errors"
+	if err != nil {
+		log.Fatal(err)
+	}
+}
+
+func mkClient[T any]() *T {
+	return nil
+}
+
+func badClientHTTPGet() {
+	client := mkClient[http.Client]()
+	res, _ := client.Get("")
+	defer res.Body.Close() // want "using res before checking for errors"
+}
+
+// User-defined type embedded "http.Client"
+type S[P any] struct {
+	http.Client
+}
+
+func unmatchedClientTypeName(client S[string]) {
+	res, _ := client.Get("")
+	defer res.Body.Close() // the name of client's type doesn't match "*http.Client"
+}
+
+// User-defined Client type
+type C[P any] interface {
+	Get(url string) (resp *P, err error)
+}
+
+func userDefinedClientType(client C[http.Response]) {
+	resp, _ := client.Get("http://foo.com")
+	defer resp.Body.Close() // "client" is not of type "*http.Client"
+}