MCPcopy
hub / github.com/cloudflare/cloudflared / TestNewProtocolSelector

Function TestNewProtocolSelector

connection/protocol_test.go:29–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestNewProtocolSelector(t *testing.T) {
30 tests := []struct {
31 name string
32 protocol string
33 tunnelTokenProvided bool
34 expectedProtocol Protocol
35 hasFallback bool
36 expectedFallback Protocol
37 wantErr bool
38 }{
39 {
40 name: "named tunnel with unknown protocol",
41 protocol: "unknown",
42 wantErr: true,
43 },
44 {
45 name: "named tunnel with h2mux: force to http2",
46 protocol: "h2mux",
47 expectedProtocol: HTTP2,
48 },
49 {
50 name: "named tunnel with http2: no fallback",
51 protocol: "http2",
52 expectedProtocol: HTTP2,
53 },
54 {
55 name: "named tunnel with auto: quic",
56 protocol: AutoSelectFlag,
57 expectedProtocol: QUIC,
58 hasFallback: true,
59 expectedFallback: HTTP2,
60 },
61 }
62
63 fetcher := dynamicMockFetcher{
64 protocolPercents: edgediscovery.ProtocolPercents{},
65 }
66
67 for _, test := range tests {
68 t.Run(test.name, func(t *testing.T) {
69 selector, err := NewProtocolSelector(test.protocol, testAccountTag, test.tunnelTokenProvided, fetcher.fetch(), ResolveTTL, &log)
70 if test.wantErr {
71 assert.Error(t, err, "test %s failed", test.name)
72 } else {
73 require.NoError(t, err, "test %s failed", test.name)
74 assert.Equalf(t, test.expectedProtocol, selector.Current(), "test %s failed", test.name)
75 fallback, ok := selector.Fallback()
76 assert.Equalf(t, test.hasFallback, ok, "test %s failed", test.name)
77 if test.hasFallback {
78 assert.Equalf(t, test.expectedFallback, fallback, "test %s failed", test.name)
79 }
80 }
81 })
82 }
83}
84
85func TestAutoProtocolSelectorRefresh(t *testing.T) {
86 fetcher := dynamicMockFetcher{}

Callers

nothing calls this directly

Calls 6

fetchMethod · 0.95
CurrentMethod · 0.95
FallbackMethod · 0.95
NewProtocolSelectorFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected