Skip to content
Closed
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
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ switched_rules_by_language(name = "com_google_googleapis_imports", go = True, gr

http_archive(
name = "io_bazel_rules_go",
sha256 = "af47f30e9cbd70ae34e49866e201b3f77069abb111183f2c0297e7e74ba6bbc0",
sha256 = "f74c98d6df55217a36859c74b460e774abc0410a47cc100d822be34d5f990f16",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.47.0/rules_go-v0.47.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.47.0/rules_go-v0.47.0.zip",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.47.1/rules_go-v0.47.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.47.1/rules_go-v0.47.1.zip",
],
)

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ require (
github.com/jhump/protoreflect v1.16.0
gitlab.com/golang-commonmark/markdown v0.0.0-20211110145824-bf3e522c626a
golang.org/x/text v0.15.0
google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6
google.golang.org/genproto v0.0.0-20240509183442-62759503f434
google.golang.org/genproto/googleapis/api v0.0.0-20240509183442-62759503f434
google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434
google.golang.org/protobuf v1.34.1
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 h1:MTmrc2F5TZKDKXigcZetYkH04YwqtOPEQJwh4PPOgfk=
google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6/go.mod h1:2ROWwqCIx97Y7CSyp11xB8fori0wzvD6+gbacaf5c8I=
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 h1:DTJM0R8LECCgFeUwApvcEJHz85HLagW8uRENYxHh1ww=
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6/go.mod h1:10yRODfgim2/T8csjQsMPgZOMvtytXKTDRzH6HRGzRw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/genproto v0.0.0-20240509183442-62759503f434 h1:+PQKEGakpJad0y8bF9UJlgg4dO2U5H+cydccJNjzkww=
google.golang.org/genproto v0.0.0-20240509183442-62759503f434/go.mod h1:i4np6Wrjp8EujFAUn0CM0SH+iZhY1EbrfzEIJbFkHFM=
google.golang.org/genproto/googleapis/api v0.0.0-20240509183442-62759503f434 h1:OpXbo8JnN8+jZGPrL4SSfaDjSCjupr8lXyBAbexEm/U=
google.golang.org/genproto/googleapis/api v0.0.0-20240509183442-62759503f434/go.mod h1:FfiGhwUm6CJviekPrc0oJ+7h29e+DmWU6UtjX0ZvI7Y=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434 h1:umK/Ey0QEzurTNlsV3R+MfxHAb78HCEX/IkuR+zH4WQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
Expand Down
1 change: 1 addition & 0 deletions internal/snippets/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_test(
embed = [":snippets"],
deps = [
"//internal/snippets/metadata",
"//internal/testing/sample",
"@com_github_google_go_cmp//cmp",
"@org_golang_google_protobuf//proto",
],
Expand Down
41 changes: 16 additions & 25 deletions internal/snippets/snippets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,37 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/googleapis/gapic-generator-go/internal/snippets/metadata"
"github.com/googleapis/gapic-generator-go/internal/testing/sample"
"google.golang.org/protobuf/proto"
)

var protoPkg = "google.cloud.bigquery.migration.v2"
var libPkg = "cloud.google.com/go/bigquery/migration/apiv2"
var defaultHost = "bigquerymigration.googleapis.com"
var version = "v2"
var pkgName = "migration"

func TestNewMetadata(t *testing.T) {
sm := NewMetadata(protoPkg, libPkg, pkgName)
sm := NewMetadata(sample.ProtoPackagePath, sample.GoPackagePath, sample.GoPackageName)

if sm.protoPkg != protoPkg {
t.Errorf("%s: got %s want %s,", t.Name(), sm.protoPkg, protoPkg)
if sm.protoPkg != sample.ProtoPackagePath {
t.Errorf("%s: got %s want %s,", t.Name(), sm.protoPkg, sample.ProtoPackagePath)
}
if sm.libPkg != libPkg {
t.Errorf("%s: got %s want %s", t.Name(), sm.libPkg, libPkg)
if sm.libPkg != sample.GoPackagePath {
t.Errorf("%s: got %s want %s", t.Name(), sm.libPkg, sample.GoPackagePath)
}
if got := len(sm.protoServices); got != 0 {
t.Errorf("%s: got %d want empty", t.Name(), len(sm.protoServices))
}
if sm.apiVersion != version {
t.Errorf("%s: got %s want %s", t.Name(), sm.apiVersion, version)
if sm.apiVersion != sample.ProtoVersion {
t.Errorf("%s: got %s want %s", t.Name(), sm.apiVersion, sample.ProtoVersion)
}
}

func TestToMetadataJSON(t *testing.T) {
// Build fixture
sm := NewMetadata(protoPkg, libPkg, pkgName)
sm := NewMetadata(sample.ProtoPackagePath, sample.GoPackagePath, sample.GoPackageName)
regionTagStart := 18
regionTagEnd := 50
for i := 0; i < 2; i++ {
serviceName := fmt.Sprintf("Foo%dService", i)
methodName := fmt.Sprintf("Bar%dMethod", i)
sm.AddService(serviceName, defaultHost)
sm.AddMethod(serviceName, methodName, protoPkg, serviceName, regionTagEnd)
sm.AddService(serviceName, sample.ServiceURL)
sm.AddMethod(serviceName, methodName, sample.ProtoPackagePath, serviceName, regionTagEnd)
sm.UpdateMethodDoc(serviceName, methodName, methodName+" doc\n New line.")
sm.UpdateMethodResult(serviceName, methodName, "mypackage."+methodName+"Result")
sm.AddParams(serviceName, methodName, "mypackage."+methodName+"Request")
Expand All @@ -63,12 +58,12 @@ func TestToMetadataJSON(t *testing.T) {
// Build expectation
want := &metadata.Index{
ClientLibrary: &metadata.ClientLibrary{
Name: libPkg,
Name: sample.GoPackagePath,
Version: VersionPlaceholder,
Language: metadata.Language_GO,
Apis: []*metadata.Api{
{
Id: protoPkg,
Id: sample.ProtoPackagePath,
Version: "v2",
},
},
Expand Down Expand Up @@ -142,15 +137,11 @@ func TestToMetadataJSON(t *testing.T) {
}

func TestRegionTag(t *testing.T) {
protoPkg := "google.cloud.bigquery.migration.v2"
libPkg := "google.golang.org/genproto/googleapis/cloud/bigquery/migration/v2"
sm := NewMetadata(protoPkg, libPkg, pkgName)
serviceName := "MigrationService"
defaultHost := "bigquerymigration.googleapis.com"
sm.AddService(serviceName, defaultHost)
methodName := "GetMigrationWorkflow"
sm := NewMetadata(sample.ProtoPackagePath, libPkg, sample.GoPackagePath)
sm.AddService(sample.ServiceName, sample.ServiceURL)
want := "bigquerymigration_v2_generated_MigrationService_GetMigrationWorkflow_sync"
if got := sm.RegionTag(serviceName, methodName); got != want {
if got := sm.RegionTag(sample.ServiceName, sample.GetMethod); got != want {
t.Errorf("%s: got %s want %s", t.Name(), got, want)
}
}
7 changes: 7 additions & 0 deletions internal/testing/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const (
// Example:
// https://github.com/googleapis/googleapis/blob/f7df662a24c56ecaab79cb7d808fed4d2bb4981d/google/cloud/bigquery/migration/v2/migration_service.proto#L17
ProtoPackagePath = "google.cloud.bigquery.migration.v2"

// ProtoVersion is the major version as defined in the protofile.
ProtoVersion = "v2"
)

const (
Expand Down Expand Up @@ -126,6 +129,10 @@ const (
// https://pkg.go.dev/cloud.google.com/go/bigquery/migration/apiv2/migrationpb.
// https://github.com/googleapis/googleapis/blob/f7df662a24c56ecaab79cb7d808fed4d2bb4981d/google/cloud/bigquery/migration/v2/migration_service.proto#L28
GoProtoPackagePath = "cloud.google.com/go/bigquery/migration/apiv2/migrationpb"

// GoVersion is the version used in the package path for versioning the Go
// module containing the package.
GoVersion = "apiv2"
)

// DescriptorInfoTypeName constructs the name format used by g.descInfo.Type.
Expand Down
Loading