1// Copyright 2021 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 17package cx 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "cloud.google.com/go/longrunning" 27 lroauto "cloud.google.com/go/longrunning/autogen" 28 "github.com/golang/protobuf/proto" 29 gax "github.com/googleapis/gax-go/v2" 30 "google.golang.org/api/iterator" 31 "google.golang.org/api/option" 32 "google.golang.org/api/option/internaloption" 33 gtransport "google.golang.org/api/transport/grpc" 34 cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" 35 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 36 "google.golang.org/grpc" 37 "google.golang.org/grpc/codes" 38 "google.golang.org/grpc/metadata" 39) 40 41var newTestCasesClientHook clientHook 42 43// TestCasesCallOptions contains the retry settings for each method of TestCasesClient. 44type TestCasesCallOptions struct { 45 ListTestCases []gax.CallOption 46 BatchDeleteTestCases []gax.CallOption 47 GetTestCase []gax.CallOption 48 CreateTestCase []gax.CallOption 49 UpdateTestCase []gax.CallOption 50 RunTestCase []gax.CallOption 51 BatchRunTestCases []gax.CallOption 52 CalculateCoverage []gax.CallOption 53 ImportTestCases []gax.CallOption 54 ExportTestCases []gax.CallOption 55 ListTestCaseResults []gax.CallOption 56 GetTestCaseResult []gax.CallOption 57} 58 59func defaultTestCasesClientOptions() []option.ClientOption { 60 return []option.ClientOption{ 61 internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), 62 internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), 63 internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), 64 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 65 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 66 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 67 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 68 } 69} 70 71func defaultTestCasesCallOptions() *TestCasesCallOptions { 72 return &TestCasesCallOptions{ 73 ListTestCases: []gax.CallOption{ 74 gax.WithRetry(func() gax.Retryer { 75 return gax.OnCodes([]codes.Code{ 76 codes.Unavailable, 77 }, gax.Backoff{ 78 Initial: 100 * time.Millisecond, 79 Max: 60000 * time.Millisecond, 80 Multiplier: 1.30, 81 }) 82 }), 83 }, 84 BatchDeleteTestCases: []gax.CallOption{ 85 gax.WithRetry(func() gax.Retryer { 86 return gax.OnCodes([]codes.Code{ 87 codes.Unavailable, 88 }, gax.Backoff{ 89 Initial: 100 * time.Millisecond, 90 Max: 60000 * time.Millisecond, 91 Multiplier: 1.30, 92 }) 93 }), 94 }, 95 GetTestCase: []gax.CallOption{ 96 gax.WithRetry(func() gax.Retryer { 97 return gax.OnCodes([]codes.Code{ 98 codes.Unavailable, 99 }, gax.Backoff{ 100 Initial: 100 * time.Millisecond, 101 Max: 60000 * time.Millisecond, 102 Multiplier: 1.30, 103 }) 104 }), 105 }, 106 CreateTestCase: []gax.CallOption{ 107 gax.WithRetry(func() gax.Retryer { 108 return gax.OnCodes([]codes.Code{ 109 codes.Unavailable, 110 }, gax.Backoff{ 111 Initial: 100 * time.Millisecond, 112 Max: 60000 * time.Millisecond, 113 Multiplier: 1.30, 114 }) 115 }), 116 }, 117 UpdateTestCase: []gax.CallOption{ 118 gax.WithRetry(func() gax.Retryer { 119 return gax.OnCodes([]codes.Code{ 120 codes.Unavailable, 121 }, gax.Backoff{ 122 Initial: 100 * time.Millisecond, 123 Max: 60000 * time.Millisecond, 124 Multiplier: 1.30, 125 }) 126 }), 127 }, 128 RunTestCase: []gax.CallOption{ 129 gax.WithRetry(func() gax.Retryer { 130 return gax.OnCodes([]codes.Code{ 131 codes.Unavailable, 132 }, gax.Backoff{ 133 Initial: 100 * time.Millisecond, 134 Max: 60000 * time.Millisecond, 135 Multiplier: 1.30, 136 }) 137 }), 138 }, 139 BatchRunTestCases: []gax.CallOption{ 140 gax.WithRetry(func() gax.Retryer { 141 return gax.OnCodes([]codes.Code{ 142 codes.Unavailable, 143 }, gax.Backoff{ 144 Initial: 100 * time.Millisecond, 145 Max: 60000 * time.Millisecond, 146 Multiplier: 1.30, 147 }) 148 }), 149 }, 150 CalculateCoverage: []gax.CallOption{ 151 gax.WithRetry(func() gax.Retryer { 152 return gax.OnCodes([]codes.Code{ 153 codes.Unavailable, 154 }, gax.Backoff{ 155 Initial: 100 * time.Millisecond, 156 Max: 60000 * time.Millisecond, 157 Multiplier: 1.30, 158 }) 159 }), 160 }, 161 ImportTestCases: []gax.CallOption{ 162 gax.WithRetry(func() gax.Retryer { 163 return gax.OnCodes([]codes.Code{ 164 codes.Unavailable, 165 }, gax.Backoff{ 166 Initial: 100 * time.Millisecond, 167 Max: 60000 * time.Millisecond, 168 Multiplier: 1.30, 169 }) 170 }), 171 }, 172 ExportTestCases: []gax.CallOption{ 173 gax.WithRetry(func() gax.Retryer { 174 return gax.OnCodes([]codes.Code{ 175 codes.Unavailable, 176 }, gax.Backoff{ 177 Initial: 100 * time.Millisecond, 178 Max: 60000 * time.Millisecond, 179 Multiplier: 1.30, 180 }) 181 }), 182 }, 183 ListTestCaseResults: []gax.CallOption{ 184 gax.WithRetry(func() gax.Retryer { 185 return gax.OnCodes([]codes.Code{ 186 codes.Unavailable, 187 }, gax.Backoff{ 188 Initial: 100 * time.Millisecond, 189 Max: 60000 * time.Millisecond, 190 Multiplier: 1.30, 191 }) 192 }), 193 }, 194 GetTestCaseResult: []gax.CallOption{ 195 gax.WithRetry(func() gax.Retryer { 196 return gax.OnCodes([]codes.Code{ 197 codes.Unavailable, 198 }, gax.Backoff{ 199 Initial: 100 * time.Millisecond, 200 Max: 60000 * time.Millisecond, 201 Multiplier: 1.30, 202 }) 203 }), 204 }, 205 } 206} 207 208// TestCasesClient is a client for interacting with Dialogflow API. 209// 210// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 211type TestCasesClient struct { 212 // Connection pool of gRPC connections to the service. 213 connPool gtransport.ConnPool 214 215 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 216 disableDeadlines bool 217 218 // The gRPC API client. 219 testCasesClient cxpb.TestCasesClient 220 221 // LROClient is used internally to handle longrunning operations. 222 // It is exposed so that its CallOptions can be modified if required. 223 // Users should not Close this client. 224 LROClient *lroauto.OperationsClient 225 226 // The call options for this service. 227 CallOptions *TestCasesCallOptions 228 229 // The x-goog-* metadata to be sent with each request. 230 xGoogMetadata metadata.MD 231} 232 233// NewTestCasesClient creates a new test cases client. 234// 235// Service for managing [Test Cases][google.cloud.dialogflow.cx.v3.TestCase] and 236// [Test Case Results][google.cloud.dialogflow.cx.v3.TestCaseResult]. 237func NewTestCasesClient(ctx context.Context, opts ...option.ClientOption) (*TestCasesClient, error) { 238 clientOpts := defaultTestCasesClientOptions() 239 240 if newTestCasesClientHook != nil { 241 hookOpts, err := newTestCasesClientHook(ctx, clientHookParams{}) 242 if err != nil { 243 return nil, err 244 } 245 clientOpts = append(clientOpts, hookOpts...) 246 } 247 248 disableDeadlines, err := checkDisableDeadlines() 249 if err != nil { 250 return nil, err 251 } 252 253 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 254 if err != nil { 255 return nil, err 256 } 257 c := &TestCasesClient{ 258 connPool: connPool, 259 disableDeadlines: disableDeadlines, 260 CallOptions: defaultTestCasesCallOptions(), 261 262 testCasesClient: cxpb.NewTestCasesClient(connPool), 263 } 264 c.setGoogleClientInfo() 265 266 c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 267 if err != nil { 268 // This error "should not happen", since we are just reusing old connection pool 269 // and never actually need to dial. 270 // If this does happen, we could leak connp. However, we cannot close conn: 271 // If the user invoked the constructor with option.WithGRPCConn, 272 // we would close a connection that's still in use. 273 // TODO: investigate error conditions. 274 return nil, err 275 } 276 return c, nil 277} 278 279// Connection returns a connection to the API service. 280// 281// Deprecated. 282func (c *TestCasesClient) Connection() *grpc.ClientConn { 283 return c.connPool.Conn() 284} 285 286// Close closes the connection to the API service. The user should invoke this when 287// the client is no longer required. 288func (c *TestCasesClient) Close() error { 289 return c.connPool.Close() 290} 291 292// setGoogleClientInfo sets the name and version of the application in 293// the `x-goog-api-client` header passed on each request. Intended for 294// use by Google-written clients. 295func (c *TestCasesClient) setGoogleClientInfo(keyval ...string) { 296 kv := append([]string{"gl-go", versionGo()}, keyval...) 297 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 298 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 299} 300 301// ListTestCases fetches a list of test cases for a given agent. 302func (c *TestCasesClient) ListTestCases(ctx context.Context, req *cxpb.ListTestCasesRequest, opts ...gax.CallOption) *TestCaseIterator { 303 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 304 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 305 opts = append(c.CallOptions.ListTestCases[0:len(c.CallOptions.ListTestCases):len(c.CallOptions.ListTestCases)], opts...) 306 it := &TestCaseIterator{} 307 req = proto.Clone(req).(*cxpb.ListTestCasesRequest) 308 it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TestCase, string, error) { 309 var resp *cxpb.ListTestCasesResponse 310 req.PageToken = pageToken 311 if pageSize > math.MaxInt32 { 312 req.PageSize = math.MaxInt32 313 } else { 314 req.PageSize = int32(pageSize) 315 } 316 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 317 var err error 318 resp, err = c.testCasesClient.ListTestCases(ctx, req, settings.GRPC...) 319 return err 320 }, opts...) 321 if err != nil { 322 return nil, "", err 323 } 324 325 it.Response = resp 326 return resp.GetTestCases(), resp.GetNextPageToken(), nil 327 } 328 fetch := func(pageSize int, pageToken string) (string, error) { 329 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 330 if err != nil { 331 return "", err 332 } 333 it.items = append(it.items, items...) 334 return nextPageToken, nil 335 } 336 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 337 it.pageInfo.MaxSize = int(req.GetPageSize()) 338 it.pageInfo.Token = req.GetPageToken() 339 return it 340} 341 342// BatchDeleteTestCases batch deletes test cases. 343func (c *TestCasesClient) BatchDeleteTestCases(ctx context.Context, req *cxpb.BatchDeleteTestCasesRequest, opts ...gax.CallOption) error { 344 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 345 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 346 defer cancel() 347 ctx = cctx 348 } 349 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 350 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 351 opts = append(c.CallOptions.BatchDeleteTestCases[0:len(c.CallOptions.BatchDeleteTestCases):len(c.CallOptions.BatchDeleteTestCases)], opts...) 352 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 353 var err error 354 _, err = c.testCasesClient.BatchDeleteTestCases(ctx, req, settings.GRPC...) 355 return err 356 }, opts...) 357 return err 358} 359 360// GetTestCase gets a test case. 361func (c *TestCasesClient) GetTestCase(ctx context.Context, req *cxpb.GetTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 362 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 363 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 364 defer cancel() 365 ctx = cctx 366 } 367 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 368 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 369 opts = append(c.CallOptions.GetTestCase[0:len(c.CallOptions.GetTestCase):len(c.CallOptions.GetTestCase)], opts...) 370 var resp *cxpb.TestCase 371 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 372 var err error 373 resp, err = c.testCasesClient.GetTestCase(ctx, req, settings.GRPC...) 374 return err 375 }, opts...) 376 if err != nil { 377 return nil, err 378 } 379 return resp, nil 380} 381 382// CreateTestCase creates a test case for the given agent. 383func (c *TestCasesClient) CreateTestCase(ctx context.Context, req *cxpb.CreateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 384 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 385 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 386 defer cancel() 387 ctx = cctx 388 } 389 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 390 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 391 opts = append(c.CallOptions.CreateTestCase[0:len(c.CallOptions.CreateTestCase):len(c.CallOptions.CreateTestCase)], opts...) 392 var resp *cxpb.TestCase 393 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 394 var err error 395 resp, err = c.testCasesClient.CreateTestCase(ctx, req, settings.GRPC...) 396 return err 397 }, opts...) 398 if err != nil { 399 return nil, err 400 } 401 return resp, nil 402} 403 404// UpdateTestCase updates the specified test case. 405func (c *TestCasesClient) UpdateTestCase(ctx context.Context, req *cxpb.UpdateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 406 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 407 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 408 defer cancel() 409 ctx = cctx 410 } 411 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "test_case.name", url.QueryEscape(req.GetTestCase().GetName()))) 412 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 413 opts = append(c.CallOptions.UpdateTestCase[0:len(c.CallOptions.UpdateTestCase):len(c.CallOptions.UpdateTestCase)], opts...) 414 var resp *cxpb.TestCase 415 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 416 var err error 417 resp, err = c.testCasesClient.UpdateTestCase(ctx, req, settings.GRPC...) 418 return err 419 }, opts...) 420 if err != nil { 421 return nil, err 422 } 423 return resp, nil 424} 425 426// RunTestCase kicks off a test case run. 427func (c *TestCasesClient) RunTestCase(ctx context.Context, req *cxpb.RunTestCaseRequest, opts ...gax.CallOption) (*RunTestCaseOperation, error) { 428 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 429 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 430 defer cancel() 431 ctx = cctx 432 } 433 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 434 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 435 opts = append(c.CallOptions.RunTestCase[0:len(c.CallOptions.RunTestCase):len(c.CallOptions.RunTestCase)], opts...) 436 var resp *longrunningpb.Operation 437 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 438 var err error 439 resp, err = c.testCasesClient.RunTestCase(ctx, req, settings.GRPC...) 440 return err 441 }, opts...) 442 if err != nil { 443 return nil, err 444 } 445 return &RunTestCaseOperation{ 446 lro: longrunning.InternalNewOperation(c.LROClient, resp), 447 }, nil 448} 449 450// BatchRunTestCases kicks off a batch run of test cases. 451func (c *TestCasesClient) BatchRunTestCases(ctx context.Context, req *cxpb.BatchRunTestCasesRequest, opts ...gax.CallOption) (*BatchRunTestCasesOperation, error) { 452 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 453 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 454 defer cancel() 455 ctx = cctx 456 } 457 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 458 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 459 opts = append(c.CallOptions.BatchRunTestCases[0:len(c.CallOptions.BatchRunTestCases):len(c.CallOptions.BatchRunTestCases)], opts...) 460 var resp *longrunningpb.Operation 461 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 462 var err error 463 resp, err = c.testCasesClient.BatchRunTestCases(ctx, req, settings.GRPC...) 464 return err 465 }, opts...) 466 if err != nil { 467 return nil, err 468 } 469 return &BatchRunTestCasesOperation{ 470 lro: longrunning.InternalNewOperation(c.LROClient, resp), 471 }, nil 472} 473 474// CalculateCoverage calculates the test coverage for an agent. 475func (c *TestCasesClient) CalculateCoverage(ctx context.Context, req *cxpb.CalculateCoverageRequest, opts ...gax.CallOption) (*cxpb.CalculateCoverageResponse, error) { 476 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 477 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 478 defer cancel() 479 ctx = cctx 480 } 481 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "agent", url.QueryEscape(req.GetAgent()))) 482 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 483 opts = append(c.CallOptions.CalculateCoverage[0:len(c.CallOptions.CalculateCoverage):len(c.CallOptions.CalculateCoverage)], opts...) 484 var resp *cxpb.CalculateCoverageResponse 485 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 486 var err error 487 resp, err = c.testCasesClient.CalculateCoverage(ctx, req, settings.GRPC...) 488 return err 489 }, opts...) 490 if err != nil { 491 return nil, err 492 } 493 return resp, nil 494} 495 496// ImportTestCases imports the test cases from a Cloud Storage bucket or a local file. It 497// always creates new test cases and won’t overwite any existing ones. The 498// provided ID in the imported test case is neglected. 499func (c *TestCasesClient) ImportTestCases(ctx context.Context, req *cxpb.ImportTestCasesRequest, opts ...gax.CallOption) (*ImportTestCasesOperation, error) { 500 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 501 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 502 defer cancel() 503 ctx = cctx 504 } 505 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 506 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 507 opts = append(c.CallOptions.ImportTestCases[0:len(c.CallOptions.ImportTestCases):len(c.CallOptions.ImportTestCases)], opts...) 508 var resp *longrunningpb.Operation 509 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 510 var err error 511 resp, err = c.testCasesClient.ImportTestCases(ctx, req, settings.GRPC...) 512 return err 513 }, opts...) 514 if err != nil { 515 return nil, err 516 } 517 return &ImportTestCasesOperation{ 518 lro: longrunning.InternalNewOperation(c.LROClient, resp), 519 }, nil 520} 521 522// ExportTestCases exports the test cases under the agent to a Cloud Storage bucket or a local 523// file. Filter can be applied to export a subset of test cases. 524func (c *TestCasesClient) ExportTestCases(ctx context.Context, req *cxpb.ExportTestCasesRequest, opts ...gax.CallOption) (*ExportTestCasesOperation, error) { 525 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 526 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 527 defer cancel() 528 ctx = cctx 529 } 530 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 531 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 532 opts = append(c.CallOptions.ExportTestCases[0:len(c.CallOptions.ExportTestCases):len(c.CallOptions.ExportTestCases)], opts...) 533 var resp *longrunningpb.Operation 534 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 535 var err error 536 resp, err = c.testCasesClient.ExportTestCases(ctx, req, settings.GRPC...) 537 return err 538 }, opts...) 539 if err != nil { 540 return nil, err 541 } 542 return &ExportTestCasesOperation{ 543 lro: longrunning.InternalNewOperation(c.LROClient, resp), 544 }, nil 545} 546 547// ListTestCaseResults fetches a list of results for a given test case. 548func (c *TestCasesClient) ListTestCaseResults(ctx context.Context, req *cxpb.ListTestCaseResultsRequest, opts ...gax.CallOption) *TestCaseResultIterator { 549 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 550 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 551 opts = append(c.CallOptions.ListTestCaseResults[0:len(c.CallOptions.ListTestCaseResults):len(c.CallOptions.ListTestCaseResults)], opts...) 552 it := &TestCaseResultIterator{} 553 req = proto.Clone(req).(*cxpb.ListTestCaseResultsRequest) 554 it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TestCaseResult, string, error) { 555 var resp *cxpb.ListTestCaseResultsResponse 556 req.PageToken = pageToken 557 if pageSize > math.MaxInt32 { 558 req.PageSize = math.MaxInt32 559 } else { 560 req.PageSize = int32(pageSize) 561 } 562 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 563 var err error 564 resp, err = c.testCasesClient.ListTestCaseResults(ctx, req, settings.GRPC...) 565 return err 566 }, opts...) 567 if err != nil { 568 return nil, "", err 569 } 570 571 it.Response = resp 572 return resp.GetTestCaseResults(), resp.GetNextPageToken(), nil 573 } 574 fetch := func(pageSize int, pageToken string) (string, error) { 575 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 576 if err != nil { 577 return "", err 578 } 579 it.items = append(it.items, items...) 580 return nextPageToken, nil 581 } 582 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 583 it.pageInfo.MaxSize = int(req.GetPageSize()) 584 it.pageInfo.Token = req.GetPageToken() 585 return it 586} 587 588// GetTestCaseResult gets a test case result. 589func (c *TestCasesClient) GetTestCaseResult(ctx context.Context, req *cxpb.GetTestCaseResultRequest, opts ...gax.CallOption) (*cxpb.TestCaseResult, error) { 590 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 591 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 592 defer cancel() 593 ctx = cctx 594 } 595 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 596 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 597 opts = append(c.CallOptions.GetTestCaseResult[0:len(c.CallOptions.GetTestCaseResult):len(c.CallOptions.GetTestCaseResult)], opts...) 598 var resp *cxpb.TestCaseResult 599 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 600 var err error 601 resp, err = c.testCasesClient.GetTestCaseResult(ctx, req, settings.GRPC...) 602 return err 603 }, opts...) 604 if err != nil { 605 return nil, err 606 } 607 return resp, nil 608} 609 610// BatchRunTestCasesOperation manages a long-running operation from BatchRunTestCases. 611type BatchRunTestCasesOperation struct { 612 lro *longrunning.Operation 613} 614 615// BatchRunTestCasesOperation returns a new BatchRunTestCasesOperation from a given name. 616// The name must be that of a previously created BatchRunTestCasesOperation, possibly from a different process. 617func (c *TestCasesClient) BatchRunTestCasesOperation(name string) *BatchRunTestCasesOperation { 618 return &BatchRunTestCasesOperation{ 619 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 620 } 621} 622 623// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 624// 625// See documentation of Poll for error-handling information. 626func (op *BatchRunTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.BatchRunTestCasesResponse, error) { 627 var resp cxpb.BatchRunTestCasesResponse 628 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 629 return nil, err 630 } 631 return &resp, nil 632} 633 634// Poll fetches the latest state of the long-running operation. 635// 636// Poll also fetches the latest metadata, which can be retrieved by Metadata. 637// 638// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 639// the operation has completed with failure, the error is returned and op.Done will return true. 640// If Poll succeeds and the operation has completed successfully, 641// op.Done will return true, and the response of the operation is returned. 642// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 643func (op *BatchRunTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.BatchRunTestCasesResponse, error) { 644 var resp cxpb.BatchRunTestCasesResponse 645 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 646 return nil, err 647 } 648 if !op.Done() { 649 return nil, nil 650 } 651 return &resp, nil 652} 653 654// Metadata returns metadata associated with the long-running operation. 655// Metadata itself does not contact the server, but Poll does. 656// To get the latest metadata, call this method after a successful call to Poll. 657// If the metadata is not available, the returned metadata and error are both nil. 658func (op *BatchRunTestCasesOperation) Metadata() (*cxpb.BatchRunTestCasesMetadata, error) { 659 var meta cxpb.BatchRunTestCasesMetadata 660 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 661 return nil, nil 662 } else if err != nil { 663 return nil, err 664 } 665 return &meta, nil 666} 667 668// Done reports whether the long-running operation has completed. 669func (op *BatchRunTestCasesOperation) Done() bool { 670 return op.lro.Done() 671} 672 673// Name returns the name of the long-running operation. 674// The name is assigned by the server and is unique within the service from which the operation is created. 675func (op *BatchRunTestCasesOperation) Name() string { 676 return op.lro.Name() 677} 678 679// ExportTestCasesOperation manages a long-running operation from ExportTestCases. 680type ExportTestCasesOperation struct { 681 lro *longrunning.Operation 682} 683 684// ExportTestCasesOperation returns a new ExportTestCasesOperation from a given name. 685// The name must be that of a previously created ExportTestCasesOperation, possibly from a different process. 686func (c *TestCasesClient) ExportTestCasesOperation(name string) *ExportTestCasesOperation { 687 return &ExportTestCasesOperation{ 688 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 689 } 690} 691 692// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 693// 694// See documentation of Poll for error-handling information. 695func (op *ExportTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportTestCasesResponse, error) { 696 var resp cxpb.ExportTestCasesResponse 697 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 698 return nil, err 699 } 700 return &resp, nil 701} 702 703// Poll fetches the latest state of the long-running operation. 704// 705// Poll also fetches the latest metadata, which can be retrieved by Metadata. 706// 707// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 708// the operation has completed with failure, the error is returned and op.Done will return true. 709// If Poll succeeds and the operation has completed successfully, 710// op.Done will return true, and the response of the operation is returned. 711// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 712func (op *ExportTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportTestCasesResponse, error) { 713 var resp cxpb.ExportTestCasesResponse 714 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 715 return nil, err 716 } 717 if !op.Done() { 718 return nil, nil 719 } 720 return &resp, nil 721} 722 723// Metadata returns metadata associated with the long-running operation. 724// Metadata itself does not contact the server, but Poll does. 725// To get the latest metadata, call this method after a successful call to Poll. 726// If the metadata is not available, the returned metadata and error are both nil. 727func (op *ExportTestCasesOperation) Metadata() (*cxpb.ExportTestCasesMetadata, error) { 728 var meta cxpb.ExportTestCasesMetadata 729 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 730 return nil, nil 731 } else if err != nil { 732 return nil, err 733 } 734 return &meta, nil 735} 736 737// Done reports whether the long-running operation has completed. 738func (op *ExportTestCasesOperation) Done() bool { 739 return op.lro.Done() 740} 741 742// Name returns the name of the long-running operation. 743// The name is assigned by the server and is unique within the service from which the operation is created. 744func (op *ExportTestCasesOperation) Name() string { 745 return op.lro.Name() 746} 747 748// ImportTestCasesOperation manages a long-running operation from ImportTestCases. 749type ImportTestCasesOperation struct { 750 lro *longrunning.Operation 751} 752 753// ImportTestCasesOperation returns a new ImportTestCasesOperation from a given name. 754// The name must be that of a previously created ImportTestCasesOperation, possibly from a different process. 755func (c *TestCasesClient) ImportTestCasesOperation(name string) *ImportTestCasesOperation { 756 return &ImportTestCasesOperation{ 757 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 758 } 759} 760 761// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 762// 763// See documentation of Poll for error-handling information. 764func (op *ImportTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ImportTestCasesResponse, error) { 765 var resp cxpb.ImportTestCasesResponse 766 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 767 return nil, err 768 } 769 return &resp, nil 770} 771 772// Poll fetches the latest state of the long-running operation. 773// 774// Poll also fetches the latest metadata, which can be retrieved by Metadata. 775// 776// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 777// the operation has completed with failure, the error is returned and op.Done will return true. 778// If Poll succeeds and the operation has completed successfully, 779// op.Done will return true, and the response of the operation is returned. 780// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 781func (op *ImportTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ImportTestCasesResponse, error) { 782 var resp cxpb.ImportTestCasesResponse 783 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 784 return nil, err 785 } 786 if !op.Done() { 787 return nil, nil 788 } 789 return &resp, nil 790} 791 792// Metadata returns metadata associated with the long-running operation. 793// Metadata itself does not contact the server, but Poll does. 794// To get the latest metadata, call this method after a successful call to Poll. 795// If the metadata is not available, the returned metadata and error are both nil. 796func (op *ImportTestCasesOperation) Metadata() (*cxpb.ImportTestCasesMetadata, error) { 797 var meta cxpb.ImportTestCasesMetadata 798 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 799 return nil, nil 800 } else if err != nil { 801 return nil, err 802 } 803 return &meta, nil 804} 805 806// Done reports whether the long-running operation has completed. 807func (op *ImportTestCasesOperation) Done() bool { 808 return op.lro.Done() 809} 810 811// Name returns the name of the long-running operation. 812// The name is assigned by the server and is unique within the service from which the operation is created. 813func (op *ImportTestCasesOperation) Name() string { 814 return op.lro.Name() 815} 816 817// RunTestCaseOperation manages a long-running operation from RunTestCase. 818type RunTestCaseOperation struct { 819 lro *longrunning.Operation 820} 821 822// RunTestCaseOperation returns a new RunTestCaseOperation from a given name. 823// The name must be that of a previously created RunTestCaseOperation, possibly from a different process. 824func (c *TestCasesClient) RunTestCaseOperation(name string) *RunTestCaseOperation { 825 return &RunTestCaseOperation{ 826 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 827 } 828} 829 830// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 831// 832// See documentation of Poll for error-handling information. 833func (op *RunTestCaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.RunTestCaseResponse, error) { 834 var resp cxpb.RunTestCaseResponse 835 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 836 return nil, err 837 } 838 return &resp, nil 839} 840 841// Poll fetches the latest state of the long-running operation. 842// 843// Poll also fetches the latest metadata, which can be retrieved by Metadata. 844// 845// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 846// the operation has completed with failure, the error is returned and op.Done will return true. 847// If Poll succeeds and the operation has completed successfully, 848// op.Done will return true, and the response of the operation is returned. 849// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 850func (op *RunTestCaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.RunTestCaseResponse, error) { 851 var resp cxpb.RunTestCaseResponse 852 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 853 return nil, err 854 } 855 if !op.Done() { 856 return nil, nil 857 } 858 return &resp, nil 859} 860 861// Metadata returns metadata associated with the long-running operation. 862// Metadata itself does not contact the server, but Poll does. 863// To get the latest metadata, call this method after a successful call to Poll. 864// If the metadata is not available, the returned metadata and error are both nil. 865func (op *RunTestCaseOperation) Metadata() (*cxpb.RunTestCaseMetadata, error) { 866 var meta cxpb.RunTestCaseMetadata 867 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 868 return nil, nil 869 } else if err != nil { 870 return nil, err 871 } 872 return &meta, nil 873} 874 875// Done reports whether the long-running operation has completed. 876func (op *RunTestCaseOperation) Done() bool { 877 return op.lro.Done() 878} 879 880// Name returns the name of the long-running operation. 881// The name is assigned by the server and is unique within the service from which the operation is created. 882func (op *RunTestCaseOperation) Name() string { 883 return op.lro.Name() 884} 885 886// TestCaseIterator manages a stream of *cxpb.TestCase. 887type TestCaseIterator struct { 888 items []*cxpb.TestCase 889 pageInfo *iterator.PageInfo 890 nextFunc func() error 891 892 // Response is the raw response for the current page. 893 // It must be cast to the RPC response type. 894 // Calling Next() or InternalFetch() updates this value. 895 Response interface{} 896 897 // InternalFetch is for use by the Google Cloud Libraries only. 898 // It is not part of the stable interface of this package. 899 // 900 // InternalFetch returns results from a single call to the underlying RPC. 901 // The number of results is no greater than pageSize. 902 // If there are no more results, nextPageToken is empty and err is nil. 903 InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TestCase, nextPageToken string, err error) 904} 905 906// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 907func (it *TestCaseIterator) PageInfo() *iterator.PageInfo { 908 return it.pageInfo 909} 910 911// Next returns the next result. Its second return value is iterator.Done if there are no more 912// results. Once Next returns Done, all subsequent calls will return Done. 913func (it *TestCaseIterator) Next() (*cxpb.TestCase, error) { 914 var item *cxpb.TestCase 915 if err := it.nextFunc(); err != nil { 916 return item, err 917 } 918 item = it.items[0] 919 it.items = it.items[1:] 920 return item, nil 921} 922 923func (it *TestCaseIterator) bufLen() int { 924 return len(it.items) 925} 926 927func (it *TestCaseIterator) takeBuf() interface{} { 928 b := it.items 929 it.items = nil 930 return b 931} 932 933// TestCaseResultIterator manages a stream of *cxpb.TestCaseResult. 934type TestCaseResultIterator struct { 935 items []*cxpb.TestCaseResult 936 pageInfo *iterator.PageInfo 937 nextFunc func() error 938 939 // Response is the raw response for the current page. 940 // It must be cast to the RPC response type. 941 // Calling Next() or InternalFetch() updates this value. 942 Response interface{} 943 944 // InternalFetch is for use by the Google Cloud Libraries only. 945 // It is not part of the stable interface of this package. 946 // 947 // InternalFetch returns results from a single call to the underlying RPC. 948 // The number of results is no greater than pageSize. 949 // If there are no more results, nextPageToken is empty and err is nil. 950 InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TestCaseResult, nextPageToken string, err error) 951} 952 953// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 954func (it *TestCaseResultIterator) PageInfo() *iterator.PageInfo { 955 return it.pageInfo 956} 957 958// Next returns the next result. Its second return value is iterator.Done if there are no more 959// results. Once Next returns Done, all subsequent calls will return Done. 960func (it *TestCaseResultIterator) Next() (*cxpb.TestCaseResult, error) { 961 var item *cxpb.TestCaseResult 962 if err := it.nextFunc(); err != nil { 963 return item, err 964 } 965 item = it.items[0] 966 it.items = it.items[1:] 967 return item, nil 968} 969 970func (it *TestCaseResultIterator) bufLen() int { 971 return len(it.items) 972} 973 974func (it *TestCaseResultIterator) takeBuf() interface{} { 975 b := it.items 976 it.items = nil 977 return b 978} 979