diff --git a/internal/server/http/imposter.go b/internal/server/http/imposter.go index 0fe0a95..e5ae638 100644 --- a/internal/server/http/imposter.go +++ b/internal/server/http/imposter.go @@ -133,9 +133,16 @@ type ImposterFs struct { } func NewImposterFS(path string) (ImposterFs, error) { - // TODO: What if user lacks permissions? - if _, err := os.Stat(path); os.IsNotExist(err) { - return ImposterFs{}, fmt.Errorf("%w: the directory %s doesn't exists", err, path) + _, err := os.Stat(path) + if err != nil { + switch { + case os.IsNotExist(err): + return ImposterFs{}, fmt.Errorf("the directory '%s' does not exist", path) + case os.IsPermission(err): + return ImposterFs{}, fmt.Errorf("could not read the directory '%s': permission denied", path) + default: + return ImposterFs{}, fmt.Errorf("could not read the directory '%s': %w", path, err) + } } return ImposterFs{ diff --git a/internal/server/http/imposter_test.go b/internal/server/http/imposter_test.go index c757597..6eb9e0c 100644 --- a/internal/server/http/imposter_test.go +++ b/internal/server/http/imposter_test.go @@ -13,7 +13,7 @@ func TestNewImposterFS(t *testing.T) { t.Run("imposters directory not found", func(t *testing.T) { _, err := NewImposterFS("failImposterPath") assert.Error(t, err) - assert.Contains(t, err.Error(), "the directory failImposterPath doesn't exists") + assert.Contains(t, err.Error(), "the directory 'failImposterPath' does not exist") }) t.Run("existing imposters directory", func(t *testing.T) { diff --git a/internal/server/http/server.go b/internal/server/http/server.go index e3e96a6..d334e84 100644 --- a/internal/server/http/server.go +++ b/internal/server/http/server.go @@ -4,11 +4,12 @@ import ( "context" "crypto/tls" _ "embed" + "log" + "net/http" + killgrave "github.com/friendsofgo/killgrave/internal" "github.com/gorilla/handlers" "github.com/gorilla/mux" - "log" - "net/http" ) //go:embed cert/server.key