TestBalancerGroupBuildOptions verifies that the balancer.BuildOptions passed to the balancergroup at creation time is passed to child policies.
(t *testing.T)
| 447 | // TestBalancerGroupBuildOptions verifies that the balancer.BuildOptions passed |
| 448 | // to the balancergroup at creation time is passed to child policies. |
| 449 | func (s) TestBalancerGroupBuildOptions(t *testing.T) { |
| 450 | const ( |
| 451 | balancerName = "stubBalancer-TestBalancerGroupBuildOptions" |
| 452 | userAgent = "ua" |
| 453 | ) |
| 454 | |
| 455 | // Setup the stub balancer such that we can read the build options passed to |
| 456 | // it in the UpdateClientConnState method. |
| 457 | bOpts := balancer.BuildOptions{ |
| 458 | DialCreds: insecure.NewCredentials(), |
| 459 | ChannelzParent: channelz.RegisterChannel(nil, "test channel"), |
| 460 | CustomUserAgent: userAgent, |
| 461 | } |
| 462 | stub.Register(balancerName, stub.BalancerFuncs{ |
| 463 | UpdateClientConnState: func(bd *stub.BalancerData, _ balancer.ClientConnState) error { |
| 464 | if bd.BuildOptions.DialCreds != bOpts.DialCreds || bd.BuildOptions.ChannelzParent != bOpts.ChannelzParent || bd.BuildOptions.CustomUserAgent != bOpts.CustomUserAgent { |
| 465 | return fmt.Errorf("buildOptions in child balancer: %v, want %v", bd, bOpts) |
| 466 | } |
| 467 | return nil |
| 468 | }, |
| 469 | }) |
| 470 | cc := testutils.NewBalancerClientConn(t) |
| 471 | bg := balancergroup.New(balancergroup.Options{ |
| 472 | CC: cc, |
| 473 | BuildOpts: bOpts, |
| 474 | StateAggregator: nil, |
| 475 | Logger: nil, |
| 476 | }) |
| 477 | |
| 478 | // Add the stub balancer build above as a child policy. |
| 479 | balancerBuilder := balancer.Get(balancerName) |
| 480 | bg.Add(testBalancerIDs[0], balancerBuilder) |
| 481 | |
| 482 | // Send an empty clientConn state change. This should trigger the |
| 483 | // verification of the buildOptions being passed to the child policy. |
| 484 | if err := bg.UpdateClientConnState(testBalancerIDs[0], balancer.ClientConnState{}); err != nil { |
| 485 | t.Fatal(err) |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | func (s) TestBalancerGroup_UpdateClientConnState_AfterClose(t *testing.T) { |
| 490 | balancerName := t.Name() |
nothing calls this directly
no test coverage detected