Skip to content

Commit 5d94047

Browse files
authored
Merge pull request #49 from shadyoak/unit-test-fixes
Fixed unit tests to run on Windows
2 parents e8afc6f + c918fd5 commit 5d94047

6 files changed

+18
-9
lines changed

content_store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func NewContentStore(base string) (*ContentStore, error) {
2929
}
3030

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

3636
f, err := os.Open(path)

content_store_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
var contentStore *ContentStore
1212

13-
func TestContenStorePut(t *testing.T) {
13+
func TestContentStorePut(t *testing.T) {
1414
setup()
1515
defer teardown()
1616

@@ -31,7 +31,7 @@ func TestContenStorePut(t *testing.T) {
3131
}
3232
}
3333

34-
func TestContenStorePutHashMismatch(t *testing.T) {
34+
func TestContentStorePutHashMismatch(t *testing.T) {
3535
setup()
3636
defer teardown()
3737

@@ -52,7 +52,7 @@ func TestContenStorePutHashMismatch(t *testing.T) {
5252
}
5353
}
5454

55-
func TestContenStorePutSizeMismatch(t *testing.T) {
55+
func TestContentStorePutSizeMismatch(t *testing.T) {
5656
setup()
5757
defer teardown()
5858

@@ -73,7 +73,7 @@ func TestContenStorePutSizeMismatch(t *testing.T) {
7373
}
7474
}
7575

76-
func TestContenStoreGet(t *testing.T) {
76+
func TestContentStoreGet(t *testing.T) {
7777
setup()
7878
defer teardown()
7979

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

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

102-
func TestContenStoreGetWithRange(t *testing.T) {
104+
func TestContentStoreGetWithRange(t *testing.T) {
103105
setup()
104106
defer teardown()
105107

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

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

138-
func TestContenStoreExists(t *testing.T) {
142+
func TestContentStoreExists(t *testing.T) {
139143
setup()
140144
defer teardown()
141145

meta_store_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,6 @@ func setupMeta() {
107107
}
108108

109109
func teardownMeta() {
110+
metaStoreTest.Close()
110111
os.RemoveAll("test-meta-store.db")
111112
}

mgmt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (a *App) objectsRawHandler(w http.ResponseWriter, r *http.Request) {
123123
writeStatus(w, r, 404)
124124
return
125125
}
126+
defer content.Close()
126127

127128
w.Header().Set("Content-Type", "application/octet-stream")
128129
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s;", vars["oid"]))

server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func (a *App) GetContentHandler(w http.ResponseWriter, r *http.Request) {
200200
writeStatus(w, r, 404)
201201
return
202202
}
203+
defer content.Close()
203204

204205
w.WriteHeader(statusCode)
205206
io.Copy(w, content)

server_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestGetAuthed(t *testing.T) {
2626
}
2727

2828
if res.StatusCode != 200 {
29-
t.Fatalf("expected status 302, got %d", res.StatusCode)
29+
t.Fatalf("expected status 200, got %d", res.StatusCode)
3030
}
3131

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

0 commit comments

Comments
 (0)