@@ -20,6 +20,7 @@ import (
2020 "strings"
2121 "testing"
2222
23+ "github.com/google/go-cmp/cmp"
2324 "github.com/googleapis/librarian/internal/config"
2425)
2526
@@ -113,3 +114,87 @@ func TestGenerateClientVersionFile(t *testing.T) {
113114 })
114115 }
115116}
117+
118+ func TestResolveClientPath (t * testing.T ) {
119+ for _ , test := range []struct {
120+ name string
121+ library * config.Library
122+ apiPath string
123+ wantVersionPath string
124+ wantClientDir string
125+ }{
126+ {
127+ name : "from apiPath" ,
128+ library : & config.Library {
129+ Name : "secretmanager" ,
130+ APIs : []* config.API {
131+ {
132+ Path : "google/cloud/secretmanager/v1" ,
133+ },
134+ {
135+ Path : "google/cloud/secretmanager/v1beta1" ,
136+ },
137+ },
138+ },
139+ apiPath : "google/cloud/secretmanager/v1" ,
140+ wantVersionPath : "secretmanager/apiv1" ,
141+ wantClientDir : "" ,
142+ },
143+ {
144+ name : "non existing GoAPI" ,
145+ library : & config.Library {
146+ Name : "secretmanager" ,
147+ APIs : []* config.API {
148+ {
149+ Path : "google/cloud/secretmanager/v1" ,
150+ },
151+ },
152+ Go : & config.GoModule {
153+ GoAPIs : []* config.GoAPI {
154+ {
155+ Path : "google/cloud/secretmanager/v1beta1" ,
156+ },
157+ },
158+ },
159+ },
160+ apiPath : "google/cloud/secretmanager/v1" ,
161+ wantVersionPath : "secretmanager/apiv1" ,
162+ wantClientDir : "" ,
163+ },
164+ {
165+ name : "from apiPath and client directory" ,
166+ library : & config.Library {
167+ Name : "ai" ,
168+ APIs : []* config.API {
169+ {
170+ Path : "google/cloud/ai/v1" ,
171+ },
172+ },
173+ Go : & config.GoModule {
174+ GoAPIs : []* config.GoAPI {
175+ {
176+ Path : "google/cloud/ai/v1" ,
177+ ClientDirectory : "customdir" ,
178+ },
179+ {
180+ Path : "google/cloud/ai/v1beta1" ,
181+ },
182+ },
183+ },
184+ },
185+ apiPath : "google/cloud/ai/v1" ,
186+ wantVersionPath : "ai/customdir/apiv1" ,
187+ wantClientDir : "customdir" ,
188+ },
189+ } {
190+ t .Run (test .name , func (t * testing.T ) {
191+ gotVersionPath , gotClientDir := resolveClientPath (test .library , test .apiPath )
192+ if diff := cmp .Diff (test .wantVersionPath , gotVersionPath ); diff != "" {
193+ t .Errorf ("mismatch (-want +got):\n %s" , diff )
194+ }
195+ if diff := cmp .Diff (test .wantClientDir , gotClientDir ); diff != "" {
196+ t .Errorf ("mismatch (-want +got):\n %s" , diff )
197+ }
198+ })
199+ }
200+ }
0 commit comments