TestAuthorityInBuildOptions tests that the Authority field in balancer.BuildOptions is setup correctly from gRPC.
(t *testing.T)
| 682 | // TestAuthorityInBuildOptions tests that the Authority field in |
| 683 | // balancer.BuildOptions is setup correctly from gRPC. |
| 684 | func (s) TestAuthorityInBuildOptions(t *testing.T) { |
| 685 | const dialTarget = "test.server" |
| 686 | |
| 687 | tests := []struct { |
| 688 | name string |
| 689 | dopts []grpc.DialOption |
| 690 | wantAuthority string |
| 691 | }{ |
| 692 | { |
| 693 | name: "authority from dial target", |
| 694 | dopts: []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}, |
| 695 | wantAuthority: dialTarget, |
| 696 | }, |
| 697 | { |
| 698 | name: "authority from dial option", |
| 699 | dopts: []grpc.DialOption{ |
| 700 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 701 | grpc.WithAuthority("authority-override"), |
| 702 | }, |
| 703 | wantAuthority: "authority-override", |
| 704 | }, |
| 705 | { |
| 706 | name: "authority from transport creds", |
| 707 | dopts: []grpc.DialOption{grpc.WithTransportCredentials(&authorityOverrideTransportCreds{authorityOverride: "authority-override-from-transport-creds"})}, |
| 708 | wantAuthority: "authority-override-from-transport-creds", |
| 709 | }, |
| 710 | } |
| 711 | |
| 712 | for _, test := range tests { |
| 713 | t.Run(test.name, func(t *testing.T) { |
| 714 | authorityCh := make(chan string, 1) |
| 715 | bf := stub.BalancerFuncs{ |
| 716 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 717 | select { |
| 718 | case authorityCh <- bd.BuildOptions.Authority: |
| 719 | default: |
| 720 | } |
| 721 | |
| 722 | addrs := ccs.ResolverState.Addresses |
| 723 | if len(addrs) == 0 { |
| 724 | return nil |
| 725 | } |
| 726 | |
| 727 | // Only use the first address. |
| 728 | var sc balancer.SubConn |
| 729 | sc, err := bd.ClientConn.NewSubConn([]resolver.Address{addrs[0]}, balancer.NewSubConnOptions{ |
| 730 | StateListener: func(state balancer.SubConnState) { |
| 731 | bd.ClientConn.UpdateState(balancer.State{ConnectivityState: state.ConnectivityState, Picker: &aiPicker{result: balancer.PickResult{SubConn: sc}, err: state.ConnectionError}}) |
| 732 | }, |
| 733 | }) |
| 734 | if err != nil { |
| 735 | return err |
| 736 | } |
| 737 | sc.Connect() |
| 738 | return nil |
| 739 | }, |
| 740 | } |
| 741 | balancerName := "stub-balancer-" + test.name |
nothing calls this directly
no test coverage detected