1515package gcloud
1616
1717import (
18+ "fmt"
1819 "path"
1920 "slices"
20- "strings"
2121 "testing"
2222
2323 "github.com/google/go-cmp/cmp"
2424 "github.com/googleapis/librarian/internal/sidekick/api"
25+ "github.com/googleapis/librarian/internal/sidekick/parser/httprule"
2526 "github.com/googleapis/librarian/internal/surfer/gcloud/provider"
2627)
2728
@@ -43,9 +44,9 @@ func TestCommandTreeBuilder_Build_EmptyDefaultHost(t *testing.T) {
4344
4445func TestCommandTreeBuilder_Build_Structure (t * testing.T ) {
4546 service := mockService ("parallelstore.googleapis.com" ,
46- mockMethod ("CreateInstance" , "v1/projects/locations/instances" ),
47- mockMethod ("ListInstances" , "v1/projects/locations/instances" ),
48- mockMethod ("GetOperation" , "v1/projects/locations/operations" ),
47+ mockMethod ("CreateInstance" , "v1/{parent= projects/*/ locations/*} /instances" ),
48+ mockMethod ("ListInstances" , "v1/{parent= projects/*/ locations/*} /instances" ),
49+ mockMethod ("GetOperation" , "v1/{name= projects/*/ locations/*/ operations/*} " ),
4950 )
5051 model := & api.API {
5152 Name : "parallelstore" ,
@@ -81,7 +82,7 @@ func TestCommandTreeBuilder_Build_Structure(t *testing.T) {
8182}
8283
8384func TestCommandTreeBuilder_Build_Operations_Disabled (t * testing.T ) {
84- service := mockService ("parallelstore.googleapis.com" , mockMethod ("GetOperation" , "v1/projects/locations/operations" ))
85+ service := mockService ("parallelstore.googleapis.com" , mockMethod ("GetOperation" , "v1/{name= projects/*/ locations/*/ operations/*} " ))
8586
8687 model := & api.API {
8788 Name : "parallelstore" ,
@@ -101,7 +102,7 @@ func TestCommandTreeBuilder_Build_Operations_Disabled(t *testing.T) {
101102}
102103
103104func TestCommandTreeBuilder_Build_Operations_Enabled (t * testing.T ) {
104- service := mockService ("parallelstore.googleapis.com" , mockMethod ("GetOperation" , "v1/projects/locations/operations" ))
105+ service := mockService ("parallelstore.googleapis.com" , mockMethod ("GetOperation" , "v1/{name= projects/*/ locations/*/ operations/*} " ))
105106
106107 model := & api.API {
107108 Name : "parallelstore" ,
@@ -125,8 +126,8 @@ func TestCommandTreeBuilder_Build_Operations_Enabled(t *testing.T) {
125126}
126127
127128func TestCommandTreeBuilder_Build_MultipleServices (t * testing.T ) {
128- serviceOne := mockService ("ParallelstoreService" , mockMethod ("CreateInstance" , "v1/projects/locations/instances" ))
129- serviceTwo := mockService ("OtherParallelstoreService" , mockMethod ("CreateOtherInstance" , "v1/projects/locations/otherInstances" ))
129+ serviceOne := mockService ("ParallelstoreService" , mockMethod ("CreateInstance" , "v1/{parent= projects/*/ locations/*} /instances" ))
130+ serviceTwo := mockService ("OtherParallelstoreService" , mockMethod ("CreateOtherInstance" , "v1/{parent= projects/*/ locations/*} /otherInstances" ))
130131
131132 model := & api.API {
132133 Name : "parallelstore" ,
@@ -151,8 +152,8 @@ func TestCommandTreeBuilder_Build_MultipleServices(t *testing.T) {
151152}
152153
153154func TestCommandTreeBuilder_Build_MultipleReleaseTracks (t * testing.T ) {
154- serviceOne := mockService ("ParallelstoreService" , mockMethod ("CreateInstance" , "v1/projects/locations/instances" ))
155- serviceTwo := mockService ("ParallelstoreService" , mockMethod ("CreateInstance" , "v1alpha/projects/locations/instances" ))
155+ serviceOne := mockService ("ParallelstoreService" , mockMethod ("CreateInstance" , "v1/{parent= projects/*/ locations/*} /instances" ))
156+ serviceTwo := mockService ("ParallelstoreService" , mockMethod ("CreateInstance" , "v1alpha/{parent= projects/*/ locations/*} /instances" ))
156157 serviceTwo .Package = "google.cloud.parallelstore.v1alpha"
157158
158159 model := & api.API {
@@ -203,23 +204,17 @@ func flattenTree(g *CommandGroup) []string {
203204 return paths
204205}
205206
206- func parseLiteralPath (path string ) * api.PathTemplate {
207- pt := api .NewPathTemplate ()
208- for _ , part := range strings .Split (path , "/" ) {
209- if part != "" {
210- pt = pt .WithLiteral (part )
211- }
212- }
213- return pt
214- }
215-
216207func mockMethod (name , path string ) * api.Method {
208+ pt , err := httprule .ParseResourcePattern (path )
209+ if err != nil {
210+ panic (fmt .Sprintf ("failed to parse path %q: %v" , path , err ))
211+ }
217212 return & api.Method {
218213 Name : name ,
219214 PathInfo : & api.PathInfo {
220215 Bindings : []* api.PathBinding {
221216 {
222- PathTemplate : parseLiteralPath ( path ) ,
217+ PathTemplate : pt ,
223218 },
224219 },
225220 },
0 commit comments