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

Function TestHTTP2ProtocolSelectorRefresh

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

Source from the content-addressed store, hash-verified

112}
113
114func TestHTTP2ProtocolSelectorRefresh(t *testing.T) {
115 fetcher := dynamicMockFetcher{}
116 // Since the user chooses http2 on purpose, we always stick to it.
117 selector, err := NewProtocolSelector(HTTP2.String(), testAccountTag, false, fetcher.fetch(), testNoTTL, &log)
118 require.NoError(t, err)
119 assert.Equal(t, HTTP2, selector.Current())
120
121 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}}
122 assert.Equal(t, HTTP2, selector.Current())
123
124 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}}
125 assert.Equal(t, HTTP2, selector.Current())
126
127 fetcher.err = fmt.Errorf("failed to fetch")
128 assert.Equal(t, HTTP2, selector.Current())
129
130 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}}
131 fetcher.err = nil
132 assert.Equal(t, HTTP2, selector.Current())
133
134 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}}
135 assert.Equal(t, HTTP2, selector.Current())
136
137 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}}
138 assert.Equal(t, HTTP2, selector.Current())
139
140 fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}}
141 assert.Equal(t, HTTP2, selector.Current())
142}
143
144func TestAutoProtocolSelectorNoRefreshWithToken(t *testing.T) {
145 fetcher := dynamicMockFetcher{}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected