Repository: googleapis/gapic-generator-go
Pull request #1411 (2023-10-05 21:26:34)

chore(internal): run tests in parallel
Use `t.Run` to run tests in parallel where relevant. Additionally, remove the `name` argument `txtdiff.Diff` since it isn't being used.

snippet-bot[bot]: <!-- probot comment [11299897]-->
Here is the summary of changes.
<details>
  <summary>You are about to add 1 region tag.</summary>

  - [internal/gengapic/snippets_test.go:233](https://github.com/julieqiu/gapic-generator-go/blob/f48394f418add42c45447a739b40314bbcb60f69/internal/gengapic/snippets_test.go#L233), tag `_pkg_generated_Foo_%s_sync`

</details>

<details>
  <summary>You are about to delete 1 region tag.
</summary>

  - [internal/gengapic/snippets_test.go:233](https://github.com/googleapis/gapic-generator-go/blob/c6c22fa4810e209d63092166b8dee433f7f42415/internal/gengapic/snippets_test.go#L233), tag `_pkg_generated_Foo_%s_sync`

</details>

---
This comment is generated by [snippet-bot](https://github.com/apps/snippet-bot).
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add `snippet-bot:force-run` label or use the checkbox below:
- [ ] Refresh this comment


Patch:
diff --git a/internal/txtdiff/diff.go b/internal/txtdiff/diff.go
index 436142d..ea0c901 100644
--- a/internal/txtdiff/diff.go
+++ b/internal/txtdiff/diff.go
@@ -27,7 +27,7 @@ var updateGolden = flag.Bool("update_golden", false, "update golden files")
 
 // Diff is a test helper, testing got against contents of goldenFile. If they do not match,
 // Diff fails the test, reporting the diff.
-func Diff(t *testing.T, name, got, goldenFile string) {
+func Diff(t *testing.T, got, goldenFile string) {
 	t.Helper()
 
 	if *updateGolden {


Test patch:
diff --git a/internal/gencli/cmd_file_test.go b/internal/gencli/cmd_file_test.go
index 4c8d1c1..8015c9a 100644
--- a/internal/gencli/cmd_file_test.go
+++ b/internal/gencli/cmd_file_test.go
@@ -205,17 +205,19 @@ func TestCommandFile(t *testing.T) {
 			goldenPath: filepath.Join("testdata", "manage-todos.want"),
 		},
 	} {
-		tst.g.genCommandFile(tst.cmd)
-		if tst.g.response.GetError() != "" {
-			t.Errorf("Error generating the command file %s: %s", tst.name, tst.g.response.GetError())
-			return
-		}
+		t.Run(tst.name, func(t *testing.T) {
+			tst.g.genCommandFile(tst.cmd)
+			if tst.g.response.GetError() != "" {
+				t.Errorf("Error generating the command file %s: %s", tst.name, tst.g.response.GetError())
+				return
+			}
 
-		file := tst.g.response.File[0]
+			file := tst.g.response.File[0]
 
-		if file.GetName() != tst.name+".go" {
-			t.Errorf("(%+v).genCommands() = %s, want %s", tst.g, file.GetName(), tst.name+".go")
-		}
-		txtdiff.Diff(t, tst.name, file.GetContent(), tst.goldenPath)
+			if file.GetName() != tst.name+".go" {
+				t.Errorf("(%+v).genCommands() = %s, want %s", tst.g, file.GetName(), tst.name+".go")
+			}
+			txtdiff.Diff(t, file.GetContent(), tst.goldenPath)
+		})
 	}
 }
diff --git a/internal/gencli/completion_file_test.go b/internal/gencli/completion_file_test.go
index f7ca4e6..b6630d8 100644
--- a/internal/gencli/completion_file_test.go
+++ b/internal/gencli/completion_file_test.go
@@ -44,5 +44,5 @@ func TestCompletionFile(t *testing.T) {
 	if file.GetName() != "completion.go" {
 		t.Errorf("(%s).genCompletionCmdFile() = %s, want %s", g.root, file.GetName(), "completion.go")
 	}
-	txtdiff.Diff(t, "completion_file", file.GetContent(), filepath.Join("testdata", "completion_file.want"))
+	txtdiff.Diff(t, file.GetContent(), filepath.Join("testdata", "completion_file.want"))
 }
diff --git a/internal/gencli/root_file_test.go b/internal/gencli/root_file_test.go
index c46c020..62a9a77 100644
--- a/internal/gencli/root_file_test.go
+++ b/internal/gencli/root_file_test.go
@@ -44,5 +44,5 @@ func TestRootFile(t *testing.T) {
 	if file.GetName() != "root.go" {
 		t.Errorf("(%s).genRootCmdFile() = %s, want %s", g.root, file.GetName(), "root.go")
 	}
-	txtdiff.Diff(t, "root_file", file.GetContent(), filepath.Join("testdata", "root_file.want"))
+	txtdiff.Diff(t, file.GetContent(), filepath.Join("testdata", "root_file.want"))
 }
diff --git a/internal/gencli/service_file_test.go b/internal/gencli/service_file_test.go
index 29defe0..a6bbe06 100644
--- a/internal/gencli/service_file_test.go
+++ b/internal/gencli/service_file_test.go
@@ -68,5 +68,5 @@ func TestServiceFile(t *testing.T) {
 	if file.GetName() != "todo_service.go" {
 		t.Errorf("(%+v).genServiceCmdFile(%+v) = %s, want %s", g, cmd, file.GetName(), "todo_service.go")
 	}
-	txtdiff.Diff(t, "service_file", file.GetContent(), filepath.Join("testdata", "service_file.want"))
+	txtdiff.Diff(t, file.GetContent(), filepath.Join("testdata", "service_file.want"))
 }
diff --git a/internal/gengapic/client_init_test.go b/internal/gengapic/client_init_test.go
index 9b10a86..35fefb7 100644
--- a/internal/gengapic/client_init_test.go
+++ b/internal/gengapic/client_init_test.go
@@ -244,16 +244,17 @@ func TestClientOpt(t *testing.T) {
 			},
 		},
 	} {
-		g.reset()
-		g.hasIAMPolicyOverrides = tst.hasOverride
-		if err := g.clientOptions(tst.serv, tst.servName); err != nil {
-			t.Error(err)
-			continue
-		}
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("TestClientOpt(%s): imports got(-),want(+):\n%s", tst.tstName, diff)
-		}
-		txtdiff.Diff(t, tst.tstName, g.pt.String(), filepath.Join("testdata", tst.tstName+".want"))
+		t.Run(tst.tstName, func(t *testing.T) {
+			g.reset()
+			g.hasIAMPolicyOverrides = tst.hasOverride
+			if err := g.clientOptions(tst.serv, tst.servName); err != nil {
+				t.Fatal(err)
+			}
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("TestClientOpt(%s): imports got(-),want(+):\n%s", tst.tstName, diff)
+			}
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", tst.tstName+".want"))
+		})
 	}
 }
 
