Skip to content
Merged
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
2 changes: 1 addition & 1 deletion internal/sidekick/api/apitest/apitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func CheckMessage(t *testing.T, got *api.Message, want *api.Message) {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
// Ignore parent because types are cyclic
if diff := cmp.Diff(want.OneOfs, got.OneOfs, cmpopts.SortSlices(less)); diff != "" {
if diff := cmp.Diff(want.OneOfs, got.OneOfs, cmpopts.SortSlices(less), cmpopts.IgnoreFields(api.Field{}, "Parent")); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
}
Expand Down
31 changes: 12 additions & 19 deletions internal/sidekick/parser/disco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ func TestDisco_ParsePagination(t *testing.T) {
if got == nil {
t.Fatalf("expected method %s in the API model", wantID)
}
wantPagination := &api.Field{
Name: "pageToken",
JSONName: "pageToken",
ID: "..zones.listRequest.pageToken",
Typez: api.TypezString,
TypezID: "string",
Optional: true,
}
wantPagination := api.NewTestField("pageToken").
WithType(api.TypezString).
WithTypezID("string").
WithOptional()
wantPagination.ID = "..zones.listRequest.pageToken"
if diff := cmp.Diff(wantPagination, got.Pagination, cmpopts.IgnoreFields(api.Field{}, "Documentation")); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
Expand All @@ -143,14 +140,11 @@ func TestDisco_ParsePaginationAggregate(t *testing.T) {
if got == nil {
t.Fatalf("expected method %s in the API model", wantID)
}
wantPagination := &api.Field{
Name: "pageToken",
JSONName: "pageToken",
ID: "..machineTypes.aggregatedListRequest.pageToken",
Typez: api.TypezString,
TypezID: "string",
Optional: true,
}
wantPagination := api.NewTestField("pageToken").
WithType(api.TypezString).
WithTypezID("string").
WithOptional()
wantPagination.ID = "..machineTypes.aggregatedListRequest.pageToken"
if diff := cmp.Diff(wantPagination, got.Pagination, cmpopts.IgnoreFields(api.Field{}, "Documentation")); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
Expand All @@ -164,9 +158,8 @@ func TestDisco_ParseDeprecatedEnum(t *testing.T) {
if err != nil {
t.Fatal(err)
}
wantEnum := &api.Enum{
ID: "..AcceleratorTypeAggregatedList.warning.code",
}
wantEnum := api.NewTestEnum("code").
WithID("..AcceleratorTypeAggregatedList.warning.code")
got := model.Enum(wantEnum.ID)
if got == nil {
t.Fatalf("expected method %s in the API model", wantEnum.ID)
Expand Down
84 changes: 36 additions & 48 deletions internal/sidekick/parser/protobuf_api_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,41 @@ func TestProtobuf_ApiVersion(t *testing.T) {
if service == nil {
t.Fatalf("Cannot find service %s in API State", id)
}
want := &api.Service{
Name: "Service",
ID: ".test.Service",
Package: "test",
Documentation: "A service with an API version.",
DefaultHost: "test.googleapis.com",
Methods: []*api.Method{
{
Name: "Create",
ID: ".test.Service.Create",
SourceServiceID: ".test.Service",
Documentation: "A create method.",
InputTypeID: ".test.Request",
OutputTypeID: ".test.Response",
PathInfo: &api.PathInfo{
Bindings: []*api.PathBinding{
{
Verb: "POST",
PathTemplate: (&api.PathTemplate{}).
WithLiteral("v7").
WithLiteral("thing"),
QueryParameters: map[string]bool{"parent": true}},
},
},
APIVersion: "v7_20260206",
},
{
Name: "Make",
ID: ".test.Service.Make",
SourceServiceID: ".test.Service",
Documentation: "Another sort of method.",
InputTypeID: ".test.Request",
OutputTypeID: ".test.Response",
PathInfo: &api.PathInfo{
Bindings: []*api.PathBinding{
{
Verb: "POST",
PathTemplate: (&api.PathTemplate{}).
WithLiteral("v7").
WithLiteral("thing").
WithVerb("make"),
QueryParameters: map[string]bool{"parent": true}},
},
},
APIVersion: "v7_20260206",
},
},
}
createMethod := api.NewTestMethod("Create").
WithID(".test.Service.Create").
WithDocumentation("A create method.").
WithVerb("POST").
WithPathTemplate(
(&api.PathTemplate{}).
WithLiteral("v7").
WithLiteral("thing"),
).
WithQueryParameters(map[string]bool{"parent": true}).
WithAPIVersion("v7_20260206")
createMethod.SourceServiceID = ".test.Service"
createMethod.InputTypeID = ".test.Request"
createMethod.OutputTypeID = ".test.Response"

makeMethod := api.NewTestMethod("Make").
WithID(".test.Service.Make").
WithDocumentation("Another sort of method.").
WithVerb("POST").
WithPathTemplate(
(&api.PathTemplate{}).
WithLiteral("v7").
WithLiteral("thing").
WithVerb("make"),
).
WithQueryParameters(map[string]bool{"parent": true}).
WithAPIVersion("v7_20260206")
makeMethod.SourceServiceID = ".test.Service"
makeMethod.InputTypeID = ".test.Request"
makeMethod.OutputTypeID = ".test.Response"

want := api.NewTestService("Service").
WithPackage("test").
WithDocumentation("A service with an API version.").
WithDefaultHost("test.googleapis.com").
WithMethods(createMethod, makeMethod)
apitest.CheckService(t, service, want)
}
13 changes: 6 additions & 7 deletions internal/sidekick/parser/protobuf_file_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ func TestProtobuf_FileOptions(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := &api.API{
Name: "testdata",
Title: "A test-only API",
CsharpNamespace: "Google.Cloud.TestData.V1",
PhpNamespace: "Google\\Cloud\\TestData\\V1",
RubyPackage: "Google::Cloud::TestData::V1",
}
want := api.NewTestAPI(nil, nil, nil).
WithName("testdata").
WithTitle("A test-only API").
WithCsharpNamespace("Google.Cloud.TestData.V1").
WithPhpNamespace("Google\\Cloud\\TestData\\V1").
WithRubyPackage("Google::Cloud::TestData::V1")
if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(api.API{})); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
Expand Down
Loading
Loading