Skip to content

Commit

Permalink
Improved gorelic reporting
Browse files Browse the repository at this point in the history
With tests updated to 1.5:
- JPEG Encoding produces different md5's
- CMYK image encoding/decoding is now supported
  • Loading branch information
sharpner committed Sep 3, 2015
1 parent bbbbb89 commit 6878629
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion server/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (s *DatabaseTestSuite) SetUpTest(c *C) {
// set a jpeg image to gridfs
defer testJpeg.Close()
io.Copy(childFile, testJpeg)

childFile.Close()

}
Expand Down
2 changes: 1 addition & 1 deletion server/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (s *ImageTestSuite) TestResizeJpegImageFromGridFsCMYK(c *C) {
c.Assert(err, IsNil)

_, _, errResult := ResizeImageFromGridfs(testMongoPNG, &entry)
c.Assert(errResult, ErrorMatches, "unsupported JPEG feature: SOF has wrong length")
c.Assert(errResult, Equals, nil)
}

//TestFallbackToImageMagick
Expand Down
11 changes: 10 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,28 @@ func Deliver() int {
return -1
}

var wrapperFunc func(http.Handler) http.Handler

if *newrelicKey != "" {
agent := gorelic.NewAgent()
agent.NewrelicLicense = *newrelicKey
agent.NewrelicName = "Go image server"
agent.CollectHTTPStat = true
agent.Run()
wrapperFunc = agent.WrapHTTPHandler
}

Connection.SetMode(mgo.Eventual, true)
Connection.SetSyncTimeout(0)

r := mux.NewRouter()
r.HandleFunc("/", welcomeHandler)
r.Handle(serverRoute, VarsHandler(imageHandler))

if wrapperFunc != nil {
r.Handle(serverRoute, wrapperFunc(VarsHandler(imageHandler)))
} else {
r.Handle(serverRoute, VarsHandler(imageHandler))
}

http.Handle("/", r)

Expand Down
8 changes: 4 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *ServerTestSuite) SetUpTest(c *C) {

c.Assert(openErr, IsNil)

c.Assert(testMongoFile.MD5(), Equals, "d5b390993a34a440891a6f20407f9dde")
c.Assert(testMongoFile.MD5(), Equals, "4838427937843516d983b30dce94fd43")
}

// TearDownTest removes the created test file.
Expand Down Expand Up @@ -269,7 +269,7 @@ func (s *ServerTestSuite) TestimageHandlerImageCached(c *C) {
responseWriter := NewResponseWriter(header, -1)

r, _ := http.NewRequest("GET", "test-url", nil)
r.Header.Set("If-None-Match", "d5b390993a34a440891a6f20407f9dde")
r.Header.Set("If-None-Match", "4838427937843516d983b30dce94fd43")
r.Header.Set("Cache-Control", fmt.Sprintf("max-age=%d", 1000))
r.Header.Set("If-Modified-Since", modified)

Expand Down Expand Up @@ -305,10 +305,10 @@ func (s *ServerTestSuite) TestimageHandlerNotCachedParent(c *C) {
// The default value of the responseWriterMock is -1
c.Assert(responseWriter.HeaderCode, Equals, -1)

c.Assert(responseWriter.Header().Get("Etag"), Equals, "d5b390993a34a440891a6f20407f9dde")
c.Assert(responseWriter.Header().Get("Etag"), Equals, "4838427937843516d983b30dce94fd43")

hexMd5 := md5.Sum(responseWriter.Body)
md5String := hex.EncodeToString(hexMd5[:16])

c.Assert(md5String, Equals, "d5b390993a34a440891a6f20407f9dde")
c.Assert(md5String, Equals, "4838427937843516d983b30dce94fd43")
}

0 comments on commit 6878629

Please sign in to comment.