From 852bc344189e05a403117d340e0d347daacb6a94 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 4 Aug 2022 14:37:44 -0600 Subject: [PATCH] fix(gengapic): fix service-specific constructor name in doc_file.go closes: #1077 --- internal/gengapic/doc_file.go | 7 ++++--- internal/gengapic/doc_file_test.go | 4 +++- internal/gengapic/testdata/doc_file.want | 2 +- internal/gengapic/testdata/doc_file_alpha.want | 2 +- .../gengapic/testdata/doc_file_alpha_emptyservice.want | 2 +- internal/gengapic/testdata/doc_file_beta.want | 2 +- internal/gengapic/testdata/doc_file_beta_emptyservice.want | 2 +- internal/gengapic/testdata/doc_file_emptyservice.want | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/gengapic/doc_file.go b/internal/gengapic/doc_file.go index 179ac2056..136965cc6 100644 --- a/internal/gengapic/doc_file.go +++ b/internal/gengapic/doc_file.go @@ -70,9 +70,10 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi p("//") p("// To get started with this package, create a client.") // Code block for client creation + servName := pbinfo.ReduceServName(serv.GetName(), g.opts.pkgName) tmpClient := g.pt g.pt = printer.P{} - g.exampleInitClient(g.opts.pkgName, pbinfo.ReduceServName(serv.GetName(), g.opts.pkgName)) + g.exampleInitClient(g.opts.pkgName, servName) snipClient := g.pt.String() g.pt = tmpClient g.codesnippet(snipClient) @@ -89,7 +90,7 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi // Code block for client using the first method of the service tmpMethod := g.pt g.pt = printer.P{} - g.exampleMethodBody(g.opts.pkgName, pbinfo.ReduceServName(serv.GetName(), g.opts.pkgName), serv.GetMethod()[0]) + g.exampleMethodBody(g.opts.pkgName, servName, serv.GetMethod()[0]) snipMethod := g.pt.String() g.pt = tmpMethod g.codesnippet(snipMethod) @@ -97,7 +98,7 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi p("// Use of Context") p("//") - p("// The ctx passed to NewClient is used for authentication requests and") + p("// The ctx passed to New%sClient is used for authentication requests and", servName) p("// for creating the underlying connection, but is not used for subsequent calls.") p("// Individual methods on the client use the ctx given to them.") p("//") diff --git a/internal/gengapic/doc_file_test.go b/internal/gengapic/doc_file_test.go index 7ad3c7c16..54e6c72fc 100644 --- a/internal/gengapic/doc_file_test.go +++ b/internal/gengapic/doc_file_test.go @@ -15,6 +15,7 @@ package gengapic import ( + "fmt" "path/filepath" "testing" @@ -143,7 +144,8 @@ func TestDocFileEmptyService(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, "doc_file", g.pt.String(), tst.want) + name := fmt.Sprintf("doc_file: %s", tst.want) + txtdiff.Diff(t, name, g.pt.String(), tst.want) g.reset() } } diff --git a/internal/gengapic/testdata/doc_file.want b/internal/gengapic/testdata/doc_file.want index 4911d05f8..bb14f0c5d 100644 --- a/internal/gengapic/testdata/doc_file.want +++ b/internal/gengapic/testdata/doc_file.want @@ -59,7 +59,7 @@ // // Use of Context // -// The ctx passed to NewClient is used for authentication requests and +// The ctx passed to NewFooClient is used for authentication requests and // for creating the underlying connection, but is not used for subsequent calls. // Individual methods on the client use the ctx given to them. // diff --git a/internal/gengapic/testdata/doc_file_alpha.want b/internal/gengapic/testdata/doc_file_alpha.want index ba3abe6ad..f523c280e 100644 --- a/internal/gengapic/testdata/doc_file_alpha.want +++ b/internal/gengapic/testdata/doc_file_alpha.want @@ -61,7 +61,7 @@ // // Use of Context // -// The ctx passed to NewClient is used for authentication requests and +// The ctx passed to NewFooClient is used for authentication requests and // for creating the underlying connection, but is not used for subsequent calls. // Individual methods on the client use the ctx given to them. // diff --git a/internal/gengapic/testdata/doc_file_alpha_emptyservice.want b/internal/gengapic/testdata/doc_file_alpha_emptyservice.want index 42c53ba8f..a769dd6eb 100644 --- a/internal/gengapic/testdata/doc_file_alpha_emptyservice.want +++ b/internal/gengapic/testdata/doc_file_alpha_emptyservice.want @@ -39,7 +39,7 @@ // // Use of Context // -// The ctx passed to NewClient is used for authentication requests and +// The ctx passed to NewFooClient is used for authentication requests and // for creating the underlying connection, but is not used for subsequent calls. // Individual methods on the client use the ctx given to them. // diff --git a/internal/gengapic/testdata/doc_file_beta.want b/internal/gengapic/testdata/doc_file_beta.want index 78dd79c43..82d4289c1 100644 --- a/internal/gengapic/testdata/doc_file_beta.want +++ b/internal/gengapic/testdata/doc_file_beta.want @@ -61,7 +61,7 @@ // // Use of Context // -// The ctx passed to NewClient is used for authentication requests and +// The ctx passed to NewFooClient is used for authentication requests and // for creating the underlying connection, but is not used for subsequent calls. // Individual methods on the client use the ctx given to them. // diff --git a/internal/gengapic/testdata/doc_file_beta_emptyservice.want b/internal/gengapic/testdata/doc_file_beta_emptyservice.want index 187c82408..b67939e81 100644 --- a/internal/gengapic/testdata/doc_file_beta_emptyservice.want +++ b/internal/gengapic/testdata/doc_file_beta_emptyservice.want @@ -39,7 +39,7 @@ // // Use of Context // -// The ctx passed to NewClient is used for authentication requests and +// The ctx passed to NewFooClient is used for authentication requests and // for creating the underlying connection, but is not used for subsequent calls. // Individual methods on the client use the ctx given to them. // diff --git a/internal/gengapic/testdata/doc_file_emptyservice.want b/internal/gengapic/testdata/doc_file_emptyservice.want index 6ec985216..013e9c36a 100644 --- a/internal/gengapic/testdata/doc_file_emptyservice.want +++ b/internal/gengapic/testdata/doc_file_emptyservice.want @@ -37,7 +37,7 @@ // // Use of Context // -// The ctx passed to NewClient is used for authentication requests and +// The ctx passed to NewFooClient is used for authentication requests and // for creating the underlying connection, but is not used for subsequent calls. // Individual methods on the client use the ctx given to them. //