From c918fd53bcf4a8b7fee04d91e5c54b81a55295ba Mon Sep 17 00:00:00 2001 From: nmorse Date: Fri, 11 Mar 2016 09:22:19 -0600 Subject: [PATCH] Fixed unit tests to run on Windows --- content_store.go | 4 ++-- content_store_test.go | 16 ++++++++++------ meta_store_test.go | 1 + mgmt.go | 1 + server.go | 1 + server_test.go | 4 +++- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/content_store.go b/content_store.go index aff6e87..c534e97 100644 --- a/content_store.go +++ b/content_store.go @@ -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) diff --git a/content_store_test.go b/content_store_test.go index 9c19648..9af931e 100644 --- a/content_store_test.go +++ b/content_store_test.go @@ -10,7 +10,7 @@ import ( var contentStore *ContentStore -func TestContenStorePut(t *testing.T) { +func TestContentStorePut(t *testing.T) { setup() defer teardown() @@ -31,7 +31,7 @@ func TestContenStorePut(t *testing.T) { } } -func TestContenStorePutHashMismatch(t *testing.T) { +func TestContentStorePutHashMismatch(t *testing.T) { setup() defer teardown() @@ -52,7 +52,7 @@ func TestContenStorePutHashMismatch(t *testing.T) { } } -func TestContenStorePutSizeMismatch(t *testing.T) { +func TestContentStorePutSizeMismatch(t *testing.T) { setup() defer teardown() @@ -73,7 +73,7 @@ func TestContenStorePutSizeMismatch(t *testing.T) { } } -func TestContenStoreGet(t *testing.T) { +func TestContentStoreGet(t *testing.T) { setup() defer teardown() @@ -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) @@ -99,7 +101,7 @@ func TestContenStoreGet(t *testing.T) { } } -func TestContenStoreGetWithRange(t *testing.T) { +func TestContentStoreGetWithRange(t *testing.T) { setup() defer teardown() @@ -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) @@ -135,7 +139,7 @@ func TestContenStoreGetNonExisting(t *testing.T) { } } -func TestContenStoreExists(t *testing.T) { +func TestContentStoreExists(t *testing.T) { setup() defer teardown() diff --git a/meta_store_test.go b/meta_store_test.go index 19ae46d..9e382d7 100644 --- a/meta_store_test.go +++ b/meta_store_test.go @@ -107,5 +107,6 @@ func setupMeta() { } func teardownMeta() { + metaStoreTest.Close() os.RemoveAll("test-meta-store.db") } diff --git a/mgmt.go b/mgmt.go index 4b88c24..a93b7e5 100644 --- a/mgmt.go +++ b/mgmt.go @@ -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"])) diff --git a/server.go b/server.go index bf582bf..4f51d75 100644 --- a/server.go +++ b/server.go @@ -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) diff --git a/server_test.go b/server_test.go index 4a23519..c6983b0 100644 --- a/server_test.go +++ b/server_test.go @@ -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) @@ -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 {