@@ -530,97 +531,99 @@ func TestClientInit(t *testing.T) {
 			},
 		},
 	} {
-		setExt := tst.setExt
-		if setExt == nil {
-			setExt = func() (protoreflect.ExtensionType, interface{}) {
-				return annotations.E_Http, &annotations.HttpRule{
-					Pattern: &annotations.HttpRule_Get{
-						Get: "/zip",
-					},
+		t.Run(tst.tstName, func(t *testing.T) {
+			setExt := tst.setExt
+			if setExt == nil {
+				setExt = func() (protoreflect.ExtensionType, interface{}) {
+					return annotations.E_Http, &annotations.HttpRule{
+						Pattern: &annotations.HttpRule_Get{
+							Get: "/zip",
+						},
+					}
 				}
 			}
-		}
-		ext, value := setExt()
-		proto.SetExtension(tst.serv.Method[0].GetOptions(), ext, value)
+			ext, value := setExt()
+			proto.SetExtension(tst.serv.Method[0].GetOptions(), ext, value)
 
-		fds := append(mixinDescriptors(), &descriptor.FileDescriptorProto{
-			Package: proto.String("mypackage"),
-			Options: &descriptor.FileOptions{
-				GoPackage: proto.String("github.com/googleapis/mypackage/v1"),
-			},
-			Service: []*descriptor.ServiceDescriptorProto{tst.serv, tst.customOpServ},
-			MessageType: []*descriptor.DescriptorProto{
-				{
-					Name: proto.String("Bar"),
+			fds := append(mixinDescriptors(), &descriptor.FileDescriptorProto{
+				Package: proto.String("mypackage"),
+				Options: &descriptor.FileOptions{
+					GoPackage: proto.String("github.com/googleapis/mypackage/v1"),
 				},
-				{
-					Name: proto.String("Foo"),
+				Service: []*descriptor.ServiceDescriptorProto{tst.serv, tst.customOpServ},
+				MessageType: []*descriptor.DescriptorProto{
+					{
+						Name: proto.String("Bar"),
+					},
+					{
+						Name: proto.String("Foo"),
+					},
+					cop,
 				},
-				cop,
-			},
-		})
-		request := plugin.CodeGeneratorRequest{
-			Parameter: tst.parameter,
-			ProtoFile: fds,
-		}
-		g.init(&request)
-		g.comments = map[protoiface.MessageV1]string{
-			tst.serv:                "Foo service does stuff.",
-			tst.serv.GetMethod()[0]: "Does some stuff.",
-		}
-		g.mixins = tst.mixins
-		g.serviceConfig = &serviceconfig.Service{
-			Apis: []*apipb.Api{
-				{Name: "foo.bar.Baz"},
-				{Name: "google.iam.v1.IAMPolicy"},
-				{Name: "google.cloud.location.Locations"},
-				{Name: "google.longrunning.Operations"},
-			},
-		}
-		g.aux.customOp = &customOp{
-			message: cop,
-		}
-		if tst.customOpServ != nil {
-			g.customOpServices = map[*descriptor.ServiceDescriptorProto]*descriptor.ServiceDescriptorProto{
-				tst.serv: tst.customOpServ,
+			})
+			request := plugin.CodeGeneratorRequest{
+				Parameter: tst.parameter,
+				ProtoFile: fds,
+			}
+			g.init(&request)
+			g.comments = map[protoiface.MessageV1]string{
+				tst.serv:                "Foo service does stuff.",
+				tst.serv.GetMethod()[0]: "Does some stuff.",
+			}
+			g.mixins = tst.mixins
+			g.serviceConfig = &serviceconfig.Service{
+				Apis: []*apipb.Api{
+					{Name: "foo.bar.Baz"},
+					{Name: "google.iam.v1.IAMPolicy"},
+					{Name: "google.cloud.location.Locations"},
+					{Name: "google.longrunning.Operations"},
+				},
+			}
+			g.aux.customOp = &customOp{
+				message: cop,
+			}
+			if tst.customOpServ != nil {
+				g.customOpServices = map[*descriptor.ServiceDescriptorProto]*descriptor.ServiceDescriptorProto{
+					tst.serv: tst.customOpServ,
+				}
 			}
-		}
-
-		g.reset()
-		sm := snippets.NewMetadata("mypackage", "github.com/googleapis/mypackage", "mypackagego")
-		sm.AddService(tst.serv.GetName(), "mypackage.googleapis.com")
-		for _, m := range tst.serv.GetMethod() {
-			sm.AddMethod(tst.serv.GetName(), m.GetName(), "mypackage", tst.serv.GetName(), 50)
-		}
-		for _, m := range g.getMixinMethods() {
-			sm.AddMethod(tst.serv.GetName(), m.GetName(), "mypackage", tst.serv.GetName(), 50)
-		}
-		g.snippetMetadata = sm
-		g.makeClients(tst.serv, tst.servName)
-
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("ClientInit(%s) imports got(-),want(+):\n%s", tst.tstName, diff)
-		}
 
-		txtdiff.Diff(t, tst.tstName, g.pt.String(), filepath.Join("testdata", tst.tstName+".want"))
-		mi := g.snippetMetadata.ToMetadataIndex()
-		if got := len(mi.Snippets); got != tst.wantNumSnps {
-			t.Errorf("%s: got %d want len %d", t.Name(), tst.wantNumSnps, got)
-		}
-		for _, snp := range mi.Snippets {
-			if got := snp.ClientMethod.Parameters[0].Name; got != "ctx" {
-				t.Errorf("%s: got %s want ctx,", t.Name(), got)
+			g.reset()
+			sm := snippets.NewMetadata("mypackage", "github.com/googleapis/mypackage", "mypackagego")
+			sm.AddService(tst.serv.GetName(), "mypackage.googleapis.com")
+			for _, m := range tst.serv.GetMethod() {
+				sm.AddMethod(tst.serv.GetName(), m.GetName(), "mypackage", tst.serv.GetName(), 50)
 			}
-			if got := snp.ClientMethod.Parameters[1].Name; got != "req" {
-				t.Errorf("%s: got %s want req,", t.Name(), got)
+			for _, m := range g.getMixinMethods() {
+				sm.AddMethod(tst.serv.GetName(), m.GetName(), "mypackage", tst.serv.GetName(), 50)
 			}
-			if got := snp.ClientMethod.Parameters[2].Name; got != "opts" {
-				t.Errorf("%s: got %s want opts,", t.Name(), got)
+			g.snippetMetadata = sm
+			g.makeClients(tst.serv, tst.servName)
+
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("ClientInit(%s) imports got(-),want(+):\n%s", tst.tstName, diff)
 			}
-			if snp.ClientMethod.ShortName != "CancelOperation" && snp.ClientMethod.ShortName != "DeleteOperation" && snp.ClientMethod.ResultType == "" {
-				t.Errorf("%s: got empty string, want ResultType for %s", t.Name(), snp.ClientMethod.ShortName)
+
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", tst.tstName+".want"))
+			mi := g.snippetMetadata.ToMetadataIndex()
+			if got := len(mi.Snippets); got != tst.wantNumSnps {
+				t.Errorf("%s: got %d want len %d", t.Name(), tst.wantNumSnps, got)
 			}
-		}
+			for _, snp := range mi.Snippets {
+				if got := snp.ClientMethod.Parameters[0].Name; got != "ctx" {
+					t.Errorf("%s: got %s want ctx,", t.Name(), got)
+				}
+				if got := snp.ClientMethod.Parameters[1].Name; got != "req" {
+					t.Errorf("%s: got %s want req,", t.Name(), got)
+				}
+				if got := snp.ClientMethod.Parameters[2].Name; got != "opts" {
+					t.Errorf("%s: got %s want opts,", t.Name(), got)
+				}
+				if snp.ClientMethod.ShortName != "CancelOperation" && snp.ClientMethod.ShortName != "DeleteOperation" && snp.ClientMethod.ResultType == "" {
+					t.Errorf("%s: got empty string, want ResultType for %s", t.Name(), snp.ClientMethod.ShortName)
+				}
+			}
+		})
 	}
 }
 
diff --git a/internal/gengapic/custom_operation_test.go b/internal/gengapic/custom_operation_test.go
index c383cd4..62554ac 100644
--- a/internal/gengapic/custom_operation_test.go
+++ b/internal/gengapic/custom_operation_test.go
@@ -117,7 +117,7 @@ func TestCustomOpInit(t *testing.T) {
 		opts: &options{pkgName: "bar"},
 	}
 	g.customOpInit("foo", "req", "op", req, opServ)
-	txtdiff.Diff(t, "custom_op_init_helper", g.pt.String(), filepath.Join("testdata", "custom_op_init_helper.want"))
+	txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", "custom_op_init_helper.want"))
 }
 
 func TestCustomOperationType(t *testing.T) {
@@ -266,16 +266,18 @@ func TestCustomOperationType(t *testing.T) {
 			errorField: true,
 		},
 	} {
-		op.Field = []*descriptor.FieldDescriptorProto{errorCodeField, errorMessageField, nameField, tst.st}
-		if tst.errorField {
-			op.Field = append(op.Field, errorField)
-		}
-		err := g.customOperationType()
-		if err != nil {
-			t.Fatal(err)
-		}
-		tn := "custom_op_type_" + tst.name
-		txtdiff.Diff(t, tn, g.pt.String(), filepath.Join("testdata", tn+".want"))
-		g.reset()
+		t.Run(tst.name, func(t *testing.T) {
+			op.Field = []*descriptor.FieldDescriptorProto{errorCodeField, errorMessageField, nameField, tst.st}
+			if tst.errorField {
+				op.Field = append(op.Field, errorField)
+			}
+			err := g.customOperationType()
+			if err != nil {
+				t.Fatal(err)
+			}
+			tn := "custom_op_type_" + tst.name
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", tn+".want"))
+			g.reset()
+		})
 	}
 }
diff --git a/internal/gengapic/doc_file_test.go b/internal/gengapic/doc_file_test.go
index bcfb9e4..763edc0 100644
--- a/internal/gengapic/doc_file_test.go
+++ b/internal/gengapic/doc_file_test.go
@@ -15,7 +15,6 @@
 package gengapic
 
 import (
-	"fmt"
 	"path/filepath"
 	"testing"
 
@@ -84,10 +83,12 @@ func TestDocFile(t *testing.T) {
 			want:   filepath.Join("testdata", "doc_file_beta.want"),
 		},
 	} {
-		g.opts.relLvl = tst.relLvl
-		g.genDocFile(42, []string{"https://foo.bar.com/auth", "https://zip.zap.com/auth"}, serv)
-		txtdiff.Diff(t, "doc_file", g.pt.String(), tst.want)
-		g.reset()
+		t.Run(tst.want, func(t *testing.T) {
+			g.opts.relLvl = tst.relLvl
+			g.genDocFile(42, []string{"https://foo.bar.com/auth", "https://zip.zap.com/auth"}, serv)
+			txtdiff.Diff(t, g.pt.String(), tst.want)
+			g.reset()
+		})
 	}
 }
 
@@ -146,10 +147,11 @@ func TestDocFileEmptyService(t *testing.T) {
 			want:   filepath.Join("testdata", "doc_file_deprecated_emptyservice.want"),
 		},
 	} {
-		g.opts.relLvl = tst.relLvl
-		g.genDocFile(43, []string{"https://foo.bar.com/auth", "https://zip.zap.com/auth"}, serv)
-		name := fmt.Sprintf("doc_file: %s", tst.want)
-		txtdiff.Diff(t, name, g.pt.String(), tst.want)
-		g.reset()
+		t.Run(tst.want, func(t *testing.T) {
+			g.opts.relLvl = tst.relLvl
+			g.genDocFile(43, []string{"https://foo.bar.com/auth", "https://zip.zap.com/auth"}, serv)
+			txtdiff.Diff(t, g.pt.String(), tst.want)
+			g.reset()
+		})
 	}
 }
diff --git a/internal/gengapic/example_test.go b/internal/gengapic/example_test.go
index 05a48c8..f3426d2 100644
--- a/internal/gengapic/example_test.go
+++ b/internal/gengapic/example_test.go
@@ -262,18 +262,20 @@ func TestExample(t *testing.T) {
 			op: &customOp{message: cop},
 		},
 	} {
-		g.reset()
-		g.opts = &tst.options
-		g.mixins = mix
-		if tst.options.diregapic {
-			g.mixins = nil
-		}
-		g.aux.customOp = tst.op
-		g.genExampleFile(serv)
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("TestExample(%s): imports got(-),want(+):\n%s", tst.tstName, diff)
-		}
-		txtdiff.Diff(t, tst.tstName, g.pt.String(), filepath.Join("testdata", tst.tstName+".want"))
+		t.Run(tst.tstName, func(t *testing.T) {
+			g.reset()
+			g.opts = &tst.options
+			g.mixins = mix
+			if tst.options.diregapic {
+				g.mixins = nil
+			}
+			g.aux.customOp = tst.op
+			g.genExampleFile(serv)
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("TestExample(%s): imports got(-),want(+):\n%s", tst.tstName, diff)
+			}
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", tst.tstName+".want"))
+		})
 	}
 }
 
