github.com/codingeasygo/util@v0.0.0-20231206062002-1ce2f004b7d9/xio/byte_test.go (about) 1 package xio 2 3 import ( 4 "bytes" 5 "fmt" 6 "testing" 7 ) 8 9 func TestByteDistributeWriteCloser(t *testing.T) { 10 dist := NewByteDistributeWriter() 11 buffer1 := bytes.NewBuffer(nil) 12 buffer2 := bytes.NewBuffer(nil) 13 dist.Add('a', NewCombinedReadWriteCloser(nil, buffer1, nil)) 14 dist.Add('b', NewCombinedReadWriteCloser(nil, buffer2, nil)) 15 fmt.Fprintf(dist, "a123") 16 fmt.Fprintf(dist, "b000") 17 if buffer1.String() != "a123" { 18 t.Error("error") 19 return 20 } 21 if buffer2.String() != "b000" { 22 t.Error("error") 23 return 24 } 25 _, err := dist.Write([]byte("111")) 26 if err == nil { 27 t.Error(err) 28 return 29 } 30 dist.Close() 31 }