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

Method TestBuild_Failure

internal/xds/clients/grpctransport/grpc_transport_test.go:185–253  ·  view source on GitHub ↗

TestBuild_Failure verifies that the Builder returns error when incorrect ServerIdentifier is provided. It covers the following scenarios: - ServerURI is empty. - Extensions is nil. - Extensions is not ServerIdentifierExtension. - Credentials are nil.

(t *testing.T)

Source from the content-addressed store, hash-verified

183// - Extensions is not ServerIdentifierExtension.
184// - Credentials are nil.
185func (s) TestBuild_Failure(t *testing.T) {
186 tests := []struct {
187 name string
188 serverID clients.ServerIdentifier
189 }{
190 {
191 name: "ServerURI is empty",
192 serverID: clients.ServerIdentifier{
193 ServerURI: "",
194 Extensions: ServerIdentifierExtension{ConfigName: "local"},
195 },
196 },
197 {
198 name: "Extensions is nil",
199 serverID: clients.ServerIdentifier{ServerURI: "server-address"},
200 },
201 {
202 name: "Extensions is not a ServerIdentifierExtension",
203 serverID: clients.ServerIdentifier{
204 ServerURI: "server-address",
205 Extensions: 1,
206 },
207 },
208 {
209 name: "ServerIdentifierExtension without ConfigName",
210 serverID: clients.ServerIdentifier{
211 ServerURI: "server-address",
212 Extensions: ServerIdentifierExtension{},
213 },
214 },
215 {
216 name: "ServerIdentifierExtension ConfigName is not present",
217 serverID: clients.ServerIdentifier{
218 ServerURI: "server-address",
219 Extensions: ServerIdentifierExtension{ConfigName: "unknown"},
220 },
221 },
222 {
223 name: "ServerIdentifierExtension ConfigName maps to nil credentials",
224 serverID: clients.ServerIdentifier{
225 ServerURI: "server-address",
226 Extensions: ServerIdentifierExtension{ConfigName: "nil-credentials"},
227 },
228 },
229 {
230 name: "ServerIdentifierExtension is added as pointer",
231 serverID: clients.ServerIdentifier{
232 ServerURI: "server-address",
233 Extensions: &ServerIdentifierExtension{ConfigName: "local"},
234 },
235 },
236 }
237 for _, test := range tests {
238 t.Run(test.name, func(t *testing.T) {
239 configs := map[string]Config{
240 "local": {Credentials: &testCredentials{transportCredentials: local.NewCredentials()}},
241 "nil-credentials": {Credentials: nil},
242 }

Callers

nothing calls this directly

Calls 4

BuildMethod · 0.95
NewCredentialsFunction · 0.92
NewBuilderFunction · 0.70
FatalfMethod · 0.65

Tested by

no test coverage detected