TEST upload files in tempdir; double check upload

This commit is contained in:
boyska 2018-01-06 00:06:56 +01:00
parent 24074467cf
commit d36a0e9037

View file

@ -12,6 +12,7 @@ import (
"strings"
"testing"
"github.com/Flaque/filet"
"github.com/headzoo/surf"
)
@ -180,16 +181,17 @@ func TestUpload(t *testing.T) {
if !*doHTTP {
return
}
ts := getServer(`
global:
excluded:
- john@doe.us
- foo bar
defer filet.CleanUp(t)
d := filet.TmpDir(t, "")
conf := `
shares:
- name: foo
dir: DIR
authorized: ["*"]
description: foo
`)
`
conf = strings.Replace(conf, "DIR", d, 1)
ts := getServer(conf)
cl := ts.Client()
bodyBuf := bytes.Buffer{}
bodyWriter := multipart.NewWriter(&bodyBuf)
@ -224,23 +226,32 @@ shares:
if resp.StatusCode < 200 || resp.StatusCode > 299 {
t.Error("Server status is not success:", resp.Status, respBody)
}
fname := d + "/" + string(respBody)
if !filet.Exists(t, fname) {
t.Error("File does not exist", fname)
} else if !filet.FileSays(t, fname, []byte("example content")) {
t.Error("File exists but has wrong content")
}
}
func TestSurfUpload(t *testing.T) {
if !*doHTTP {
return
}
ts := getServer(`
defer filet.CleanUp(t)
d := filet.TmpDir(t, "")
conf := `
shares:
- name: foo
dir: /tmp/foo
dir: DIR
authorized: ["*"]
description: example
sizelimit: 1M
`)
`
conf = strings.Replace(conf, "DIR", d, 1)
ts := getServer(conf)
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)
@ -262,4 +273,10 @@ shares:
if bow.StatusCode() > 299 {
t.Error("Invalid status code", bow.StatusCode(), bow.Body())
}
fname := d + "/" + bow.Body()
if !filet.Exists(t, fname) {
t.Error("File does not exist", fname)
} else if !filet.FileSays(t, fname, []byte("example content")) {
t.Error("File exists but has wrong content")
}
}