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" "strings"
"testing" "testing"
"github.com/Flaque/filet"
"github.com/headzoo/surf" "github.com/headzoo/surf"
) )
@ -180,16 +181,17 @@ func TestUpload(t *testing.T) {
if !*doHTTP { if !*doHTTP {
return return
} }
ts := getServer(` defer filet.CleanUp(t)
global: d := filet.TmpDir(t, "")
excluded: conf := `
- john@doe.us
- foo bar
shares: shares:
- name: foo - name: foo
dir: DIR
authorized: ["*"] authorized: ["*"]
description: foo description: foo
`) `
conf = strings.Replace(conf, "DIR", d, 1)
ts := getServer(conf)
cl := ts.Client() cl := ts.Client()
bodyBuf := bytes.Buffer{} bodyBuf := bytes.Buffer{}
bodyWriter := multipart.NewWriter(&bodyBuf) bodyWriter := multipart.NewWriter(&bodyBuf)
@ -224,23 +226,32 @@ shares:
if resp.StatusCode < 200 || resp.StatusCode > 299 { if resp.StatusCode < 200 || resp.StatusCode > 299 {
t.Error("Server status is not success:", resp.Status, respBody) 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) { func TestSurfUpload(t *testing.T) {
if !*doHTTP { if !*doHTTP {
return return
} }
ts := getServer(` defer filet.CleanUp(t)
d := filet.TmpDir(t, "")
conf := `
shares: shares:
- name: foo - name: foo
dir: /tmp/foo dir: DIR
authorized: ["*"] authorized: ["*"]
description: example description: example
sizelimit: 1M sizelimit: 1M
`) `
conf = strings.Replace(conf, "DIR", d, 1)
ts := getServer(conf)
bow := surf.NewBrowser() bow := surf.NewBrowser()
bow.AddRequestHeader("X-Forwarded-User", "someone") bow.AddRequestHeader("X-Forwarded-User", "someone")
// TODO: add x-forwarded-user
var err error var err error
if err = bow.Open(ts.URL); err != nil { if err = bow.Open(ts.URL); err != nil {
t.Fatal("error opening home", err) t.Fatal("error opening home", err)
@ -262,4 +273,10 @@ shares:
if bow.StatusCode() > 299 { if bow.StatusCode() > 299 {
t.Error("Invalid status code", bow.StatusCode(), bow.Body()) 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")
}
} }