github.com/blend/go-sdk@v1.20220411.3/bufferutil/buffer_handlers_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package bufferutil 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 func TestBufferHandlers(t *testing.T) { 17 assert := assert.New(t) 18 19 handlers := new(BufferHandlers) 20 defer handlers.Close() 21 22 datums := make(chan string, 2) 23 24 didCallOne := make(chan struct{}) 25 handlers.Add("one", func(c BufferChunk) { 26 datums <- string(c.Data) 27 close(didCallOne) 28 }) 29 30 didCallTwo := make(chan struct{}) 31 handlers.Add("two", func(c BufferChunk) { 32 datums <- string(c.Data) 33 close(didCallTwo) 34 }) 35 36 go func() { 37 handlers.Handle(BufferChunk{Data: []byte("hi")}) 38 }() 39 40 <-didCallOne 41 <-didCallTwo 42 43 assert.Len(datums, 2) 44 }