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 defaultTestCasesGRPCClientOptions() []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// internalTestCasesClient is an interface that defines the methods availaible from Dialogflow API. 209type internalTestCasesClient interface { 210 Close() error 211 setGoogleClientInfo(...string) 212 Connection() *grpc.ClientConn 213 ListTestCases(context.Context, *cxpb.ListTestCasesRequest, ...gax.CallOption) *TestCaseIterator 214 BatchDeleteTestCases(context.Context, *cxpb.BatchDeleteTestCasesRequest, ...gax.CallOption) error 215 GetTestCase(context.Context, *cxpb.GetTestCaseRequest, ...gax.CallOption) (*cxpb.TestCase, error) 216 CreateTestCase(context.Context, *cxpb.CreateTestCaseRequest, ...gax.CallOption) (*cxpb.TestCase, error) 217 UpdateTestCase(context.Context, *cxpb.UpdateTestCaseRequest, ...gax.CallOption) (*cxpb.TestCase, error) 218 RunTestCase(context.Context, *cxpb.RunTestCaseRequest, ...gax.CallOption) (*RunTestCaseOperation, error) 219 RunTestCaseOperation(name string) *RunTestCaseOperation 220 BatchRunTestCases(context.Context, *cxpb.BatchRunTestCasesRequest, ...gax.CallOption) (*BatchRunTestCasesOperation, error) 221 BatchRunTestCasesOperation(name string) *BatchRunTestCasesOperation 222 CalculateCoverage(context.Context, *cxpb.CalculateCoverageRequest, ...gax.CallOption) (*cxpb.CalculateCoverageResponse, error) 223 ImportTestCases(context.Context, *cxpb.ImportTestCasesRequest, ...gax.CallOption) (*ImportTestCasesOperation, error) 224 ImportTestCasesOperation(name string) *ImportTestCasesOperation 225 ExportTestCases(context.Context, *cxpb.ExportTestCasesRequest, ...gax.CallOption) (*ExportTestCasesOperation, error) 226 ExportTestCasesOperation(name string) *ExportTestCasesOperation 227 ListTestCaseResults(context.Context, *cxpb.ListTestCaseResultsRequest, ...gax.CallOption) *TestCaseResultIterator 228 GetTestCaseResult(context.Context, *cxpb.GetTestCaseResultRequest, ...gax.CallOption) (*cxpb.TestCaseResult, error) 229} 230 231// TestCasesClient is a client for interacting with Dialogflow API. 232// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 233// 234// Service for managing [Test Cases][google.cloud.dialogflow.cx.v3.TestCase] and 235// [Test Case Results][google.cloud.dialogflow.cx.v3.TestCaseResult]. 236type TestCasesClient struct { 237 // The internal transport-dependent client. 238 internalClient internalTestCasesClient 239 240 // The call options for this service. 241 CallOptions *TestCasesCallOptions 242 243 // LROClient is used internally to handle long-running operations. 244 // It is exposed so that its CallOptions can be modified if required. 245 // Users should not Close this client. 246 LROClient *lroauto.OperationsClient 247} 248 249// Wrapper methods routed to the internal client. 250 251// Close closes the connection to the API service. The user should invoke this when 252// the client is no longer required. 253func (c *TestCasesClient) Close() error { 254 return c.internalClient.Close() 255} 256 257// setGoogleClientInfo sets the name and version of the application in 258// the `x-goog-api-client` header passed on each request. Intended for 259// use by Google-written clients. 260func (c *TestCasesClient) setGoogleClientInfo(keyval ...string) { 261 c.internalClient.setGoogleClientInfo(keyval...) 262} 263 264// Connection returns a connection to the API service. 265// 266// Deprecated. 267func (c *TestCasesClient) Connection() *grpc.ClientConn { 268 return c.internalClient.Connection() 269} 270 271// ListTestCases fetches a list of test cases for a given agent. 272func (c *TestCasesClient) ListTestCases(ctx context.Context, req *cxpb.ListTestCasesRequest, opts ...gax.CallOption) *TestCaseIterator { 273 return c.internalClient.ListTestCases(ctx, req, opts...) 274} 275 276// BatchDeleteTestCases batch deletes test cases. 277func (c *TestCasesClient) BatchDeleteTestCases(ctx context.Context, req *cxpb.BatchDeleteTestCasesRequest, opts ...gax.CallOption) error { 278 return c.internalClient.BatchDeleteTestCases(ctx, req, opts...) 279} 280 281// GetTestCase gets a test case. 282func (c *TestCasesClient) GetTestCase(ctx context.Context, req *cxpb.GetTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 283 return c.internalClient.GetTestCase(ctx, req, opts...) 284} 285 286// CreateTestCase creates a test case for the given agent. 287func (c *TestCasesClient) CreateTestCase(ctx context.Context, req *cxpb.CreateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 288 return c.internalClient.CreateTestCase(ctx, req, opts...) 289} 290 291// UpdateTestCase updates the specified test case. 292func (c *TestCasesClient) UpdateTestCase(ctx context.Context, req *cxpb.UpdateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 293 return c.internalClient.UpdateTestCase(ctx, req, opts...) 294} 295 296// RunTestCase kicks off a test case run. 297func (c *TestCasesClient) RunTestCase(ctx context.Context, req *cxpb.RunTestCaseRequest, opts ...gax.CallOption) (*RunTestCaseOperation, error) { 298 return c.internalClient.RunTestCase(ctx, req, opts...) 299} 300 301// RunTestCaseOperation returns a new RunTestCaseOperation from a given name. 302// The name must be that of a previously created RunTestCaseOperation, possibly from a different process. 303func (c *TestCasesClient) RunTestCaseOperation(name string) *RunTestCaseOperation { 304 return c.internalClient.RunTestCaseOperation(name) 305} 306 307// BatchRunTestCases kicks off a batch run of test cases. 308func (c *TestCasesClient) BatchRunTestCases(ctx context.Context, req *cxpb.BatchRunTestCasesRequest, opts ...gax.CallOption) (*BatchRunTestCasesOperation, error) { 309 return c.internalClient.BatchRunTestCases(ctx, req, opts...) 310} 311 312// BatchRunTestCasesOperation returns a new BatchRunTestCasesOperation from a given name. 313// The name must be that of a previously created BatchRunTestCasesOperation, possibly from a different process. 314func (c *TestCasesClient) BatchRunTestCasesOperation(name string) *BatchRunTestCasesOperation { 315 return c.internalClient.BatchRunTestCasesOperation(name) 316} 317 318// CalculateCoverage calculates the test coverage for an agent. 319func (c *TestCasesClient) CalculateCoverage(ctx context.Context, req *cxpb.CalculateCoverageRequest, opts ...gax.CallOption) (*cxpb.CalculateCoverageResponse, error) { 320 return c.internalClient.CalculateCoverage(ctx, req, opts...) 321} 322 323// ImportTestCases imports the test cases from a Cloud Storage bucket or a local file. It 324// always creates new test cases and won’t overwite any existing ones. The 325// provided ID in the imported test case is neglected. 326func (c *TestCasesClient) ImportTestCases(ctx context.Context, req *cxpb.ImportTestCasesRequest, opts ...gax.CallOption) (*ImportTestCasesOperation, error) { 327 return c.internalClient.ImportTestCases(ctx, req, opts...) 328} 329 330// ImportTestCasesOperation returns a new ImportTestCasesOperation from a given name. 331// The name must be that of a previously created ImportTestCasesOperation, possibly from a different process. 332func (c *TestCasesClient) ImportTestCasesOperation(name string) *ImportTestCasesOperation { 333 return c.internalClient.ImportTestCasesOperation(name) 334} 335 336// ExportTestCases exports the test cases under the agent to a Cloud Storage bucket or a local 337// file. Filter can be applied to export a subset of test cases. 338func (c *TestCasesClient) ExportTestCases(ctx context.Context, req *cxpb.ExportTestCasesRequest, opts ...gax.CallOption) (*ExportTestCasesOperation, error) { 339 return c.internalClient.ExportTestCases(ctx, req, opts...) 340} 341 342// ExportTestCasesOperation returns a new ExportTestCasesOperation from a given name. 343// The name must be that of a previously created ExportTestCasesOperation, possibly from a different process. 344func (c *TestCasesClient) ExportTestCasesOperation(name string) *ExportTestCasesOperation { 345 return c.internalClient.ExportTestCasesOperation(name) 346} 347 348// ListTestCaseResults fetches a list of results for a given test case. 349func (c *TestCasesClient) ListTestCaseResults(ctx context.Context, req *cxpb.ListTestCaseResultsRequest, opts ...gax.CallOption) *TestCaseResultIterator { 350 return c.internalClient.ListTestCaseResults(ctx, req, opts...) 351} 352 353// GetTestCaseResult gets a test case result. 354func (c *TestCasesClient) GetTestCaseResult(ctx context.Context, req *cxpb.GetTestCaseResultRequest, opts ...gax.CallOption) (*cxpb.TestCaseResult, error) { 355 return c.internalClient.GetTestCaseResult(ctx, req, opts...) 356} 357 358// testCasesGRPCClient is a client for interacting with Dialogflow API over gRPC transport. 359// 360// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 361type testCasesGRPCClient struct { 362 // Connection pool of gRPC connections to the service. 363 connPool gtransport.ConnPool 364 365 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 366 disableDeadlines bool 367 368 // Points back to the CallOptions field of the containing TestCasesClient 369 CallOptions **TestCasesCallOptions 370 371 // The gRPC API client. 372 testCasesClient cxpb.TestCasesClient 373 374 // LROClient is used internally to handle long-running operations. 375 // It is exposed so that its CallOptions can be modified if required. 376 // Users should not Close this client. 377 LROClient **lroauto.OperationsClient 378 379 // The x-goog-* metadata to be sent with each request. 380 xGoogMetadata metadata.MD 381} 382 383// NewTestCasesClient creates a new test cases client based on gRPC. 384// The returned client must be Closed when it is done being used to clean up its underlying connections. 385// 386// Service for managing [Test Cases][google.cloud.dialogflow.cx.v3.TestCase] and 387// [Test Case Results][google.cloud.dialogflow.cx.v3.TestCaseResult]. 388func NewTestCasesClient(ctx context.Context, opts ...option.ClientOption) (*TestCasesClient, error) { 389 clientOpts := defaultTestCasesGRPCClientOptions() 390 if newTestCasesClientHook != nil { 391 hookOpts, err := newTestCasesClientHook(ctx, clientHookParams{}) 392 if err != nil { 393 return nil, err 394 } 395 clientOpts = append(clientOpts, hookOpts...) 396 } 397 398 disableDeadlines, err := checkDisableDeadlines() 399 if err != nil { 400 return nil, err 401 } 402 403 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 404 if err != nil { 405 return nil, err 406 } 407 client := TestCasesClient{CallOptions: defaultTestCasesCallOptions()} 408 409 c := &testCasesGRPCClient{ 410 connPool: connPool, 411 disableDeadlines: disableDeadlines, 412 testCasesClient: cxpb.NewTestCasesClient(connPool), 413 CallOptions: &client.CallOptions, 414 } 415 c.setGoogleClientInfo() 416 417 client.internalClient = c 418 419 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 420 if err != nil { 421 // This error "should not happen", since we are just reusing old connection pool 422 // and never actually need to dial. 423 // If this does happen, we could leak connp. However, we cannot close conn: 424 // If the user invoked the constructor with option.WithGRPCConn, 425 // we would close a connection that's still in use. 426 // TODO: investigate error conditions. 427 return nil, err 428 } 429 c.LROClient = &client.LROClient 430 return &client, nil 431} 432 433// Connection returns a connection to the API service. 434// 435// Deprecated. 436func (c *testCasesGRPCClient) Connection() *grpc.ClientConn { 437 return c.connPool.Conn() 438} 439 440// setGoogleClientInfo sets the name and version of the application in 441// the `x-goog-api-client` header passed on each request. Intended for 442// use by Google-written clients. 443func (c *testCasesGRPCClient) setGoogleClientInfo(keyval ...string) { 444 kv := append([]string{"gl-go", versionGo()}, keyval...) 445 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 446 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 447} 448 449// Close closes the connection to the API service. The user should invoke this when 450// the client is no longer required. 451func (c *testCasesGRPCClient) Close() error { 452 return c.connPool.Close() 453} 454 455func (c *testCasesGRPCClient) ListTestCases(ctx context.Context, req *cxpb.ListTestCasesRequest, opts ...gax.CallOption) *TestCaseIterator { 456 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 457 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 458 opts = append((*c.CallOptions).ListTestCases[0:len((*c.CallOptions).ListTestCases):len((*c.CallOptions).ListTestCases)], opts...) 459 it := &TestCaseIterator{} 460 req = proto.Clone(req).(*cxpb.ListTestCasesRequest) 461 it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TestCase, string, error) { 462 var resp *cxpb.ListTestCasesResponse 463 req.PageToken = pageToken 464 if pageSize > math.MaxInt32 { 465 req.PageSize = math.MaxInt32 466 } else { 467 req.PageSize = int32(pageSize) 468 } 469 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 470 var err error 471 resp, err = c.testCasesClient.ListTestCases(ctx, req, settings.GRPC...) 472 return err 473 }, opts...) 474 if err != nil { 475 return nil, "", err 476 } 477 478 it.Response = resp 479 return resp.GetTestCases(), resp.GetNextPageToken(), nil 480 } 481 fetch := func(pageSize int, pageToken string) (string, error) { 482 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 483 if err != nil { 484 return "", err 485 } 486 it.items = append(it.items, items...) 487 return nextPageToken, nil 488 } 489 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 490 it.pageInfo.MaxSize = int(req.GetPageSize()) 491 it.pageInfo.Token = req.GetPageToken() 492 return it 493} 494 495func (c *testCasesGRPCClient) BatchDeleteTestCases(ctx context.Context, req *cxpb.BatchDeleteTestCasesRequest, opts ...gax.CallOption) error { 496 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 497 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 498 defer cancel() 499 ctx = cctx 500 } 501 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 502 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 503 opts = append((*c.CallOptions).BatchDeleteTestCases[0:len((*c.CallOptions).BatchDeleteTestCases):len((*c.CallOptions).BatchDeleteTestCases)], opts...) 504 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 505 var err error 506 _, err = c.testCasesClient.BatchDeleteTestCases(ctx, req, settings.GRPC...) 507 return err 508 }, opts...) 509 return err 510} 511 512func (c *testCasesGRPCClient) GetTestCase(ctx context.Context, req *cxpb.GetTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 513 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 514 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 515 defer cancel() 516 ctx = cctx 517 } 518 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 519 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 520 opts = append((*c.CallOptions).GetTestCase[0:len((*c.CallOptions).GetTestCase):len((*c.CallOptions).GetTestCase)], opts...) 521 var resp *cxpb.TestCase 522 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 523 var err error 524 resp, err = c.testCasesClient.GetTestCase(ctx, req, settings.GRPC...) 525 return err 526 }, opts...) 527 if err != nil { 528 return nil, err 529 } 530 return resp, nil 531} 532 533func (c *testCasesGRPCClient) CreateTestCase(ctx context.Context, req *cxpb.CreateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 534 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 535 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 536 defer cancel() 537 ctx = cctx 538 } 539 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 540 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 541 opts = append((*c.CallOptions).CreateTestCase[0:len((*c.CallOptions).CreateTestCase):len((*c.CallOptions).CreateTestCase)], opts...) 542 var resp *cxpb.TestCase 543 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 544 var err error 545 resp, err = c.testCasesClient.CreateTestCase(ctx, req, settings.GRPC...) 546 return err 547 }, opts...) 548 if err != nil { 549 return nil, err 550 } 551 return resp, nil 552} 553 554func (c *testCasesGRPCClient) UpdateTestCase(ctx context.Context, req *cxpb.UpdateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { 555 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 556 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 557 defer cancel() 558 ctx = cctx 559 } 560 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "test_case.name", url.QueryEscape(req.GetTestCase().GetName()))) 561 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 562 opts = append((*c.CallOptions).UpdateTestCase[0:len((*c.CallOptions).UpdateTestCase):len((*c.CallOptions).UpdateTestCase)], opts...) 563 var resp *cxpb.TestCase 564 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 565 var err error 566 resp, err = c.testCasesClient.UpdateTestCase(ctx, req, settings.GRPC...) 567 return err 568 }, opts...) 569 if err != nil { 570 return nil, err 571 } 572 return resp, nil 573} 574 575func (c *testCasesGRPCClient) RunTestCase(ctx context.Context, req *cxpb.RunTestCaseRequest, opts ...gax.CallOption) (*RunTestCaseOperation, error) { 576 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 577 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 578 defer cancel() 579 ctx = cctx 580 } 581 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 582 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 583 opts = append((*c.CallOptions).RunTestCase[0:len((*c.CallOptions).RunTestCase):len((*c.CallOptions).RunTestCase)], opts...) 584 var resp *longrunningpb.Operation 585 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 586 var err error 587 resp, err = c.testCasesClient.RunTestCase(ctx, req, settings.GRPC...) 588 return err 589 }, opts...) 590 if err != nil { 591 return nil, err 592 } 593 return &RunTestCaseOperation{ 594 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 595 }, nil 596} 597 598func (c *testCasesGRPCClient) BatchRunTestCases(ctx context.Context, req *cxpb.BatchRunTestCasesRequest, opts ...gax.CallOption) (*BatchRunTestCasesOperation, error) { 599 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 600 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 601 defer cancel() 602 ctx = cctx 603 } 604 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 605 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 606 opts = append((*c.CallOptions).BatchRunTestCases[0:len((*c.CallOptions).BatchRunTestCases):len((*c.CallOptions).BatchRunTestCases)], opts...) 607 var resp *longrunningpb.Operation 608 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 609 var err error 610 resp, err = c.testCasesClient.BatchRunTestCases(ctx, req, settings.GRPC...) 611 return err 612 }, opts...) 613 if err != nil { 614 return nil, err 615 } 616 return &BatchRunTestCasesOperation{ 617 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 618 }, nil 619} 620 621func (c *testCasesGRPCClient) CalculateCoverage(ctx context.Context, req *cxpb.CalculateCoverageRequest, opts ...gax.CallOption) (*cxpb.CalculateCoverageResponse, error) { 622 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 623 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 624 defer cancel() 625 ctx = cctx 626 } 627 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "agent", url.QueryEscape(req.GetAgent()))) 628 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 629 opts = append((*c.CallOptions).CalculateCoverage[0:len((*c.CallOptions).CalculateCoverage):len((*c.CallOptions).CalculateCoverage)], opts...) 630 var resp *cxpb.CalculateCoverageResponse 631 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 632 var err error 633 resp, err = c.testCasesClient.CalculateCoverage(ctx, req, settings.GRPC...) 634 return err 635 }, opts...) 636 if err != nil { 637 return nil, err 638 } 639 return resp, nil 640} 641 642func (c *testCasesGRPCClient) ImportTestCases(ctx context.Context, req *cxpb.ImportTestCasesRequest, opts ...gax.CallOption) (*ImportTestCasesOperation, error) { 643 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 644 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 645 defer cancel() 646 ctx = cctx 647 } 648 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 649 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 650 opts = append((*c.CallOptions).ImportTestCases[0:len((*c.CallOptions).ImportTestCases):len((*c.CallOptions).ImportTestCases)], opts...) 651 var resp *longrunningpb.Operation 652 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 653 var err error 654 resp, err = c.testCasesClient.ImportTestCases(ctx, req, settings.GRPC...) 655 return err 656 }, opts...) 657 if err != nil { 658 return nil, err 659 } 660 return &ImportTestCasesOperation{ 661 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 662 }, nil 663} 664 665func (c *testCasesGRPCClient) ExportTestCases(ctx context.Context, req *cxpb.ExportTestCasesRequest, opts ...gax.CallOption) (*ExportTestCasesOperation, error) { 666 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 667 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 668 defer cancel() 669 ctx = cctx 670 } 671 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 672 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 673 opts = append((*c.CallOptions).ExportTestCases[0:len((*c.CallOptions).ExportTestCases):len((*c.CallOptions).ExportTestCases)], opts...) 674 var resp *longrunningpb.Operation 675 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 676 var err error 677 resp, err = c.testCasesClient.ExportTestCases(ctx, req, settings.GRPC...) 678 return err 679 }, opts...) 680 if err != nil { 681 return nil, err 682 } 683 return &ExportTestCasesOperation{ 684 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 685 }, nil 686} 687 688func (c *testCasesGRPCClient) ListTestCaseResults(ctx context.Context, req *cxpb.ListTestCaseResultsRequest, opts ...gax.CallOption) *TestCaseResultIterator { 689 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 690 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 691 opts = append((*c.CallOptions).ListTestCaseResults[0:len((*c.CallOptions).ListTestCaseResults):len((*c.CallOptions).ListTestCaseResults)], opts...) 692 it := &TestCaseResultIterator{} 693 req = proto.Clone(req).(*cxpb.ListTestCaseResultsRequest) 694 it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TestCaseResult, string, error) { 695 var resp *cxpb.ListTestCaseResultsResponse 696 req.PageToken = pageToken 697 if pageSize > math.MaxInt32 { 698 req.PageSize = math.MaxInt32 699 } else { 700 req.PageSize = int32(pageSize) 701 } 702 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 703 var err error 704 resp, err = c.testCasesClient.ListTestCaseResults(ctx, req, settings.GRPC...) 705 return err 706 }, opts...) 707 if err != nil { 708 return nil, "", err 709 } 710 711 it.Response = resp 712 return resp.GetTestCaseResults(), resp.GetNextPageToken(), nil 713 } 714 fetch := func(pageSize int, pageToken string) (string, error) { 715 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 716 if err != nil { 717 return "", err 718 } 719 it.items = append(it.items, items...) 720 return nextPageToken, nil 721 } 722 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 723 it.pageInfo.MaxSize = int(req.GetPageSize()) 724 it.pageInfo.Token = req.GetPageToken() 725 return it 726} 727 728func (c *testCasesGRPCClient) GetTestCaseResult(ctx context.Context, req *cxpb.GetTestCaseResultRequest, opts ...gax.CallOption) (*cxpb.TestCaseResult, error) { 729 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 730 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 731 defer cancel() 732 ctx = cctx 733 } 734 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 735 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 736 opts = append((*c.CallOptions).GetTestCaseResult[0:len((*c.CallOptions).GetTestCaseResult):len((*c.CallOptions).GetTestCaseResult)], opts...) 737 var resp *cxpb.TestCaseResult 738 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 739 var err error 740 resp, err = c.testCasesClient.GetTestCaseResult(ctx, req, settings.GRPC...) 741 return err 742 }, opts...) 743 if err != nil { 744 return nil, err 745 } 746 return resp, nil 747} 748 749// BatchRunTestCasesOperation manages a long-running operation from BatchRunTestCases. 750type BatchRunTestCasesOperation struct { 751 lro *longrunning.Operation 752} 753 754// BatchRunTestCasesOperation returns a new BatchRunTestCasesOperation from a given name. 755// The name must be that of a previously created BatchRunTestCasesOperation, possibly from a different process. 756func (c *testCasesGRPCClient) BatchRunTestCasesOperation(name string) *BatchRunTestCasesOperation { 757 return &BatchRunTestCasesOperation{ 758 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 759 } 760} 761 762// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 763// 764// See documentation of Poll for error-handling information. 765func (op *BatchRunTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.BatchRunTestCasesResponse, error) { 766 var resp cxpb.BatchRunTestCasesResponse 767 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 768 return nil, err 769 } 770 return &resp, nil 771} 772 773// Poll fetches the latest state of the long-running operation. 774// 775// Poll also fetches the latest metadata, which can be retrieved by Metadata. 776// 777// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 778// the operation has completed with failure, the error is returned and op.Done will return true. 779// If Poll succeeds and the operation has completed successfully, 780// op.Done will return true, and the response of the operation is returned. 781// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 782func (op *BatchRunTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.BatchRunTestCasesResponse, error) { 783 var resp cxpb.BatchRunTestCasesResponse 784 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 785 return nil, err 786 } 787 if !op.Done() { 788 return nil, nil 789 } 790 return &resp, nil 791} 792 793// Metadata returns metadata associated with the long-running operation. 794// Metadata itself does not contact the server, but Poll does. 795// To get the latest metadata, call this method after a successful call to Poll. 796// If the metadata is not available, the returned metadata and error are both nil. 797func (op *BatchRunTestCasesOperation) Metadata() (*cxpb.BatchRunTestCasesMetadata, error) { 798 var meta cxpb.BatchRunTestCasesMetadata 799 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 800 return nil, nil 801 } else if err != nil { 802 return nil, err 803 } 804 return &meta, nil 805} 806 807// Done reports whether the long-running operation has completed. 808func (op *BatchRunTestCasesOperation) Done() bool { 809 return op.lro.Done() 810} 811 812// Name returns the name of the long-running operation. 813// The name is assigned by the server and is unique within the service from which the operation is created. 814func (op *BatchRunTestCasesOperation) Name() string { 815 return op.lro.Name() 816} 817 818// ExportTestCasesOperation manages a long-running operation from ExportTestCases. 819type ExportTestCasesOperation struct { 820 lro *longrunning.Operation 821} 822 823// ExportTestCasesOperation returns a new ExportTestCasesOperation from a given name. 824// The name must be that of a previously created ExportTestCasesOperation, possibly from a different process. 825func (c *testCasesGRPCClient) ExportTestCasesOperation(name string) *ExportTestCasesOperation { 826 return &ExportTestCasesOperation{ 827 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 828 } 829} 830 831// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 832// 833// See documentation of Poll for error-handling information. 834func (op *ExportTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportTestCasesResponse, error) { 835 var resp cxpb.ExportTestCasesResponse 836 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 837 return nil, err 838 } 839 return &resp, nil 840} 841 842// Poll fetches the latest state of the long-running operation. 843// 844// Poll also fetches the latest metadata, which can be retrieved by Metadata. 845// 846// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 847// the operation has completed with failure, the error is returned and op.Done will return true. 848// If Poll succeeds and the operation has completed successfully, 849// op.Done will return true, and the response of the operation is returned. 850// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 851func (op *ExportTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportTestCasesResponse, error) { 852 var resp cxpb.ExportTestCasesResponse 853 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 854 return nil, err 855 } 856 if !op.Done() { 857 return nil, nil 858 } 859 return &resp, nil 860} 861 862// Metadata returns metadata associated with the long-running operation. 863// Metadata itself does not contact the server, but Poll does. 864// To get the latest metadata, call this method after a successful call to Poll. 865// If the metadata is not available, the returned metadata and error are both nil. 866func (op *ExportTestCasesOperation) Metadata() (*cxpb.ExportTestCasesMetadata, error) { 867 var meta cxpb.ExportTestCasesMetadata 868 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 869 return nil, nil 870 } else if err != nil { 871 return nil, err 872 } 873 return &meta, nil 874} 875 876// Done reports whether the long-running operation has completed. 877func (op *ExportTestCasesOperation) Done() bool { 878 return op.lro.Done() 879} 880 881// Name returns the name of the long-running operation. 882// The name is assigned by the server and is unique within the service from which the operation is created. 883func (op *ExportTestCasesOperation) Name() string { 884 return op.lro.Name() 885} 886 887// ImportTestCasesOperation manages a long-running operation from ImportTestCases. 888type ImportTestCasesOperation struct { 889 lro *longrunning.Operation 890} 891 892// ImportTestCasesOperation returns a new ImportTestCasesOperation from a given name. 893// The name must be that of a previously created ImportTestCasesOperation, possibly from a different process. 894func (c *testCasesGRPCClient) ImportTestCasesOperation(name string) *ImportTestCasesOperation { 895 return &ImportTestCasesOperation{ 896 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 897 } 898} 899 900// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 901// 902// See documentation of Poll for error-handling information. 903func (op *ImportTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ImportTestCasesResponse, error) { 904 var resp cxpb.ImportTestCasesResponse 905 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 906 return nil, err 907 } 908 return &resp, nil 909} 910 911// Poll fetches the latest state of the long-running operation. 912// 913// Poll also fetches the latest metadata, which can be retrieved by Metadata. 914// 915// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 916// the operation has completed with failure, the error is returned and op.Done will return true. 917// If Poll succeeds and the operation has completed successfully, 918// op.Done will return true, and the response of the operation is returned. 919// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 920func (op *ImportTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ImportTestCasesResponse, error) { 921 var resp cxpb.ImportTestCasesResponse 922 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 923 return nil, err 924 } 925 if !op.Done() { 926 return nil, nil 927 } 928 return &resp, nil 929} 930 931// Metadata returns metadata associated with the long-running operation. 932// Metadata itself does not contact the server, but Poll does. 933// To get the latest metadata, call this method after a successful call to Poll. 934// If the metadata is not available, the returned metadata and error are both nil. 935func (op *ImportTestCasesOperation) Metadata() (*cxpb.ImportTestCasesMetadata, error) { 936 var meta cxpb.ImportTestCasesMetadata 937 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 938 return nil, nil 939 } else if err != nil { 940 return nil, err 941 } 942 return &meta, nil 943} 944 945// Done reports whether the long-running operation has completed. 946func (op *ImportTestCasesOperation) Done() bool { 947 return op.lro.Done() 948} 949 950// Name returns the name of the long-running operation. 951// The name is assigned by the server and is unique within the service from which the operation is created. 952func (op *ImportTestCasesOperation) Name() string { 953 return op.lro.Name() 954} 955 956// RunTestCaseOperation manages a long-running operation from RunTestCase. 957type RunTestCaseOperation struct { 958 lro *longrunning.Operation 959} 960 961// RunTestCaseOperation returns a new RunTestCaseOperation from a given name. 962// The name must be that of a previously created RunTestCaseOperation, possibly from a different process. 963func (c *testCasesGRPCClient) RunTestCaseOperation(name string) *RunTestCaseOperation { 964 return &RunTestCaseOperation{ 965 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 966 } 967} 968 969// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 970// 971// See documentation of Poll for error-handling information. 972func (op *RunTestCaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.RunTestCaseResponse, error) { 973 var resp cxpb.RunTestCaseResponse 974 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 975 return nil, err 976 } 977 return &resp, nil 978} 979 980// Poll fetches the latest state of the long-running operation. 981// 982// Poll also fetches the latest metadata, which can be retrieved by Metadata. 983// 984// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 985// the operation has completed with failure, the error is returned and op.Done will return true. 986// If Poll succeeds and the operation has completed successfully, 987// op.Done will return true, and the response of the operation is returned. 988// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 989func (op *RunTestCaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.RunTestCaseResponse, error) { 990 var resp cxpb.RunTestCaseResponse 991 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 992 return nil, err 993 } 994 if !op.Done() { 995 return nil, nil 996 } 997 return &resp, nil 998} 999 1000// Metadata returns metadata associated with the long-running operation. 1001// Metadata itself does not contact the server, but Poll does. 1002// To get the latest metadata, call this method after a successful call to Poll. 1003// If the metadata is not available, the returned metadata and error are both nil. 1004func (op *RunTestCaseOperation) Metadata() (*cxpb.RunTestCaseMetadata, error) { 1005 var meta cxpb.RunTestCaseMetadata 1006 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1007 return nil, nil 1008 } else if err != nil { 1009 return nil, err 1010 } 1011 return &meta, nil 1012} 1013 1014// Done reports whether the long-running operation has completed. 1015func (op *RunTestCaseOperation) Done() bool { 1016 return op.lro.Done() 1017} 1018 1019// Name returns the name of the long-running operation. 1020// The name is assigned by the server and is unique within the service from which the operation is created. 1021func (op *RunTestCaseOperation) Name() string { 1022 return op.lro.Name() 1023} 1024 1025// TestCaseIterator manages a stream of *cxpb.TestCase. 1026type TestCaseIterator struct { 1027 items []*cxpb.TestCase 1028 pageInfo *iterator.PageInfo 1029 nextFunc func() error 1030 1031 // Response is the raw response for the current page. 1032 // It must be cast to the RPC response type. 1033 // Calling Next() or InternalFetch() updates this value. 1034 Response interface{} 1035 1036 // InternalFetch is for use by the Google Cloud Libraries only. 1037 // It is not part of the stable interface of this package. 1038 // 1039 // InternalFetch returns results from a single call to the underlying RPC. 1040 // The number of results is no greater than pageSize. 1041 // If there are no more results, nextPageToken is empty and err is nil. 1042 InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TestCase, nextPageToken string, err error) 1043} 1044 1045// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1046func (it *TestCaseIterator) PageInfo() *iterator.PageInfo { 1047 return it.pageInfo 1048} 1049 1050// Next returns the next result. Its second return value is iterator.Done if there are no more 1051// results. Once Next returns Done, all subsequent calls will return Done. 1052func (it *TestCaseIterator) Next() (*cxpb.TestCase, error) { 1053 var item *cxpb.TestCase 1054 if err := it.nextFunc(); err != nil { 1055 return item, err 1056 } 1057 item = it.items[0] 1058 it.items = it.items[1:] 1059 return item, nil 1060} 1061 1062func (it *TestCaseIterator) bufLen() int { 1063 return len(it.items) 1064} 1065 1066func (it *TestCaseIterator) takeBuf() interface{} { 1067 b := it.items 1068 it.items = nil 1069 return b 1070} 1071 1072// TestCaseResultIterator manages a stream of *cxpb.TestCaseResult. 1073type TestCaseResultIterator struct { 1074 items []*cxpb.TestCaseResult 1075 pageInfo *iterator.PageInfo 1076 nextFunc func() error 1077 1078 // Response is the raw response for the current page. 1079 // It must be cast to the RPC response type. 1080 // Calling Next() or InternalFetch() updates this value. 1081 Response interface{} 1082 1083 // InternalFetch is for use by the Google Cloud Libraries only. 1084 // It is not part of the stable interface of this package. 1085 // 1086 // InternalFetch returns results from a single call to the underlying RPC. 1087 // The number of results is no greater than pageSize. 1088 // If there are no more results, nextPageToken is empty and err is nil. 1089 InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TestCaseResult, nextPageToken string, err error) 1090} 1091 1092// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1093func (it *TestCaseResultIterator) PageInfo() *iterator.PageInfo { 1094 return it.pageInfo 1095} 1096 1097// Next returns the next result. Its second return value is iterator.Done if there are no more 1098// results. Once Next returns Done, all subsequent calls will return Done. 1099func (it *TestCaseResultIterator) Next() (*cxpb.TestCaseResult, error) { 1100 var item *cxpb.TestCaseResult 1101 if err := it.nextFunc(); err != nil { 1102 return item, err 1103 } 1104 item = it.items[0] 1105 it.items = it.items[1:] 1106 return item, nil 1107} 1108 1109func (it *TestCaseResultIterator) bufLen() int { 1110 return len(it.items) 1111} 1112 1113func (it *TestCaseResultIterator) takeBuf() interface{} { 1114 b := it.items 1115 it.items = nil 1116 return b 1117} 1118