github.com/lrita/ratelimit@v0.0.0-20190723030019-81504bd89bc5/reader_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the LGPLv3 with static-linking exception. 3 // See LICENCE file for details. 4 5 package ratelimit 6 7 import ( 8 "io" 9 "strings" 10 "testing" 11 ) 12 13 func TestReaderWriter(t *testing.T) { 14 rd := Reader(strings.NewReader(strings.Repeat("abcd", 1024)), 15 NewBucketWithRate(1024.0, 1024)) 16 wd := Writer(&strings.Builder{}, NewBucketWithRate(1024.0, 1024)) 17 n, err := io.Copy(wd, rd) 18 if err != nil { 19 t.Fatalf("unexpect error(%v)", err) 20 } 21 if n != 1024*4 { 22 t.Fatalf("unexpect eof") 23 } 24 }