Debian Codegraph @

cloudbuild/apiv1/v2/cloud_build_client_example_test.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package cloudbuild_test
18
19 import (
20 "context"
21
22 cloudbuild "cloud.google.com/go/cloudbuild/apiv1/v2"
23 cloudbuildpb "cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb"
24 "google.golang.org/api/iterator"
25 )
26
27 func ExampleNewClient() {
28 ctx := context.Background()
29 // This snippet has been automatically generated and should be regarded as a code template only.
30 // It will require modifications to work:
31 // - It may require correct/in-range values for request initialization.
32 // - It may require specifying regional endpoints when creating the service client as shown in:
33 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
34 c, err := cloudbuild.NewClient(ctx)
35 if err != nil {
36 // TODO: Handle error.
37 }
38 defer c.Close()
39
40 // TODO: Use client.
41 _ = c
42 }
43
44 func ExampleNewRESTClient() {
45 ctx := context.Background()
46 // This snippet has been automatically generated and should be regarded as a code template only.
47 // It will require modifications to work:
48 // - It may require correct/in-range values for request initialization.
49 // - It may require specifying regional endpoints when creating the service client as shown in:
50 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
51 c, err := cloudbuild.NewRESTClient(ctx)
52 if err != nil {
53 // TODO: Handle error.
54 }
55 defer c.Close()
56
57 // TODO: Use client.
58 _ = c
59 }
60
61 func ExampleClient_ApproveBuild() {
62 ctx := context.Background()
63 // This snippet has been automatically generated and should be regarded as a code template only.
64 // It will require modifications to work:
65 // - It may require correct/in-range values for request initialization.
66 // - It may require specifying regional endpoints when creating the service client as shown in:
67 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
68 c, err := cloudbuild.NewClient(ctx)
69 if err != nil {
70 // TODO: Handle error.
71 }
72 defer c.Close()
73
74 req := &cloudbuildpb.ApproveBuildRequest{
75 // TODO: Fill request struct fields.
76 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#ApproveBuildRequest.
77 }
78 op, err := c.ApproveBuild(ctx, req)
79 if err != nil {
80 // TODO: Handle error.
81 }
82
83 resp, err := op.Wait(ctx)
84 if err != nil {
85 // TODO: Handle error.
86 }
87 // TODO: Use resp.
88 _ = resp
89 }
90
91 func ExampleClient_CancelBuild() {
92 ctx := context.Background()
93 // This snippet has been automatically generated and should be regarded as a code template only.
94 // It will require modifications to work:
95 // - It may require correct/in-range values for request initialization.
96 // - It may require specifying regional endpoints when creating the service client as shown in:
97 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
98 c, err := cloudbuild.NewClient(ctx)
99 if err != nil {
100 // TODO: Handle error.
101 }
102 defer c.Close()
103
104 req := &cloudbuildpb.CancelBuildRequest{
105 // TODO: Fill request struct fields.
106 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#CancelBuildRequest.
107 }
108 resp, err := c.CancelBuild(ctx, req)
109 if err != nil {
110 // TODO: Handle error.
111 }
112 // TODO: Use resp.
113 _ = resp
114 }
115
116 func ExampleClient_CreateBuild() {
117 ctx := context.Background()
118 // This snippet has been automatically generated and should be regarded as a code template only.
119 // It will require modifications to work:
120 // - It may require correct/in-range values for request initialization.
121 // - It may require specifying regional endpoints when creating the service client as shown in:
122 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
123 c, err := cloudbuild.NewClient(ctx)
124 if err != nil {
125 // TODO: Handle error.
126 }
127 defer c.Close()
128
129 req := &cloudbuildpb.CreateBuildRequest{
130 // TODO: Fill request struct fields.
131 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#CreateBuildRequest.
132 }
133 op, err := c.CreateBuild(ctx, req)
134 if err != nil {
135 // TODO: Handle error.
136 }
137
138 resp, err := op.Wait(ctx)
139 if err != nil {
140 // TODO: Handle error.
141 }
142 // TODO: Use resp.
143 _ = resp
144 }
145
146 func ExampleClient_CreateBuildTrigger() {
147 ctx := context.Background()
148 // This snippet has been automatically generated and should be regarded as a code template only.
149 // It will require modifications to work:
150 // - It may require correct/in-range values for request initialization.
151 // - It may require specifying regional endpoints when creating the service client as shown in:
152 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
153 c, err := cloudbuild.NewClient(ctx)
154 if err != nil {
155 // TODO: Handle error.
156 }
157 defer c.Close()
158
159 req := &cloudbuildpb.CreateBuildTriggerRequest{
160 // TODO: Fill request struct fields.
161 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#CreateBuildTriggerRequest.
162 }
163 resp, err := c.CreateBuildTrigger(ctx, req)
164 if err != nil {
165 // TODO: Handle error.
166 }
167 // TODO: Use resp.
168 _ = resp
169 }
170
171 func ExampleClient_CreateWorkerPool() {
172 ctx := context.Background()
173 // This snippet has been automatically generated and should be regarded as a code template only.
174 // It will require modifications to work:
175 // - It may require correct/in-range values for request initialization.
176 // - It may require specifying regional endpoints when creating the service client as shown in:
177 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
178 c, err := cloudbuild.NewClient(ctx)
179 if err != nil {
180 // TODO: Handle error.
181 }
182 defer c.Close()
183
184 req := &cloudbuildpb.CreateWorkerPoolRequest{
185 // TODO: Fill request struct fields.
186 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#CreateWorkerPoolRequest.
187 }
188 op, err := c.CreateWorkerPool(ctx, req)
189 if err != nil {
190 // TODO: Handle error.
191 }
192
193 resp, err := op.Wait(ctx)
194 if err != nil {
195 // TODO: Handle error.
196 }
197 // TODO: Use resp.
198 _ = resp
199 }
200
201 func ExampleClient_DeleteBuildTrigger() {
202 ctx := context.Background()
203 // This snippet has been automatically generated and should be regarded as a code template only.
204 // It will require modifications to work:
205 // - It may require correct/in-range values for request initialization.
206 // - It may require specifying regional endpoints when creating the service client as shown in:
207 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
208 c, err := cloudbuild.NewClient(ctx)
209 if err != nil {
210 // TODO: Handle error.
211 }
212 defer c.Close()
213
214 req := &cloudbuildpb.DeleteBuildTriggerRequest{
215 // TODO: Fill request struct fields.
216 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#DeleteBuildTriggerRequest.
217 }
218 err = c.DeleteBuildTrigger(ctx, req)
219 if err != nil {
220 // TODO: Handle error.
221 }
222 }
223
224 func ExampleClient_DeleteWorkerPool() {
225 ctx := context.Background()
226 // This snippet has been automatically generated and should be regarded as a code template only.
227 // It will require modifications to work:
228 // - It may require correct/in-range values for request initialization.
229 // - It may require specifying regional endpoints when creating the service client as shown in:
230 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
231 c, err := cloudbuild.NewClient(ctx)
232 if err != nil {
233 // TODO: Handle error.
234 }
235 defer c.Close()
236
237 req := &cloudbuildpb.DeleteWorkerPoolRequest{
238 // TODO: Fill request struct fields.
239 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#DeleteWorkerPoolRequest.
240 }
241 op, err := c.DeleteWorkerPool(ctx, req)
242 if err != nil {
243 // TODO: Handle error.
244 }
245
246 err = op.Wait(ctx)
247 if err != nil {
248 // TODO: Handle error.
249 }
250 }
251
252 func ExampleClient_GetBuild() {
253 ctx := context.Background()
254 // This snippet has been automatically generated and should be regarded as a code template only.
255 // It will require modifications to work:
256 // - It may require correct/in-range values for request initialization.
257 // - It may require specifying regional endpoints when creating the service client as shown in:
258 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
259 c, err := cloudbuild.NewClient(ctx)
260 if err != nil {
261 // TODO: Handle error.
262 }
263 defer c.Close()
264
265 req := &cloudbuildpb.GetBuildRequest{
266 // TODO: Fill request struct fields.
267 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#GetBuildRequest.
268 }
269 resp, err := c.GetBuild(ctx, req)
270 if err != nil {
271 // TODO: Handle error.
272 }
273 // TODO: Use resp.
274 _ = resp
275 }
276
277 func ExampleClient_GetBuildTrigger() {
278 ctx := context.Background()
279 // This snippet has been automatically generated and should be regarded as a code template only.
280 // It will require modifications to work:
281 // - It may require correct/in-range values for request initialization.
282 // - It may require specifying regional endpoints when creating the service client as shown in:
283 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
284 c, err := cloudbuild.NewClient(ctx)
285 if err != nil {
286 // TODO: Handle error.
287 }
288 defer c.Close()
289
290 req := &cloudbuildpb.GetBuildTriggerRequest{
291 // TODO: Fill request struct fields.
292 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#GetBuildTriggerRequest.
293 }
294 resp, err := c.GetBuildTrigger(ctx, req)
295 if err != nil {
296 // TODO: Handle error.
297 }
298 // TODO: Use resp.
299 _ = resp
300 }
301
302 func ExampleClient_GetWorkerPool() {
303 ctx := context.Background()
304 // This snippet has been automatically generated and should be regarded as a code template only.
305 // It will require modifications to work:
306 // - It may require correct/in-range values for request initialization.
307 // - It may require specifying regional endpoints when creating the service client as shown in:
308 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
309 c, err := cloudbuild.NewClient(ctx)
310 if err != nil {
311 // TODO: Handle error.
312 }
313 defer c.Close()
314
315 req := &cloudbuildpb.GetWorkerPoolRequest{
316 // TODO: Fill request struct fields.
317 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#GetWorkerPoolRequest.
318 }
319 resp, err := c.GetWorkerPool(ctx, req)
320 if err != nil {
321 // TODO: Handle error.
322 }
323 // TODO: Use resp.
324 _ = resp
325 }
326
327 func ExampleClient_ListBuildTriggers() {
328 ctx := context.Background()
329 // This snippet has been automatically generated and should be regarded as a code template only.
330 // It will require modifications to work:
331 // - It may require correct/in-range values for request initialization.
332 // - It may require specifying regional endpoints when creating the service client as shown in:
333 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
334 c, err := cloudbuild.NewClient(ctx)
335 if err != nil {
336 // TODO: Handle error.
337 }
338 defer c.Close()
339
340 req := &cloudbuildpb.ListBuildTriggersRequest{
341 // TODO: Fill request struct fields.
342 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#ListBuildTriggersRequest.
343 }
344 it := c.ListBuildTriggers(ctx, req)
345 for {
346 resp, err := it.Next()
347 if err == iterator.Done {
348 break
349 }
350 if err != nil {
351 // TODO: Handle error.
352 }
353 // TODO: Use resp.
354 _ = resp
355
356 // If you need to access the underlying RPC response,
357 // you can do so by casting the `Response` as below.
358 // Otherwise, remove this line. Only populated after
359 // first call to Next(). Not safe for concurrent access.
360 _ = it.Response.(*cloudbuildpb.ListBuildTriggersResponse)
361 }
362 }
363
364 func ExampleClient_ListBuilds() {
365 ctx := context.Background()
366 // This snippet has been automatically generated and should be regarded as a code template only.
367 // It will require modifications to work:
368 // - It may require correct/in-range values for request initialization.
369 // - It may require specifying regional endpoints when creating the service client as shown in:
370 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
371 c, err := cloudbuild.NewClient(ctx)
372 if err != nil {
373 // TODO: Handle error.
374 }
375 defer c.Close()
376
377 req := &cloudbuildpb.ListBuildsRequest{
378 // TODO: Fill request struct fields.
379 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#ListBuildsRequest.
380 }
381 it := c.ListBuilds(ctx, req)
382 for {
383 resp, err := it.Next()
384 if err == iterator.Done {
385 break
386 }
387 if err != nil {
388 // TODO: Handle error.
389 }
390 // TODO: Use resp.
391 _ = resp
392
393 // If you need to access the underlying RPC response,
394 // you can do so by casting the `Response` as below.
395 // Otherwise, remove this line. Only populated after
396 // first call to Next(). Not safe for concurrent access.
397 _ = it.Response.(*cloudbuildpb.ListBuildsResponse)
398 }
399 }
400
401 func ExampleClient_ListWorkerPools() {
402 ctx := context.Background()
403 // This snippet has been automatically generated and should be regarded as a code template only.
404 // It will require modifications to work:
405 // - It may require correct/in-range values for request initialization.
406 // - It may require specifying regional endpoints when creating the service client as shown in:
407 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
408 c, err := cloudbuild.NewClient(ctx)
409 if err != nil {
410 // TODO: Handle error.
411 }
412 defer c.Close()
413
414 req := &cloudbuildpb.ListWorkerPoolsRequest{
415 // TODO: Fill request struct fields.
416 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#ListWorkerPoolsRequest.
417 }
418 it := c.ListWorkerPools(ctx, req)
419 for {
420 resp, err := it.Next()
421 if err == iterator.Done {
422 break
423 }
424 if err != nil {
425 // TODO: Handle error.
426 }
427 // TODO: Use resp.
428 _ = resp
429
430 // If you need to access the underlying RPC response,
431 // you can do so by casting the `Response` as below.
432 // Otherwise, remove this line. Only populated after
433 // first call to Next(). Not safe for concurrent access.
434 _ = it.Response.(*cloudbuildpb.ListWorkerPoolsResponse)
435 }
436 }
437
438 func ExampleClient_ReceiveTriggerWebhook() {
439 ctx := context.Background()
440 // This snippet has been automatically generated and should be regarded as a code template only.
441 // It will require modifications to work:
442 // - It may require correct/in-range values for request initialization.
443 // - It may require specifying regional endpoints when creating the service client as shown in:
444 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
445 c, err := cloudbuild.NewClient(ctx)
446 if err != nil {
447 // TODO: Handle error.
448 }
449 defer c.Close()
450
451 req := &cloudbuildpb.ReceiveTriggerWebhookRequest{
452 // TODO: Fill request struct fields.
453 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#ReceiveTriggerWebhookRequest.
454 }
455 resp, err := c.ReceiveTriggerWebhook(ctx, req)
456 if err != nil {
457 // TODO: Handle error.
458 }
459 // TODO: Use resp.
460 _ = resp
461 }
462
463 func ExampleClient_RetryBuild() {
464 ctx := context.Background()
465 // This snippet has been automatically generated and should be regarded as a code template only.
466 // It will require modifications to work:
467 // - It may require correct/in-range values for request initialization.
468 // - It may require specifying regional endpoints when creating the service client as shown in:
469 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
470 c, err := cloudbuild.NewClient(ctx)
471 if err != nil {
472 // TODO: Handle error.
473 }
474 defer c.Close()
475
476 req := &cloudbuildpb.RetryBuildRequest{
477 // TODO: Fill request struct fields.
478 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#RetryBuildRequest.
479 }
480 op, err := c.RetryBuild(ctx, req)
481 if err != nil {
482 // TODO: Handle error.
483 }
484
485 resp, err := op.Wait(ctx)
486 if err != nil {
487 // TODO: Handle error.
488 }
489 // TODO: Use resp.
490 _ = resp
491 }
492
493 func ExampleClient_RunBuildTrigger() {
494 ctx := context.Background()
495 // This snippet has been automatically generated and should be regarded as a code template only.
496 // It will require modifications to work:
497 // - It may require correct/in-range values for request initialization.
498 // - It may require specifying regional endpoints when creating the service client as shown in:
499 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
500 c, err := cloudbuild.NewClient(ctx)
501 if err != nil {
502 // TODO: Handle error.
503 }
504 defer c.Close()
505
506 req := &cloudbuildpb.RunBuildTriggerRequest{
507 // TODO: Fill request struct fields.
508 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#RunBuildTriggerRequest.
509 }
510 op, err := c.RunBuildTrigger(ctx, req)
511 if err != nil {
512 // TODO: Handle error.
513 }
514
515 resp, err := op.Wait(ctx)
516 if err != nil {
517 // TODO: Handle error.
518 }
519 // TODO: Use resp.
520 _ = resp
521 }
522
523 func ExampleClient_UpdateBuildTrigger() {
524 ctx := context.Background()
525 // This snippet has been automatically generated and should be regarded as a code template only.
526 // It will require modifications to work:
527 // - It may require correct/in-range values for request initialization.
528 // - It may require specifying regional endpoints when creating the service client as shown in:
529 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
530 c, err := cloudbuild.NewClient(ctx)
531 if err != nil {
532 // TODO: Handle error.
533 }
534 defer c.Close()
535
536 req := &cloudbuildpb.UpdateBuildTriggerRequest{
537 // TODO: Fill request struct fields.
538 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#UpdateBuildTriggerRequest.
539 }
540 resp, err := c.UpdateBuildTrigger(ctx, req)
541 if err != nil {
542 // TODO: Handle error.
543 }
544 // TODO: Use resp.
545 _ = resp
546 }
547
548 func ExampleClient_UpdateWorkerPool() {
549 ctx := context.Background()
550 // This snippet has been automatically generated and should be regarded as a code template only.
551 // It will require modifications to work:
552 // - It may require correct/in-range values for request initialization.
553 // - It may require specifying regional endpoints when creating the service client as shown in:
554 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
555 c, err := cloudbuild.NewClient(ctx)
556 if err != nil {
557 // TODO: Handle error.
558 }
559 defer c.Close()
560
561 req := &cloudbuildpb.UpdateWorkerPoolRequest{
562 // TODO: Fill request struct fields.
563 // See https://pkg.go.dev/cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb#UpdateWorkerPoolRequest.
564 }
565 op, err := c.UpdateWorkerPool(ctx, req)
566 if err != nil {
567 // TODO: Handle error.
568 }
569
570 resp, err := op.Wait(ctx)
571 if err != nil {
572 // TODO: Handle error.
573 }
574 // TODO: Use resp.
575 _ = resp
576 }