Skip to content

Commit

Permalink
Merge pull request #29 from rande/fix_static_error
Browse files Browse the repository at this point in the history
fix(static): fix error management
  • Loading branch information
rande committed Dec 5, 2016
2 parents 668aabf + 40a5fd3 commit 771f819
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 11 additions & 7 deletions mirror/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ func (gs *StaticService) Serve(state *goapp.GoroutineState) error {
}

func (gs *StaticService) WriteArchive(w io.Writer, path string) (*StaticFile, error) {
logger := gs.Logger.WithFields(log.Fields{
"path": path,
"action": "WriteArchive",
})

vaultKey := fmt.Sprintf("%s", path)
bucketKey := vaultKey

url := fmt.Sprintf("%s/%s", gs.Config.SourceServer, path)

logger := gs.Logger.WithFields(log.Fields{
"path": path,
"action": "WriteArchive",
"vaultKey": vaultKey,
"bucketKey": bucketKey,
"url": url,
})

file := &StaticFile{}

err := gs.DB.View(func(tx *bolt.Tx) error {
Expand All @@ -104,7 +106,7 @@ func (gs *StaticService) WriteArchive(w io.Writer, path string) (*StaticFile, er

if err == pkgmirror.EmptyDataError {
file.Url = url
} else {
} else if err != nil {
return nil, err
}

Expand Down Expand Up @@ -163,6 +165,8 @@ func (gs *StaticService) WriteArchive(w io.Writer, path string) (*StaticFile, er

return nil
})
} else {
logger.Info("Vault entry exist!")
}

logger.Info("Read vault entry")
Expand Down
4 changes: 2 additions & 2 deletions mirror/static/static_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
package static

import (
"bytes"
"fmt"
"net/http"

"bytes"

log "github.com/Sirupsen/logrus"
"github.com/rande/goapp"
"github.com/rande/gonode/core/vault"
Expand Down Expand Up @@ -109,6 +108,7 @@ func ConfigureHttp(name string, conf *pkgmirror.StaticConfig, app *goapp.App) {

pkgmirror.SendWithHttpCode(w, code, err.Error())
} else {

// copy header
for name := range file.Header {
if name == "Content-Length" {
Expand Down
6 changes: 6 additions & 0 deletions test/mirror/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ func Test_Static_Get_Valid_File(t *testing.T) {
assert.Equal(t, "This is a sample test file.", string(res.GetBody()))

// get the proxied file
res, err = test.RunRequest("GET", fmt.Sprintf("%s/static/static/file.txt", args.TestServer.URL))

assert.NoError(t, err)
assert.Equal(t, 200, res.StatusCode)
assert.Equal(t, "This is a sample test file.", string(res.GetBody()))

// test if the second time the code work fine (using the cache)
res, err = test.RunRequest("GET", fmt.Sprintf("%s/static/static/file.txt", args.TestServer.URL))

assert.NoError(t, err)
Expand Down

0 comments on commit 771f819

Please sign in to comment.