MCPcopy
hub / github.com/grpc/grpc-go / TestAuthorityInBuildOptions

Method TestAuthorityInBuildOptions

test/balancer_test.go:684–794  ·  view source on GitHub ↗

TestAuthorityInBuildOptions tests that the Authority field in balancer.BuildOptions is setup correctly from gRPC.

(t *testing.T)

Source from the content-addressed store, hash-verified

682// TestAuthorityInBuildOptions tests that the Authority field in
683// balancer.BuildOptions is setup correctly from gRPC.
684func (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

Callers

nothing calls this directly

Calls 15

ConnectMethod · 0.95
EmptyCallMethod · 0.95
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithAuthorityFunction · 0.92
LocalTCPListenerFunction · 0.92
NewServerFunction · 0.92
StartTestServiceFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
NewClientFunction · 0.92

Tested by

no test coverage detected