(t *testing.T)
| 107 | } |
| 108 | |
| 109 | func (s) TestNewServer_Success(t *testing.T) { |
| 110 | xdsCreds, err := xds.NewServerCredentials(xds.ServerOptions{FallbackCreds: insecure.NewCredentials()}) |
| 111 | if err != nil { |
| 112 | t.Fatalf("failed to create xds server credentials: %v", err) |
| 113 | } |
| 114 | |
| 115 | tests := []struct { |
| 116 | desc string |
| 117 | serverOpts []grpc.ServerOption |
| 118 | wantXDSCredsInUse bool |
| 119 | }{ |
| 120 | { |
| 121 | desc: "without_xds_creds", |
| 122 | serverOpts: []grpc.ServerOption{ |
| 123 | grpc.Creds(insecure.NewCredentials()), |
| 124 | BootstrapContentsForTesting(generateBootstrapContents(t, uuid.NewString(), nonExistentManagementServer)), |
| 125 | }, |
| 126 | }, |
| 127 | { |
| 128 | desc: "with_xds_creds", |
| 129 | serverOpts: []grpc.ServerOption{ |
| 130 | grpc.Creds(xdsCreds), |
| 131 | BootstrapContentsForTesting(generateBootstrapContents(t, uuid.NewString(), nonExistentManagementServer)), |
| 132 | }, |
| 133 | wantXDSCredsInUse: true, |
| 134 | }, |
| 135 | } |
| 136 | |
| 137 | for _, test := range tests { |
| 138 | t.Run(test.desc, func(t *testing.T) { |
| 139 | // The xds package adds a couple of server options (unary and stream |
| 140 | // interceptors) to the server options passed in by the user. |
| 141 | wantServerOpts := len(test.serverOpts) + 2 |
| 142 | |
| 143 | origNewGRPCServer := newGRPCServer |
| 144 | newGRPCServer = func(opts ...grpc.ServerOption) grpcServer { |
| 145 | if got := len(opts); got != wantServerOpts { |
| 146 | t.Fatalf("%d ServerOptions passed to grpc.Server, want %d", got, wantServerOpts) |
| 147 | } |
| 148 | // Verify that the user passed ServerOptions are forwarded as is. |
| 149 | if !reflect.DeepEqual(opts[2:], test.serverOpts) { |
| 150 | t.Fatalf("got ServerOptions %v, want %v", opts[2:], test.serverOpts) |
| 151 | } |
| 152 | return grpc.NewServer(opts...) |
| 153 | } |
| 154 | defer func() { |
| 155 | newGRPCServer = origNewGRPCServer |
| 156 | }() |
| 157 | |
| 158 | s, err := NewGRPCServer(test.serverOpts...) |
| 159 | if err != nil { |
| 160 | t.Fatalf("Failed to create an xDS enabled gRPC server: %v", err) |
| 161 | } |
| 162 | defer s.Stop() |
| 163 | }) |
| 164 | } |
| 165 | } |
| 166 |
nothing calls this directly
no test coverage detected