@@ -342,20 +344,22 @@ func TestGenSnippetFile(t *testing.T) {
 			},
 		},
 	} {
-		g.reset()
-		g.opts = &tst.options
-		defaultHost := "bigquerymigration.googleapis.com"
-		g.snippetMetadata.AddService(serv.GetName(), defaultHost)
-		err := g.genSnippetFile(serv, serv.Method[0])
-		if err != nil {
-			t.Fatal(err)
-		}
-		g.commit(filepath.Join("cloud.google.com/go", "internal", "generated", "snippets", "bigquery", "main.go"), "main")
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("TestExample(%s): imports got(-),want(+):\n%s", tst.tstName, diff)
-		}
-		got := *g.resp.File[0].Content + *g.resp.File[1].Content
-		txtdiff.Diff(t, tst.tstName, got, filepath.Join("testdata", tst.tstName+".want"))
+		t.Run(tst.tstName, func(t *testing.T) {
+			g.reset()
+			g.opts = &tst.options
+			defaultHost := "bigquerymigration.googleapis.com"
+			g.snippetMetadata.AddService(serv.GetName(), defaultHost)
+			err := g.genSnippetFile(serv, serv.Method[0])
+			if err != nil {
+				t.Fatal(err)
+			}
+			g.commit(filepath.Join("cloud.google.com/go", "internal", "generated", "snippets", "bigquery", "main.go"), "main")
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("TestExample(%s): imports got(-),want(+):\n%s", tst.tstName, diff)
+			}
+			got := *g.resp.File[0].Content + *g.resp.File[1].Content
+			txtdiff.Diff(t, got, filepath.Join("testdata", tst.tstName+".want"))
+		})
 	}
 }
 
