(t *testing.T)
| 2162 | } |
| 2163 | |
| 2164 | func TestAsyncProducerInterceptors(t *testing.T) { |
| 2165 | tests := []struct { |
| 2166 | name string |
| 2167 | interceptors []ProducerInterceptor |
| 2168 | expectationFn func(*testing.T, int, *ProducerMessage) |
| 2169 | }{ |
| 2170 | { |
| 2171 | name: "intercept messages", |
| 2172 | interceptors: []ProducerInterceptor{&appendInterceptor{i: 0}}, |
| 2173 | expectationFn: func(t *testing.T, i int, msg *ProducerMessage) { |
| 2174 | v, _ := msg.Value.Encode() |
| 2175 | expected := TestMessage + strconv.Itoa(i) |
| 2176 | if string(v) != expected { |
| 2177 | t.Errorf("Interceptor should have incremented the value, got %s, expected %s", v, expected) |
| 2178 | } |
| 2179 | }, |
| 2180 | }, |
| 2181 | { |
| 2182 | name: "interceptor chain", |
| 2183 | interceptors: []ProducerInterceptor{&appendInterceptor{i: 0}, &appendInterceptor{i: 1000}}, |
| 2184 | expectationFn: func(t *testing.T, i int, msg *ProducerMessage) { |
| 2185 | v, _ := msg.Value.Encode() |
| 2186 | expected := TestMessage + strconv.Itoa(i) + strconv.Itoa(i+1000) |
| 2187 | if string(v) != expected { |
| 2188 | t.Errorf("Interceptor should have incremented the value, got %s, expected %s", v, expected) |
| 2189 | } |
| 2190 | }, |
| 2191 | }, |
| 2192 | { |
| 2193 | name: "interceptor chain with one interceptor failing", |
| 2194 | interceptors: []ProducerInterceptor{&appendInterceptor{i: -1}, &appendInterceptor{i: 1000}}, |
| 2195 | expectationFn: func(t *testing.T, i int, msg *ProducerMessage) { |
| 2196 | v, _ := msg.Value.Encode() |
| 2197 | expected := TestMessage + strconv.Itoa(i+1000) |
| 2198 | if string(v) != expected { |
| 2199 | t.Errorf("Interceptor should have incremented the value, got %s, expected %s", v, expected) |
| 2200 | } |
| 2201 | }, |
| 2202 | }, |
| 2203 | { |
| 2204 | name: "interceptor chain with all interceptors failing", |
| 2205 | interceptors: []ProducerInterceptor{&appendInterceptor{i: -1}, &appendInterceptor{i: -1}}, |
| 2206 | expectationFn: func(t *testing.T, i int, msg *ProducerMessage) { |
| 2207 | v, _ := msg.Value.Encode() |
| 2208 | expected := TestMessage |
| 2209 | if string(v) != expected { |
| 2210 | t.Errorf("Interceptor should have not changed the value, got %s, expected %s", v, expected) |
| 2211 | } |
| 2212 | }, |
| 2213 | }, |
| 2214 | } |
| 2215 | for _, tt := range tests { |
| 2216 | t.Run(tt.name, func(t *testing.T) { |
| 2217 | testProducerInterceptor(t, tt.interceptors, tt.expectationFn) |
| 2218 | }) |
| 2219 | } |
| 2220 | } |
| 2221 |
nothing calls this directly
no test coverage detected