Include channel testing in goroutine fore NotifyUploadProgress test

This commit is contained in:
Marius 2017-02-21 23:33:59 +01:00
parent 9ad88c0424
commit 45a9278c74
1 changed files with 19 additions and 14 deletions

View File

@ -307,17 +307,34 @@ func TestPatch(t *testing.T) {
NotifyUploadProgress: true, NotifyUploadProgress: true,
}) })
c := make(chan FileInfo, 10) c := make(chan FileInfo)
handler.UploadProgress = c handler.UploadProgress = c
reader, writer := io.Pipe() reader, writer := io.Pipe()
a := assert.New(t)
go func() { go func() {
writer.Write([]byte("first ")) writer.Write([]byte("first "))
<-time.After(time.Second)
info := <-c
a.Equal("yes", info.ID)
a.Equal(int64(100), info.Size)
a.Equal(int64(6), info.Offset)
writer.Write([]byte("second ")) writer.Write([]byte("second "))
writer.Write([]byte("third")) writer.Write([]byte("third"))
info = <-c
a.Equal("yes", info.ID)
a.Equal(int64(100), info.Size)
a.Equal(int64(18), info.Offset)
writer.Close() writer.Close()
info = <-c
a.Equal("yes", info.ID)
a.Equal(int64(100), info.Size)
a.Equal(int64(18), info.Offset)
}() }()
(&httpTest{ (&httpTest{
@ -340,18 +357,6 @@ func TestPatch(t *testing.T) {
<-time.After(10 * time.Millisecond) <-time.After(10 * time.Millisecond)
close(handler.UploadProgress) close(handler.UploadProgress)
a := assert.New(t)
info := <-c
a.Equal("yes", info.ID)
a.Equal(int64(100), info.Size)
a.Equal(int64(6), info.Offset)
info = <-c
a.Equal("yes", info.ID)
a.Equal(int64(100), info.Size)
a.Equal(int64(18), info.Offset)
_, more := <-c _, more := <-c
a.False(more) a.False(more)
}) })