Add TestWriteStreamFromPipe
This commit is contained in:
		
							parent
							
								
									17255f2e74
								
							
						
					
					
						commit
						200a600c02
					
				@ -5,12 +5,14 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"net/http/httptest"
 | 
						"net/http/httptest"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"golang.org/x/net/webdav"
 | 
						"golang.org/x/net/webdav"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@ -413,3 +415,31 @@ func TestWriteStream(t *testing.T) {
 | 
				
			|||||||
		t.Fatalf("got: %v, want file info: %v", err, info)
 | 
							t.Fatalf("got: %v, want file info: %v", err, info)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestWriteStreamFromPipe(t *testing.T) {
 | 
				
			||||||
 | 
						cli, srv, fs, ctx := newServer(t)
 | 
				
			||||||
 | 
						defer srv.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r, w := io.Pipe()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go func() {
 | 
				
			||||||
 | 
							defer w.Close()
 | 
				
			||||||
 | 
							fmt.Fprint(w, "foo")
 | 
				
			||||||
 | 
							time.Sleep(1 * time.Second)
 | 
				
			||||||
 | 
							fmt.Fprint(w, " ")
 | 
				
			||||||
 | 
							time.Sleep(1 * time.Second)
 | 
				
			||||||
 | 
							fmt.Fprint(w, "bar\n")
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := cli.WriteStream("/newfile.txt", r, 0660); err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("got: %v, want nil", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						info, err := fs.Stat(ctx, "/newfile.txt")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("got: %v, want file info: %v", err, info)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if info.Size() != 8 {
 | 
				
			||||||
 | 
							t.Fatalf("got: %v, want file size: %d bytes", info.Size(), 8)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user