diff --git a/internal/gengapic/gengapic_test.go b/internal/gengapic/gengapic_test.go
index 8d8b661..20e199a 100644
--- a/internal/gengapic/gengapic_test.go
+++ b/internal/gengapic/gengapic_test.go
@@ -357,7 +357,6 @@ func TestGenGRPCMethods(t *testing.T) {
 	n := fmt.Sprintf(".my.pkg.%s.%s", inputType.GetName(), nestedEnum.GetName())
 	g.descInfo.Type[n] = nestedEnum
 
-methods:
 	for _, tst := range []struct {
 		m       *descriptor.MethodDescriptorProto
 		imports map[pbinfo.ImportSpec]bool
@@ -488,43 +487,42 @@ methods:
 			},
 		},
 	} {
-		g.reset()
-		g.descInfo.ParentElement[tst.m] = serv
-		serv.Method = []*descriptor.MethodDescriptorProto{
-			tst.m,
-		}
-
-		g.aux = &auxTypes{
-			iters: map[string]*iterType{},
-		}
-		if err := g.genGRPCMethods(serv, "Foo"); err != nil {
-			t.Error(err)
-			continue
-		}
+		t.Run(tst.m.GetName(), func(t *testing.T) {
+			g.reset()
+			g.descInfo.ParentElement[tst.m] = serv
+			serv.Method = []*descriptor.MethodDescriptorProto{
+				tst.m,
+			}
 
-		var lros []*descriptor.MethodDescriptorProto
-		for m := range g.aux.lros {
-			lros = append(lros, m)
-		}
-		sort.Slice(lros, func(i, j int) bool {
-			return lros[i].GetName() < lros[j].GetName()
-		})
-		for _, m := range lros {
-			if err := g.lroType("MyService", serv, m); err != nil {
-				t.Error(err)
-				continue methods
+			g.aux = &auxTypes{
+				iters: map[string]*iterType{},
+			}
+			if err := g.genGRPCMethods(serv, "Foo"); err != nil {
+				t.Fatal(err)
 			}
-		}
 
-		for _, iter := range g.aux.iters {
-			g.pagingIter(iter)
-		}
+			var lros []*descriptor.MethodDescriptorProto
+			for m := range g.aux.lros {
+				lros = append(lros, m)
+			}
+			sort.Slice(lros, func(i, j int) bool {
+				return lros[i].GetName() < lros[j].GetName()
+			})
+			for _, m := range lros {
+				if err := g.lroType("MyService", serv, m); err != nil {
+					t.Fatal(err)
+				}
+			}
 
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("TestGenMethod(%s): imports got(-),want(+):\n%s", tst.m.GetName(), diff)
-		}
+			for _, iter := range g.aux.iters {
+				g.pagingIter(iter)
+			}
 
-		txtdiff.Diff(t, tst.m.GetName(), g.pt.String(), filepath.Join("testdata", "method_"+tst.m.GetName()+".want"))
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("TestGenMethod(%s): imports got(-),want(+):\n%s", tst.m.GetName(), diff)
+			}
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", "method_"+tst.m.GetName()+".want"))
+		})
 	}
 }
 
