master
Caj Larsson 3 years ago
parent 9e41b707bf
commit 7274e08b9a

@ -33,6 +33,7 @@ func basicFileOperationContract(fac func() Repository, t *testing.T) {
is.NoErr(err) is.NoErr(err)
is.True(reopened_file != nil) is.True(reopened_file != nil)
is.Equal(reopened_file.Size(), int64(len(testdata)))
readback := make([]byte, 128) readback := make([]byte, 128)

@ -115,7 +115,13 @@ func (f Repository) Open(filename string, namespace_ns string) (swampfile.SwampO
return nil, swampfile.ErrNotExists return nil, swampfile.ErrNotExists
} }
bfd := FileSystemSwampFileData{filename, 0, time.Now(), file} stat, err := file.Stat()
if err != nil {
return nil, err
}
bfd := FileSystemSwampFileData{filename, stat.Size(), time.Now(), file}
return bfd, nil return bfd, nil
} }

@ -44,7 +44,6 @@ func (b *Bog) fileHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi") fmt.Fprintf(w, "Hi")
return return
} }
ref := swampfile.FileReference{r.URL.Path, r.Header["User-Agent"][0]} ref := swampfile.FileReference{r.URL.Path, r.Header["User-Agent"][0]}
switch r.Method { switch r.Method {
@ -71,6 +70,7 @@ func (b *Bog) fileHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(422) w.WriteHeader(422)
return return
} }
b.logger.Info("Recieving file '%s' of size %d from '%s'", ref.Path, size, ref.UserAgent) b.logger.Info("Recieving file '%s' of size %d from '%s'", ref.Path, size, ref.UserAgent)
err = b.file_service.SaveFile(ref, r.Body, size) err = b.file_service.SaveFile(ref, r.Body, size)

@ -13,20 +13,28 @@ import (
"time" "time"
) )
type TestLogger struct{}
func (t TestLogger) Debug(format string, a ...interface{}) {}
func (t TestLogger) Info(format string, a ...interface{}) {}
func (t TestLogger) Warn(format string, a ...interface{}) {}
func TestApplication(t *testing.T) { func TestApplication(t *testing.T) {
is := is.New(t) is := is.New(t)
logger := TestLogger{}
file_service := dataswamp.NewSwampFileService( file_service := dataswamp.NewSwampFileService(
namespace.NewRepository(), namespace.NewRepository(),
swampfile.NewRepository(), swampfile.NewRepository(),
1000, 1000,
time.Hour, time.Hour,
ServerLogger{Debug}, logger,
) )
bog := Bog{ bog := Bog{
router: new(http.ServeMux), router: new(http.ServeMux),
file_service: file_service, file_service: file_service,
address: "fake", address: "fake",
logger: logger,
} }
bog.routes() bog.routes()
req := httptest.NewRequest("POST", "/apath", strings.NewReader("testdata")) req := httptest.NewRequest("POST", "/apath", strings.NewReader("testdata"))

Loading…
Cancel
Save