MCPcopy Create free account
hub / github.com/assembla/cony / TestPublisher_Write

Function TestPublisher_Write

publisher_test.go:312–342  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310}
311
312func TestPublisher_Write(t *testing.T) {
313 var ok bool
314 testBuf := []byte("test1")
315 p := newTestPublisher(PublishingTemplate(amqp.Publishing{AppId: "app1"}))
316 testErr := errors.New("testing error")
317
318 go func() {
319 envelop := <-p.pubChan
320 msg := <-envelop.pub
321 if bytes.Compare(msg.Body, testBuf) == 0 {
322 if msg.AppId == "app1" {
323 ok = true
324 }
325 }
326 envelop.err <- testErr
327 }()
328
329 n, err := p.Write(testBuf)
330
331 if n != len(testBuf) {
332 t.Error("Write() should return len equal to input buffer")
333 }
334
335 if err != testErr {
336 t.Error("Write() should return correct error")
337 }
338
339 if !ok {
340 t.Error("Write() send incorrect message")
341 }
342}
343
344func TestPublishingTemplate(t *testing.T) {
345 p := newTestPublisher()

Callers

nothing calls this directly

Calls 3

newTestPublisherFunction · 0.85
PublishingTemplateFunction · 0.85
WriteMethod · 0.80

Tested by

no test coverage detected