@@ -721,7 +719,7 @@ func TestGenLRO(t *testing.T) {
 	respLROOpts := &descriptor.MethodOptions{}
 	proto.SetExtension(respLROOpts, longrunning.E_OperationInfo, respLRO)
 
-	lros := []*descriptor.MethodDescriptorProto{
+	for _, m := range []*descriptor.MethodDescriptorProto{
 		{
 			Name:       proto.String("EmptyLRO"),
 			InputType:  proto.String(".my.pkg.InputType"),
@@ -734,37 +732,34 @@ func TestGenLRO(t *testing.T) {
 			OutputType: proto.String(".google.longrunning.Operation"),
 			Options:    respLROOpts,
 		},
-	}
-
-lros:
-	for _, m := range lros {
-		g.pt.Reset()
-		g.descInfo.ParentElement[m] = serv
+	} {
+		t.Run(m.GetName(), func(t *testing.T) {
+			g.pt.Reset()
+			g.descInfo.ParentElement[m] = serv
 
-		g.aux = &auxTypes{
-			lros: map[*descriptor.MethodDescriptorProto]bool{},
-		}
+			g.aux = &auxTypes{
+				lros: map[*descriptor.MethodDescriptorProto]bool{},
+			}
 
-		if err := g.genGRPCMethod("Foo", serv, m); err != nil {
-			t.Error(err)
-			continue
-		}
+			if err := g.genGRPCMethod("Foo", serv, m); err != nil {
+				t.Fatal(err)
+			}
 
-		var genLros []*descriptor.MethodDescriptorProto
-		for m := range g.aux.lros {
-			genLros = append(genLros, m)
-		}
-		sort.Slice(genLros, func(i, j int) bool {
-			return genLros[i].GetName() < genLros[j].GetName()
-		})
-		for _, m := range genLros {
-			if err := g.lroType("MyService", serv, m); err != nil {
-				t.Error(err)
-				continue lros
+			var genLros []*descriptor.MethodDescriptorProto
+			for m := range g.aux.lros {
+				genLros = append(genLros, m)
+			}
+			sort.Slice(genLros, func(i, j int) bool {
+				return genLros[i].GetName() < genLros[j].GetName()
+			})
+			for _, m := range genLros {
+				if err := g.lroType("MyService", serv, m); err != nil {
+					t.Fatal(err)
+				}
 			}
-		}
 
-		txtdiff.Diff(t, m.GetName(), g.pt.String(), filepath.Join("testdata", "method_"+m.GetName()+".want"))
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", "method_"+m.GetName()+".want"))
+		})
 	}
 }
 
diff --git a/internal/gengapic/genrest_test.go b/internal/gengapic/genrest_test.go
index f21dd2c..c0733b1 100644
--- a/internal/gengapic/genrest_test.go
+++ b/internal/gengapic/genrest_test.go
@@ -877,45 +877,47 @@ func TestGenRestMethod(t *testing.T) {
 			},
 		},
 	} {
-		s.Method = []*descriptor.MethodDescriptorProto{tst.method}
-		g.opts = tst.options
-		g.imports = make(map[pbinfo.ImportSpec]bool)
-		g.serviceConfig = &serviceconfig.Service{
-			Http: &annotations.Http{
-				Rules: []*annotations.HttpRule{
-					{
-						Selector: "google.longrunning.Operations.GetOperation",
-						Pattern: &annotations.HttpRule_Get{
-							Get: "/v1beta1/{name=projects/*/locations/*/operations/*}",
+		t.Run(fmt.Sprintf("%s_%s", t.Name(), tst.name), func(t *testing.T) {
+			s.Method = []*descriptor.MethodDescriptorProto{tst.method}
+			g.opts = tst.options
+			g.imports = make(map[pbinfo.ImportSpec]bool)
+			g.serviceConfig = &serviceconfig.Service{
+				Http: &annotations.Http{
+					Rules: []*annotations.HttpRule{
+						{
+							Selector: "google.longrunning.Operations.GetOperation",
+							Pattern: &annotations.HttpRule_Get{
+								Get: "/v1beta1/{name=projects/*/locations/*/operations/*}",
+							},
 						},
 					},
 				},
-			},
-		}
+			}
 
-		if err := g.genRESTMethod("Foo", s, tst.method); err != nil {
-			t.Fatal(err)
-		}
+			if err := g.genRESTMethod("Foo", s, tst.method); err != nil {
+				t.Fatal(err)
+			}
 
-		var genLros []*descriptor.MethodDescriptorProto
-		for m := range g.aux.lros {
-			genLros = append(genLros, m)
-		}
-		sort.Slice(genLros, func(i, j int) bool {
-			return genLros[i].GetName() < genLros[j].GetName()
-		})
-		for _, m := range genLros {
-			if err := g.lroType("Foo", s, m); err != nil {
-				t.Error(err)
+			var genLros []*descriptor.MethodDescriptorProto
+			for m := range g.aux.lros {
+				genLros = append(genLros, m)
+			}
+			sort.Slice(genLros, func(i, j int) bool {
+				return genLros[i].GetName() < genLros[j].GetName()
+			})
+			for _, m := range genLros {
+				if err := g.lroType("Foo", s, m); err != nil {
+					t.Error(err)
+				}
 			}
-		}
 
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("TestGenRESTMethod(%s): imports got(-),want(+):\n%s", tst.name, diff)
-		}
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("TestGenRESTMethod(%s): imports got(-),want(+):\n%s", tst.name, diff)
+			}
 
-		txtdiff.Diff(t, fmt.Sprintf("%s_%s", t.Name(), tst.name), g.pt.String(), filepath.Join("testdata", fmt.Sprintf("rest_%s.want", tst.method.GetName())))
-		g.reset()
-		g.aux.lros = make(map[*descriptor.MethodDescriptorProto]bool)
+			txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", fmt.Sprintf("rest_%s.want", tst.method.GetName())))
+			g.reset()
+			g.aux.lros = make(map[*descriptor.MethodDescriptorProto]bool)
+		})
 	}
 }
diff --git a/internal/gengapic/metadata_test.go b/internal/gengapic/metadata_test.go
index d74f732..2756b57 100644
--- a/internal/gengapic/metadata_test.go
+++ b/internal/gengapic/metadata_test.go
@@ -228,5 +228,5 @@ func TestGenGapicMetadataFile_standardized(t *testing.T) {
 	if err := g.genGapicMetadataFile(); err != nil {
 		t.Fatalf("got genGapicMetadataFile() = %v, want nil", err)
 	}
-	txtdiff.Diff(t, "genGapicMetadataFile", g.pt.String(), "testdata/metadata.want")
+	txtdiff.Diff(t, g.pt.String(), "testdata/metadata.want")
 }
diff --git a/internal/gengapic/snippets_test.go b/internal/gengapic/snippets_test.go
index d39009d..937e842 100644
--- a/internal/gengapic/snippets_test.go
+++ b/internal/gengapic/snippets_test.go
@@ -212,29 +212,30 @@ func TestGenAndCommitSnippets(t *testing.T) {
 			},
 		},
 	} {
-		g.reset()
-		g.descInfo.ParentElement[tst.m] = serv
-		serv.Method = []*descriptor.MethodDescriptorProto{
-			tst.m,
-		}
-		g.aux = &auxTypes{
-			iters: map[string]*iterType{},
-		}
+		t.Run(tst.m.GetName(), func(t *testing.T) {
+			g.reset()
+			g.descInfo.ParentElement[tst.m] = serv
+			serv.Method = []*descriptor.MethodDescriptorProto{
+				tst.m,
+			}
+			g.aux = &auxTypes{
+				iters: map[string]*iterType{},
+			}
 
-		if err := g.genAndCommitSnippets(serv); err != nil {
-			t.Error(err)
-			continue
-		}
+			if err := g.genAndCommitSnippets(serv); err != nil {
+				t.Fatal(err)
+			}
 
-		if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
-			t.Errorf("TestGenAndCommitSnippets(%s): imports got(-),want(+):\n%s", tst.m.GetName(), diff)
-		}
-		if !tst.wantNil {
-			wantRegionTag := fmt.Sprintf("// [START _pkg_generated_Foo_%s_sync]\n", tst.m.GetName())
-			if g.headerComments.String() != wantRegionTag {
-				t.Errorf("TestGenAndCommitSnippets(%s): got %s, want %s", tst.m.GetName(), g.headerComments.String(), wantRegionTag)
+			if diff := cmp.Diff(g.imports, tst.imports); diff != "" {
+				t.Errorf("TestGenAndCommitSnippets(%s): imports got(-),want(+):\n%s", tst.m.GetName(), diff)
 			}
-			txtdiff.Diff(t, tst.m.GetName(), g.pt.String(), filepath.Join("testdata", "snippet_"+tst.m.GetName()+".want"))
-		}
+			if !tst.wantNil {
+				wantRegionTag := fmt.Sprintf("// [START _pkg_generated_Foo_%s_sync]\n", tst.m.GetName())
+				if g.headerComments.String() != wantRegionTag {
+					t.Errorf("TestGenAndCommitSnippets(%s): got %s, want %s", tst.m.GetName(), g.headerComments.String(), wantRegionTag)
+				}
+				txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", "snippet_"+tst.m.GetName()+".want"))
+			}
+		})
 	}
 }