fix: trim prefix slash

This commit is contained in:
2024-01-29 09:17:28 +01:00
parent 3aa253afcf
commit fddc2dc0b6
2 changed files with 5 additions and 6 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ func (s *Server) HandleHealth(w http.ResponseWriter, _ *http.Request) {
func (s *Server) upload(path string, w http.ResponseWriter, req *http.Request) { func (s *Server) upload(path string, w http.ResponseWriter, req *http.Request) {
s.logger.Infof("uploading to %s", path) s.logger.Infof("uploading to %s", path)
err := s.store.Store(path, req.Body) err := s.store.Store(strings.TrimPrefix(path, "/"), req.Body)
if err != nil { if err != nil {
s.logger.WithError(err).Error("error storing object in bucket") s.logger.WithError(err).Error("error storing object in bucket")
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
+4 -5
View File
@@ -4,7 +4,6 @@ import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@@ -91,8 +90,8 @@ func TestServer(t *testing.T) {
args: args{ args: args{
store: func(t *testing.T) StoreFunc { store: func(t *testing.T) StoreFunc {
return func(path string, content io.Reader) error { return func(path string, content io.Reader) error {
assert.Equal(t, "/some/file", path) assert.Equal(t, "some/file", path)
temp, err := ioutil.ReadAll(content) temp, err := io.ReadAll(content)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "abc", string(temp)) assert.Equal(t, "abc", string(temp))
return fmt.Errorf("error") return fmt.Errorf("error")
@@ -175,8 +174,8 @@ func TestServer(t *testing.T) {
args: args{ args: args{
store: func(t *testing.T) StoreFunc { store: func(t *testing.T) StoreFunc {
return func(path string, content io.Reader) error { return func(path string, content io.Reader) error {
assert.Equal(t, "/20211125/588b41ebf261820104615b83201c729bd16016d6e43649b28b0ef77d54ca5aaf8da0ce74ae3f20a4", path) assert.Equal(t, "20211125/588b41ebf261820104615b83201c729bd16016d6e43649b28b0ef77d54ca5aaf8da0ce74ae3f20a4", path)
temp, err := ioutil.ReadAll(content) temp, err := io.ReadAll(content)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "abc", string(temp)) assert.Equal(t, "abc", string(temp))
return fmt.Errorf("error") return fmt.Errorf("error")