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

Function TestAutoProtocolSelectorRefresh

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

Source from the content-addressed store, hash-verified

83}
84
85func TestAutoProtocolSelectorRefresh(t *testing.T) {
86 fetcher := dynamicMockFetcher{}
87 selector, err := NewProtocolSelector(AutoSelectFlag, testAccountTag, false, fetcher.fetch(), testNoTTL, &log)
88 require.NoError(t, err)
89 assert.Equal(t, QUIC, selector.Current())
90
91 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}}
92 assert.Equal(t, HTTP2, selector.Current())
93
94 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}}
95 assert.Equal(t, QUIC, selector.Current())
96
97 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}}
98 assert.Equal(t, HTTP2, selector.Current())
99
100 fetcher.err = fmt.Errorf("failed to fetch")
101 assert.Equal(t, HTTP2, selector.Current())
102
103 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}}
104 fetcher.err = nil
105 assert.Equal(t, QUIC, selector.Current())
106
107 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}}
108 assert.Equal(t, QUIC, selector.Current())
109
110 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "quic", Percentage: 100}}
111 assert.Equal(t, QUIC, selector.Current())
112}
113
114func TestHTTP2ProtocolSelectorRefresh(t *testing.T) {
115 fetcher := dynamicMockFetcher{}

Callers

nothing calls this directly

Calls 5

fetchMethod · 0.95
CurrentMethod · 0.95
NewProtocolSelectorFunction · 0.85
ErrorfMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected