github.com/tumi8/quic-go@v0.37.4-tum/noninternal/utils/buffered_write_closer_test.go (about) 1 package utils 2 3 import ( 4 "bufio" 5 "bytes" 6 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 ) 10 11 type nopCloser struct{} 12 13 func (nopCloser) Close() error { return nil } 14 15 var _ = Describe("buffered io.WriteCloser", func() { 16 It("flushes before closing", func() { 17 buf := &bytes.Buffer{} 18 19 w := bufio.NewWriter(buf) 20 wc := NewBufferedWriteCloser(w, &nopCloser{}) 21 wc.Write([]byte("foobar")) 22 Expect(buf.Len()).To(BeZero()) 23 Expect(wc.Close()).To(Succeed()) 24 Expect(buf.String()).To(Equal("foobar")) 25 }) 26 })