(t *testing.T)
| 207 | } |
| 208 | |
| 209 | func TestPublisher_serve_errors(t *testing.T) { |
| 210 | var ( |
| 211 | runSync = make(chan bool) |
| 212 | testErrChan chan *amqp.Error |
| 213 | testPublishErr = errors.New("pub err") |
| 214 | _deletePublisher bool |
| 215 | ) |
| 216 | |
| 217 | p := newTestPublisher() |
| 218 | cli := &mqDeleterTest{ |
| 219 | _deletePublisher: func(*Publisher) { |
| 220 | _deletePublisher = true |
| 221 | }, |
| 222 | } |
| 223 | |
| 224 | ch1 := &mqChannelTest{ |
| 225 | _Close: func() error { |
| 226 | return nil |
| 227 | }, |
| 228 | _NotifyClose: func(errChan chan *amqp.Error) chan *amqp.Error { |
| 229 | testErrChan = errChan |
| 230 | return errChan |
| 231 | }, |
| 232 | _Publish: func(string, string, bool, bool, amqp.Publishing) error { |
| 233 | return testPublishErr |
| 234 | }, |
| 235 | } |
| 236 | |
| 237 | go func() { |
| 238 | <-runSync |
| 239 | p.serve(cli, ch1) |
| 240 | runSync <- true |
| 241 | }() |
| 242 | |
| 243 | runSync <- true |
| 244 | _, err := p.Write([]byte("test1")) |
| 245 | close(testErrChan) // immitate amqp.Channel close |
| 246 | <-runSync |
| 247 | |
| 248 | if err != testPublishErr { |
| 249 | t.Error("should return correct error") |
| 250 | } |
| 251 | |
| 252 | if _deletePublisher { |
| 253 | t.Error("on errors should not delete publisher") |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | func TestNewPublisher(t *testing.T) { |
| 258 | var called bool |
nothing calls this directly
no test coverage detected