Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions content_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func NewContentStore(base string) (*ContentStore, error) {
}

// Get takes a Meta object and retreives the content from the store, returning
// it as an io.Reader. If fromByte > 0, the reader starts from that byte
func (s *ContentStore) Get(meta *MetaObject, fromByte int64) (io.Reader, error) {
// it as an io.ReaderCloser. If fromByte > 0, the reader starts from that byte
func (s *ContentStore) Get(meta *MetaObject, fromByte int64) (io.ReadCloser, error) {
path := filepath.Join(s.basePath, transformKey(meta.Oid))

f, err := os.Open(path)
Expand Down
16 changes: 10 additions & 6 deletions content_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var contentStore *ContentStore

func TestContenStorePut(t *testing.T) {
func TestContentStorePut(t *testing.T) {
setup()
defer teardown()

Expand All @@ -31,7 +31,7 @@ func TestContenStorePut(t *testing.T) {
}
}

func TestContenStorePutHashMismatch(t *testing.T) {
func TestContentStorePutHashMismatch(t *testing.T) {
setup()
defer teardown()

Expand All @@ -52,7 +52,7 @@ func TestContenStorePutHashMismatch(t *testing.T) {
}
}

func TestContenStorePutSizeMismatch(t *testing.T) {
func TestContentStorePutSizeMismatch(t *testing.T) {
setup()
defer teardown()

Expand All @@ -73,7 +73,7 @@ func TestContenStorePutSizeMismatch(t *testing.T) {
}
}

func TestContenStoreGet(t *testing.T) {
func TestContentStoreGet(t *testing.T) {
setup()
defer teardown()

Expand All @@ -91,6 +91,8 @@ func TestContenStoreGet(t *testing.T) {
r, err := contentStore.Get(m, 0)
if err != nil {
t.Fatalf("expected get to succeed, got: %s", err)
} else {
defer r.Close()
}

by, _ := ioutil.ReadAll(r)
Expand All @@ -99,7 +101,7 @@ func TestContenStoreGet(t *testing.T) {
}
}

func TestContenStoreGetWithRange(t *testing.T) {
func TestContentStoreGetWithRange(t *testing.T) {
setup()
defer teardown()

Expand All @@ -117,6 +119,8 @@ func TestContenStoreGetWithRange(t *testing.T) {
r, err := contentStore.Get(m, 5)
if err != nil {
t.Fatalf("expected get to succeed, got: %s", err)
} else {
defer r.Close()
}

by, _ := ioutil.ReadAll(r)
Expand All @@ -135,7 +139,7 @@ func TestContenStoreGetNonExisting(t *testing.T) {
}
}

func TestContenStoreExists(t *testing.T) {
func TestContentStoreExists(t *testing.T) {
setup()
defer teardown()

Expand Down
1 change: 1 addition & 0 deletions meta_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ func setupMeta() {
}

func teardownMeta() {
metaStoreTest.Close()
os.RemoveAll("test-meta-store.db")
}
1 change: 1 addition & 0 deletions mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (a *App) objectsRawHandler(w http.ResponseWriter, r *http.Request) {
writeStatus(w, r, 404)
return
}
defer content.Close()

w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s;", vars["oid"]))
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (a *App) GetContentHandler(w http.ResponseWriter, r *http.Request) {
writeStatus(w, r, 404)
return
}
defer content.Close()

w.WriteHeader(statusCode)
io.Copy(w, content)
Expand Down
4 changes: 3 additions & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGetAuthed(t *testing.T) {
}

if res.StatusCode != 200 {
t.Fatalf("expected status 302, got %d", res.StatusCode)
t.Fatalf("expected status 200, got %d", res.StatusCode)
}

by, err := ioutil.ReadAll(res.Body)
Expand Down Expand Up @@ -280,6 +280,8 @@ func TestPut(t *testing.T) {
r, err := testContentStore.Get(&MetaObject{Oid: contentOid}, 0)
if err != nil {
t.Fatalf("error retreiving from content store: %s", err)
} else {
defer r.Close()
}
c, err := ioutil.ReadAll(r)
if err != nil {
Expand Down