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

Method TestFractionMatcherMatch

internal/xds/xdsclient/xdsresource/matcher_test.go:120–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func (s) TestFractionMatcherMatch(t *testing.T) {
121 const fraction = 500000
122 fm := newFractionMatcher(fraction)
123 defer func() {
124 RandInt64n = rand.Int64N
125 }()
126
127 // rand > fraction, should return false.
128 RandInt64n = func(int64) int64 {
129 return fraction + 1
130 }
131 if matched := fm.match(); matched {
132 t.Errorf("match() = %v, want not match", matched)
133 }
134
135 // rand == fraction, should return true.
136 RandInt64n = func(int64) int64 {
137 return fraction
138 }
139 if matched := fm.match(); !matched {
140 t.Errorf("match() = %v, want match", matched)
141 }
142
143 // rand < fraction, should return true.
144 RandInt64n = func(int64) int64 {
145 return fraction - 1
146 }
147 if matched := fm.match(); !matched {
148 t.Errorf("match() = %v, want match", matched)
149 }
150}
151
152func (s) TestMatchTypeForDomain(t *testing.T) {
153 tests := []struct {

Callers

nothing calls this directly

Calls 3

newFractionMatcherFunction · 0.85
matchMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected