@@ -199,21 +199,30 @@ func TestRunCommandWithConfig(t *testing.T) {
199199 Name : "stage-release" ,
200200 Id : "stage-release-trigger-id" ,
201201 },
202+ {
203+ Name : "publish-release" ,
204+ Id : "publish-release-trigger-id" ,
205+ },
206+ {
207+ Name : "update-image" ,
208+ Id : "update-image-trigger-id" ,
209+ },
202210 {
203211 Name : "prepare-release" ,
204212 Id : "prepare-release-trigger-id" ,
205213 },
206214 }
207215 for _ , test := range []struct {
208- name string
209- command string
210- config * RepositoriesConfig
211- want string
212- runError error
213- wantErr bool
214- ghPRs []* github.PullRequest
215- ghError error
216- wantTriggersRun []string
216+ name string
217+ command string
218+ config * RepositoriesConfig
219+ want string
220+ runError error
221+ wantErr bool
222+ ghPRs []* github.PullRequest
223+ ghError error
224+ wantTriggersRun []string
225+ wantSubstitutions []map [string ]string
217226 }{
218227 {
219228 name : "runs generate trigger with name" ,
@@ -223,25 +232,42 @@ func TestRunCommandWithConfig(t *testing.T) {
223232 {
224233 Name : "google-cloud-python" ,
225234 SupportedCommands : []string {"generate" },
235+ SecretName : "foo" ,
226236 },
227237 },
228238 },
229239 wantErr : false ,
230240 wantTriggersRun : []string {"generate-trigger-id" },
241+ wantSubstitutions : []map [string ]string {{
242+ "_REPOSITORY" : "google-cloud-python" ,
243+ "_FULL_REPOSITORY" : "https://github.com/googleapis/google-cloud-python" ,
244+ "_GITHUB_TOKEN_SECRET_NAME" : "foo" ,
245+ "_PUSH" : "true" ,
246+ "_BUILD" : "true" ,
247+ }},
231248 },
232249 {
233250 name : "runs generate trigger with full name" ,
234251 command : "generate" ,
235252 config : & RepositoriesConfig {
236253 Repositories : []* RepositoryConfig {
237254 {
238- Name : "https://github.com/googleapis/google-cloud-python" ,
255+ Name : "google-cloud-python" ,
256+ FullName : "https://github.com/googleapis/google-cloud-python" ,
239257 SupportedCommands : []string {"generate" },
258+ SecretName : "bar" ,
240259 },
241260 },
242261 },
243262 wantErr : false ,
244263 wantTriggersRun : []string {"generate-trigger-id" },
264+ wantSubstitutions : []map [string ]string {{
265+ "_REPOSITORY" : "google-cloud-python" ,
266+ "_FULL_REPOSITORY" : "https://github.com/googleapis/google-cloud-python" ,
267+ "_GITHUB_TOKEN_SECRET_NAME" : "bar" ,
268+ "_PUSH" : "true" ,
269+ "_BUILD" : "true" ,
270+ }},
245271 },
246272 {
247273 name : "runs generate trigger without name" ,
@@ -264,11 +290,87 @@ func TestRunCommandWithConfig(t *testing.T) {
264290 {
265291 Name : "google-cloud-python" ,
266292 SupportedCommands : []string {"stage-release" },
293+ SecretName : "baz" ,
267294 },
268295 },
269296 },
270297 wantErr : false ,
271298 wantTriggersRun : []string {"stage-release-trigger-id" },
299+ wantSubstitutions : []map [string ]string {{
300+ "_REPOSITORY" : "google-cloud-python" ,
301+ "_FULL_REPOSITORY" : "https://github.com/googleapis/google-cloud-python" ,
302+ "_GITHUB_TOKEN_SECRET_NAME" : "baz" ,
303+ "_PUSH" : "true" ,
304+ }},
305+ },
306+ {
307+ name : "runs publish-release trigger" ,
308+ command : "publish-release" ,
309+ config : & RepositoriesConfig {
310+ Repositories : []* RepositoryConfig {
311+ {
312+ Name : "google-cloud-python" ,
313+ SupportedCommands : []string {"publish-release" },
314+ SecretName : "qux" ,
315+ },
316+ },
317+ },
318+ ghPRs : []* github.PullRequest {{HTMLURL : github .Ptr ("https://github.com/googleapis/google-cloud-python/pull/42" )}},
319+ wantErr : false ,
320+ wantTriggersRun : []string {"publish-release-trigger-id" },
321+ wantSubstitutions : []map [string ]string {{
322+ "_REPOSITORY" : "google-cloud-python" ,
323+ "_FULL_REPOSITORY" : "https://github.com/googleapis/google-cloud-python" ,
324+ "_GITHUB_TOKEN_SECRET_NAME" : "qux" ,
325+ "_PUSH" : "true" ,
326+ "_PR" : "https://github.com/googleapis/google-cloud-python/pull/42" ,
327+ }},
328+ },
329+ {
330+ name : "runs update-image trigger" ,
331+ command : "update-image" ,
332+ config : & RepositoriesConfig {
333+ Repositories : []* RepositoryConfig {
334+ {
335+ Name : "google-cloud-python" ,
336+ SupportedCommands : []string {"update-image" },
337+ SecretName : "quux" ,
338+ },
339+ },
340+ },
341+ wantErr : false ,
342+ wantTriggersRun : []string {"update-image-trigger-id" },
343+ wantSubstitutions : []map [string ]string {{
344+ "_REPOSITORY" : "google-cloud-python" ,
345+ "_FULL_REPOSITORY" : "https://github.com/googleapis/google-cloud-python" ,
346+ "_GITHUB_TOKEN_SECRET_NAME" : "quux" ,
347+ "_PUSH" : "true" ,
348+ "_BUILD" : "true" ,
349+ }},
350+ },
351+ {
352+ name : "runs generate trigger on branch" ,
353+ command : "generate" ,
354+ config : & RepositoriesConfig {
355+ Repositories : []* RepositoryConfig {
356+ {
357+ Name : "google-cloud-python" ,
358+ SupportedCommands : []string {"generate" },
359+ Branch : "preview" ,
360+ SecretName : "foo" ,
361+ },
362+ },
363+ },
364+ wantErr : false ,
365+ wantTriggersRun : []string {"generate-trigger-id" },
366+ wantSubstitutions : []map [string ]string {{
367+ "_REPOSITORY" : "google-cloud-python" ,
368+ "_FULL_REPOSITORY" : "https://github.com/googleapis/google-cloud-python" ,
369+ "_GITHUB_TOKEN_SECRET_NAME" : "foo" ,
370+ "_PUSH" : "true" ,
371+ "_BRANCH" : "preview" ,
372+ "_BUILD" : "true" ,
373+ }},
272374 },
273375 } {
274376 t .Run (test .name , func (t * testing.T ) {
@@ -290,6 +392,9 @@ func TestRunCommandWithConfig(t *testing.T) {
290392 if diff := cmp .Diff (test .wantTriggersRun , client .triggersRun ); diff != "" {
291393 t .Errorf ("runCommandWithConfig() triggersRun diff (-want, +got):\n %s" , diff )
292394 }
395+ if diff := cmp .Diff (test .wantSubstitutions , client .substitutions ); diff != "" {
396+ t .Errorf ("runCommandWithConfig() substitutions diff (-want, +got):\n %s" , diff )
397+ }
293398 })
294399 }
295400}
0 commit comments