TEST upload with surf
This commit is contained in:
parent
a6d5ca9141
commit
3768f92f30
1 changed files with 41 additions and 0 deletions
41
http_test.go
41
http_test.go
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue