Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 32 additions & 60 deletions internal/gengapic/doc_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,37 @@ import (
"testing"

"github.com/googleapis/gapic-generator-go/internal/pbinfo"
"github.com/googleapis/gapic-generator-go/internal/testing/sample"
"github.com/googleapis/gapic-generator-go/internal/txtdiff"
"google.golang.org/genproto/googleapis/api/serviceconfig"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"
)

func TestDocFile(t *testing.T) {
var g generator
g.apiName = "Awesome Foo API"
g.serviceConfig = &serviceconfig.Service{
Documentation: &serviceconfig.Documentation{
Summary: "The Awesome Foo API is really really awesome. It enables the use of [Foo](https://api.foo.com) with [Buz](https://api.buz.com) and [Baz](https://api.baz.com) to acclerate `bar`.",
g := generator{
apiName: sample.ServiceTitle,
serviceConfig: sample.ServiceConfig(),
imports: map[pbinfo.ImportSpec]bool{},
opts: &options{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
},
}
g.opts = &options{pkgPath: "path/to/awesome", pkgName: "awesome", transports: []transport{grpc, rest}}
g.imports = map[pbinfo.ImportSpec]bool{}

inputType := &descriptorpb.DescriptorProto{
Name: proto.String("InputType"),
}
outputType := &descriptorpb.DescriptorProto{
Name: proto.String("OutputType"),
}

file := &descriptorpb.FileDescriptorProto{
Options: &descriptorpb.FileOptions{
GoPackage: proto.String("mypackage"),
},
}
inputType := sample.InputType(sample.CreateRequest)
outputType := sample.OutputType(sample.Resource)
file := sample.File()

commonTypes(&g)
for _, typ := range []*descriptorpb.DescriptorProto{
inputType, outputType,
} {
g.descInfo.Type[".my.pkg."+typ.GetName()] = typ
typName := sample.DescriptorInfoTypeName(typ.GetName())
g.descInfo.Type[typName] = typ
g.descInfo.ParentFile[typ] = file
}

serv := &descriptorpb.ServiceDescriptorProto{
Name: proto.String("Foo"),
Method: []*descriptorpb.MethodDescriptorProto{
{
Name: proto.String("GetOneThing"),
InputType: proto.String(".my.pkg.InputType"),
OutputType: proto.String(".my.pkg.OutputType"),
},
},
}

serv := sample.Service()
for _, tst := range []struct {
relLvl, want string
}{
Expand All @@ -85,49 +67,39 @@ func TestDocFile(t *testing.T) {
} {
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)
g.genDocFile(sample.Year, []string{sample.ServiceOAuthScope}, serv)
txtdiff.Diff(t, g.pt.String(), tst.want)
g.reset()
})
}
}

