From 200a600c02723bd26461f444bd4b35e3ad012f83 Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Wed, 2 Nov 2022 16:54:56 +0100 Subject: [PATCH] Add TestWriteStreamFromPipe --- client_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/client_test.go b/client_test.go index d331db5..9195b19 100644 --- a/client_test.go +++ b/client_test.go @@ -5,12 +5,14 @@ import ( "context" "errors" "fmt" + "io" "net/http" "net/http/httptest" "os" "strings" "sync" "testing" + "time" "golang.org/x/net/webdav" ) @@ -413,3 +415,31 @@ func TestWriteStream(t *testing.T) { 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) + } +}