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

Method TestClientConnAuthority

clientconn_authority_test.go:31–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func (s) TestClientConnAuthority(t *testing.T) {
32 serverNameOverride := "over.write.server.name"
33 creds, err := credentials.NewClientTLSFromFile(testdata.Path("x509/server_ca_cert.pem"), serverNameOverride)
34 if err != nil {
35 t.Fatalf("credentials.NewClientTLSFromFile(_, %q) failed: %v", err, serverNameOverride)
36 }
37
38 tests := []struct {
39 name string
40 target string
41 opts []DialOption
42 wantAuthority string
43 }{
44 {
45 name: "default",
46 target: "Non-Existent.Server:8080",
47 opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
48 wantAuthority: "Non-Existent.Server:8080",
49 },
50 {
51 name: "override-via-creds",
52 target: "Non-Existent.Server:8080",
53 opts: []DialOption{WithTransportCredentials(creds)},
54 wantAuthority: serverNameOverride,
55 },
56 {
57 name: "override-via-WithAuthority",
58 target: "Non-Existent.Server:8080",
59 opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithAuthority("authority-override")},
60 wantAuthority: "authority-override",
61 },
62 {
63 name: "override-via-creds-and-WithAuthority",
64 target: "Non-Existent.Server:8080",
65 opts: []DialOption{WithTransportCredentials(creds), WithAuthority(serverNameOverride)},
66 wantAuthority: serverNameOverride,
67 },
68 {
69 name: "unix relative",
70 target: "unix:sock.sock",
71 opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
72 wantAuthority: "localhost",
73 },
74 {
75 name: "unix relative with custom dialer",
76 target: "unix:sock.sock",
77 opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
78 return (&net.Dialer{}).DialContext(ctx, "", addr)
79 })},
80 wantAuthority: "localhost",
81 },
82 {
83 name: "unix absolute",
84 target: "unix:/sock.sock",
85 opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
86 wantAuthority: "localhost",
87 },
88 {

Callers

nothing calls this directly

Calls 10

NewClientTLSFromFileFunction · 0.92
PathFunction · 0.92
NewCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.85
WithAuthorityFunction · 0.85
WithContextDialerFunction · 0.85
NewClientFunction · 0.70
FatalfMethod · 0.65
CloseMethod · 0.65
DialContextMethod · 0.45

Tested by

no test coverage detected