@@ -39,6 +39,19 @@ func TestRepositoriesConfig_Validate(t *testing.T) {
3939 },
4040 wantErr : false ,
4141 },
42+ {
43+ name : "valid full name" ,
44+ config : & RepositoriesConfig {
45+ Repositories : []* RepositoryConfig {
46+ {
47+ FullName : "https://github.com/googleapis/google-cloud-foo" ,
48+ SecretName : "google-cloud-foo-github-token" ,
49+ SupportedCommands : []string {"generate" , "stage-release" , "publish-release" },
50+ },
51+ },
52+ },
53+ wantErr : false ,
54+ },
4255 {
4356 name : "missing name" ,
4457 config : & RepositoriesConfig {
@@ -136,6 +149,27 @@ func TestParseRepositoriesConfig(t *testing.T) {
136149 },
137150 },
138151 },
152+ {
153+ name : "valid state with full name" ,
154+ content : `repositories:
155+ - name: google-cloud-python
156+ full-name: https://github.com/some-org/google-cloud-python
157+ github-token-secret-name: google-cloud-python-github-token
158+ supported-commands:
159+ - generate
160+ - stage-release
161+ ` ,
162+ want : & RepositoriesConfig {
163+ Repositories : []* RepositoryConfig {
164+ {
165+ Name : "google-cloud-python" ,
166+ FullName : "https://github.com/some-org/google-cloud-python" ,
167+ SecretName : "google-cloud-python-github-token" ,
168+ SupportedCommands : []string {"generate" , "stage-release" },
169+ },
170+ },
171+ },
172+ },
139173 {
140174 name : "invalid yaml" ,
141175 content : `repositories:
@@ -225,3 +259,55 @@ func TestRepositoriesForCommand(t *testing.T) {
225259 })
226260 }
227261}
262+
263+ func TestRepositoryGitUrl (t * testing.T ) {
264+ for _ , test := range []struct {
265+ name string
266+ repository * RepositoryConfig
267+ want string
268+ wantError bool
269+ }{
270+ {
271+ name : "sets default organization" ,
272+ repository : & RepositoryConfig {
273+ Name : "google-cloud-python" ,
274+ },
275+ want : "https://github.com/googleapis/google-cloud-python" ,
276+ },
277+ {
278+ name : "reads full name" ,
279+ repository : & RepositoryConfig {
280+ FullName : "https://github.com/some-org/google-cloud-python" ,
281+ },
282+ want : "https://github.com/some-org/google-cloud-python" ,
283+ },
284+ {
285+ name : "prefers full name" ,
286+ repository : & RepositoryConfig {
287+ Name : "google-cloud-python" ,
288+ FullName : "https://github.com/some-org/google-cloud-python" ,
289+ },
290+ want : "https://github.com/some-org/google-cloud-python" ,
291+ },
292+ {
293+ name : "missing name" ,
294+ repository : & RepositoryConfig {
295+ Name : "google-cloud-python" ,
296+ FullName : "https://github.com/some-org/google-cloud-python" ,
297+ },
298+ want : "https://github.com/some-org/google-cloud-python" ,
299+ wantError : true ,
300+ },
301+ } {
302+ t .Run (test .name , func (t * testing.T ) {
303+ got , err := test .repository .GitURL ()
304+ if err != nil && test .wantError {
305+ t .Errorf ("expected to return error" )
306+ return
307+ }
308+ if diff := cmp .Diff (test .want , got ); diff != "" {
309+ t .Errorf ("parseRepositoriesConfig() mismatch (-want +got): %s" , diff )
310+ }
311+ })
312+ }
313+ }
0 commit comments