Skip to content

Commit

Permalink
Uncommented test for raw file; removed debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
deiu committed Dec 8, 2015
1 parent 4b78bca commit 40e5ee4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
7 changes: 0 additions & 7 deletions pathinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,10 @@ func (req *httpRequest) pathInfo(path string) (*pathInfo, error) {
} else {
res.FileType, res.Extension, res.MaybeRDF = MimeLookup(res.File)
if len(res.FileType) == 0 {
req.Server.debug.Println("Finding mime for", res.File)
res.FileType, err = GuessMimeType(res.File)
if err != nil {
req.Server.debug.Println(err)
}

// Old
// res.FileType, err = magic.TypeByFile(res.File)
// if err != nil {
// req.Server.debug.Println(err)
// }
}
}
}
Expand Down
66 changes: 33 additions & 33 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,39 +1219,39 @@ func TestInvalidContent(t *testing.T) {
assert.Equal(t, 415, response.StatusCode)
}

// func TestRawContent(t *testing.T) {
// path := "./tests/img.jpg"
// file, err := os.Open(path)
// defer file.Close()
// assert.NoError(t, err)
// stat, err := os.Stat(path)
// data := make([]byte, stat.Size())
// _, err = file.Read(data)
// assert.NoError(t, err)

// request, err := http.NewRequest("PUT", testServer.URL+"/test.raw", strings.NewReader(string(data)))
// assert.NoError(t, err)
// request.Header.Add("Content-Type", "image/jpeg")
// response, err := httpClient.Do(request)
// assert.NoError(t, err)
// assert.Equal(t, 201, response.StatusCode)

// request, err = http.NewRequest("GET", testServer.URL+"/test.raw", nil)
// assert.NoError(t, err)
// response, err = httpClient.Do(request)
// assert.NoError(t, err)
// assert.Equal(t, 200, response.StatusCode)
// assert.Equal(t, "image/jpeg", response.Header.Get(HCType))
// body, err := ioutil.ReadAll(response.Body)
// response.Body.Close()
// assert.Equal(t, stat.Size(), int64(len(string(body))))

// request, err = http.NewRequest("DELETE", testServer.URL+"/test.raw", nil)
// assert.NoError(t, err)
// response, err = httpClient.Do(request)
// assert.NoError(t, err)
// assert.Equal(t, 200, response.StatusCode)
// }
func TestRawContent(t *testing.T) {
path := "./tests/img.jpg"
file, err := os.Open(path)
defer file.Close()
assert.NoError(t, err)
stat, err := os.Stat(path)
data := make([]byte, stat.Size())
_, err = file.Read(data)
assert.NoError(t, err)

request, err := http.NewRequest("PUT", testServer.URL+"/test.raw", strings.NewReader(string(data)))
assert.NoError(t, err)
request.Header.Add("Content-Type", "image/jpeg")
response, err := httpClient.Do(request)
assert.NoError(t, err)
assert.Equal(t, 201, response.StatusCode)

request, err = http.NewRequest("GET", testServer.URL+"/test.raw", nil)
assert.NoError(t, err)
response, err = httpClient.Do(request)
assert.NoError(t, err)
assert.Equal(t, 200, response.StatusCode)
assert.Equal(t, "image/jpeg", response.Header.Get(HCType))
body, err := ioutil.ReadAll(response.Body)
response.Body.Close()
assert.Equal(t, stat.Size(), int64(len(string(body))))

request, err = http.NewRequest("DELETE", testServer.URL+"/test.raw", nil)
assert.NoError(t, err)
response, err = httpClient.Do(request)
assert.NoError(t, err)
assert.Equal(t, 200, response.StatusCode)
}

func BenchmarkPUT(b *testing.B) {
e := 0
Expand Down

0 comments on commit 40e5ee4

Please sign in to comment.