func TestDocFileEmptyService(t *testing.T) {
var g generator
g.apiName = "Awesome Bar API"
g.serviceConfig = &serviceconfig.Service{
Documentation: &serviceconfig.Documentation{
Summary: "The Awesome Bar API is really really awesome. It enables the use of [Foo](https://api.foo.com) with [Buz](https://api.buz.com) and [Baz](https://api.baz.com) to acclerate `bar`.",
},
}
g.opts = &options{pkgPath: "path/to/awesome", pkgName: "awesome", transports: []transport{grpc}}
g.imports = map[pbinfo.ImportSpec]bool{}

inputType := &descriptorpb.DescriptorProto{
Name: proto.String("InputType"),
}
outputType := &descriptorpb.DescriptorProto{
Name: proto.String("OutputType"),
}

file := &descriptorpb.FileDescriptorProto{
Options: &descriptorpb.FileOptions{
GoPackage: proto.String("mypackage"),
g := generator{
apiName: sample.ServiceTitle,
imports: map[pbinfo.ImportSpec]bool{},
serviceConfig: sample.ServiceConfig(),
opts: &options{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
},
}
inputType := sample.InputType(sample.CreateRequest)
outputType := sample.OutputType(sample.Resource)
file := sample.File()

commonTypes(&g)
for _, typ := range []*descriptorpb.DescriptorProto{
inputType, outputType,
} {
g.descInfo.Type[".my.pkg."+typ.GetName()] = typ
typName := sample.DescriptorInfoTypeName(typ.GetName())
g.descInfo.Type[typName] = typ
g.descInfo.ParentFile[typ] = file
}

serv := &descriptorpb.ServiceDescriptorProto{
Name: proto.String("Foo"),
}

serv := sample.Service()
serv.Method = nil
for _, tst := range []struct {
relLvl, want string
}{
Expand All @@ -149,7 +121,7 @@ func TestDocFileEmptyService(t *testing.T) {
} {
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)
g.genDocFile(sample.Year, []string{sample.ServiceOAuthScope}, serv)
txtdiff.Diff(t, g.pt.String(), tst.want)
g.reset()
})
Expand Down
8 changes: 2 additions & 6 deletions internal/gengapic/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ func TestExample(t *testing.T) {
},
}

inputType := &descriptorpb.DescriptorProto{
Name: proto.String("InputType"),
}
outputType := &descriptorpb.DescriptorProto{
Name: proto.String("OutputType"),
}
inputType := sample.InputType("InputType")
outputType := sample.OutputType("OutputType")

pageInputType := &descriptorpb.DescriptorProto{
Name: proto.String("PageInputType"),
Expand Down
28 changes: 13 additions & 15 deletions internal/gengapic/testdata/doc_file.want
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 42 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,11 @@

// Code generated by protoc-gen-go_gapic. DO NOT EDIT.

// Package awesome is an auto-generated package for the
// Awesome Foo API.
// Package migration is an auto-generated package for the
// BigQuery Migration API.
//
// The Awesome Foo API is really really awesome. It enables the use of Foo
// (at https://api.foo.com) with Buz (at https://api.buz.com) and Baz (at
// https://api.baz.com) to acclerate bar.
// The migration service, exposing apis for migration jobs operations, and
// agent management.
//
// General documentation
//
Expand All @@ -42,7 +41,7 @@
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// c, err := migration.NewClient(ctx)
// if err != nil {
// // TODO: Handle error.
// }
Expand All @@ -62,17 +61,17 @@
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// c, err := migration.NewClient(ctx)
// if err != nil {
// // TODO: Handle error.
// }
// defer c.Close()
//
// req := &mypackagepb.InputType{
// req := &migrationpb.CreateMigrationWorkflowRequest{
// // TODO: Fill request struct fields.
// // See https://pkg.go.dev/mypackage#InputType.
// // See https://pkg.go.dev/cloud.google.com/go/bigquery/migration/apiv2/migrationpb#CreateMigrationWorkflowRequest.
// }
// resp, err := c.GetOneThing(ctx, req)
// resp, err := c.CreateMigrationWorkflow(ctx, req)
// if err != nil {
// // TODO: Handle error.
// }
Expand All @@ -81,7 +80,7 @@
//
// Use of Context
//
// The ctx passed to NewFooClient is used for authentication requests and
// The ctx passed to NewClient 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.
//
Expand All @@ -92,7 +91,7 @@
// [Testing against Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Testing
// [Debugging Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Debugging
// [Inspecting errors]: https://pkg.go.dev/cloud.google.com/go#hdr-Inspecting_errors
package awesome // import "path/to/awesome"
package migration // import "cloud.google.com/go/bigquery/migration/apiv2"

import (
"context"
Expand All @@ -117,7 +116,6 @@ func getVersionClient() string {
// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
func DefaultAuthScopes() []string {
return []string{
"https://foo.bar.com/auth",
"https://zip.zap.com/auth",
"https://www.googleapis.com/auth/cloud-platform",
}
}
28 changes: 13 additions & 15 deletions internal/gengapic/testdata/doc_file_alpha.want
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 42 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,11 @@

// Code generated by protoc-gen-go_gapic. DO NOT EDIT.

// Package awesome is an auto-generated package for the
// Awesome Foo API.
// Package migration is an auto-generated package for the
// BigQuery Migration API.
//
// The Awesome Foo API is really really awesome. It enables the use of Foo
// (at https://api.foo.com) with Buz (at https://api.buz.com) and Baz (at
// https://api.baz.com) to acclerate bar.
// The migration service, exposing apis for migration jobs operations, and
// agent management.
//
// NOTE: This package is in alpha. It is not stable, and is likely to change.
//
Expand All @@ -44,7 +43,7 @@
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// c, err := migration.NewClient(ctx)
// if err != nil {
// // TODO: Handle error.
// }
Expand All @@ -64,17 +63,17 @@
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// c, err := migration.NewClient(ctx)
// if err != nil {
// // TODO: Handle error.
// }
// defer c.Close()
//
// req := &mypackagepb.InputType{
// req := &migrationpb.CreateMigrationWorkflowRequest{
// // TODO: Fill request struct fields.
// // See https://pkg.go.dev/mypackage#InputType.
// // See https://pkg.go.dev/cloud.google.com/go/bigquery/migration/apiv2/migrationpb#CreateMigrationWorkflowRequest.
// }
// resp, err := c.GetOneThing(ctx, req)
// resp, err := c.CreateMigrationWorkflow(ctx, req)
// if err != nil {
// // TODO: Handle error.
// }
Expand All @@ -83,7 +82,7 @@
//
// Use of Context
//
// The ctx passed to NewFooClient is used for authentication requests and
// The ctx passed to NewClient 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.
//
Expand All @@ -94,7 +93,7 @@
// [Testing against Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Testing
// [Debugging Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Debugging
// [Inspecting errors]: https://pkg.go.dev/cloud.google.com/go#hdr-Inspecting_errors
package awesome // import "path/to/awesome"
package migration // import "cloud.google.com/go/bigquery/migration/apiv2"

import (
"context"
Expand All @@ -119,7 +118,6 @@ func getVersionClient() string {
// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
func DefaultAuthScopes() []string {
return []string{
"https://foo.bar.com/auth",
"https://zip.zap.com/auth",
"https://www.googleapis.com/auth/cloud-platform",
}
}
20 changes: 9 additions & 11 deletions internal/gengapic/testdata/doc_file_alpha_emptyservice.want
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 43 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,11 @@

// Code generated by protoc-gen-go_gapic. DO NOT EDIT.

// Package awesome is an auto-generated package for the
// Awesome Bar API.
// Package migration is an auto-generated package for the
// BigQuery Migration API.
//
// The Awesome Bar API is really really awesome. It enables the use of Foo
// (at https://api.foo.com) with Buz (at https://api.buz.com) and Baz (at
// https://api.baz.com) to acclerate bar.
// The migration service, exposing apis for migration jobs operations, and
// agent management.
//
// NOTE: This package is in alpha. It is not stable, and is likely to change.
//
Expand All @@ -44,7 +43,7 @@
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// c, err := migration.NewClient(ctx)
// if err != nil {
// // TODO: Handle error.
// }
Expand All @@ -56,7 +55,7 @@
//
// Use of Context
//
// The ctx passed to NewFooClient is used for authentication requests and
// The ctx passed to NewClient 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.
//
Expand All @@ -67,7 +66,7 @@
// [Testing against Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Testing
// [Debugging Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Debugging
// [Inspecting errors]: https://pkg.go.dev/cloud.google.com/go#hdr-Inspecting_errors
package awesome // import "path/to/awesome"
package migration // import "cloud.google.com/go/bigquery/migration/apiv2"

import (
"context"
Expand All @@ -92,7 +91,6 @@ func getVersionClient() string {
// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
func DefaultAuthScopes() []string {
return []string{
"https://foo.bar.com/auth",
"https://zip.zap.com/auth",
"https://www.googleapis.com/auth/cloud-platform",
}
}
Loading