TEST upload with surf

This commit is contained in:
boyska 2018-01-05 23:41:34 +01:00
parent a6d5ca9141
commit 3768f92f30

View file

@ -7,7 +7,10 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/headzoo/surf"
)
var (
@ -170,3 +173,41 @@ shares:
return
}
}
func TestSurfUpload(t *testing.T) {
if !*doHTTP {
return
}
ts := getServer(`
shares:
- name: foo
dir: /tmp/foo
authorized: ["*"]
description: example
sizelimit: 1M
`)
bow := surf.NewBrowser()
bow.AddRequestHeader("X-Forwarded-User", "someone")
// TODO: add x-forwarded-user
var err error
if err = bow.Open(ts.URL); err != nil {
t.Fatal("error opening home", err)
return
}
if err = bow.Click("li a"); err != nil {
t.Fatal("error clicking on share", err)
return
}
form, err := bow.Form("form")
if err != nil {
t.Fatal("can't find form", err)
return
}
form.SetFile("file", "foo.txt", strings.NewReader("example content"))
if err = form.Submit(); err != nil {
t.Error("error submitting form", err)
}
if bow.StatusCode() > 299 {
t.Error("Invalid status code", bow.StatusCode(), bow.Body())
}
}