Skip to content

Commit 083b15a

Browse files
authored
impl(sidekick): add methods to state (#2280)
1 parent cefad37 commit 083b15a

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

internal/sidekick/internal/parser/discovery/methods.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func makeMethod(model *api.API, serviceID string, doc *document, input *method)
8181
BodyFieldPath: "*",
8282
},
8383
}
84+
model.State.MethodByID[id] = method
8485
return method, nil
8586
}
8687

internal/sidekick/internal/parser/discovery/methods_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,51 @@
1414

1515
package discovery
1616

17-
import "testing"
17+
import (
18+
"testing"
19+
20+
"github.com/google/go-cmp/cmp"
21+
"github.com/googleapis/librarian/internal/sidekick/internal/api"
22+
)
23+
24+
func TestMakeServiceMethods(t *testing.T) {
25+
model, err := ComputeDisco(t, nil)
26+
if err != nil {
27+
t.Fatal(err)
28+
}
29+
30+
id := "..zones.get"
31+
got, ok := model.State.MethodByID[id]
32+
if !ok {
33+
t.Fatalf("expected method %s in the API model", id)
34+
}
35+
want := &api.Method{
36+
ID: "..zones.get",
37+
Name: "get",
38+
Documentation: "Returns the specified Zone resource.",
39+
InputTypeID: ".google.protobuf.Empty",
40+
OutputTypeID: "..Zone",
41+
PathInfo: &api.PathInfo{
42+
Bindings: []*api.PathBinding{
43+
{
44+
Verb: "GET",
45+
PathTemplate: api.NewPathTemplate().
46+
WithLiteral("compute").
47+
WithLiteral("v1").
48+
WithLiteral("projects").
49+
WithVariableNamed("project").
50+
WithLiteral("zones").
51+
WithVariableNamed("zone"),
52+
QueryParameters: map[string]bool{},
53+
},
54+
},
55+
BodyFieldPath: "*",
56+
},
57+
}
58+
if diff := cmp.Diff(want, got); diff != "" {
59+
t.Errorf("mismatch (-want, +got):\n%s", diff)
60+
}
61+
}
1862

1963
func TestMakeServiceMethodsError(t *testing.T) {
2064
model, err := ComputeDisco(t, nil)

0 commit comments

Comments
 (0)