diff --git a/pkg/project/fs.go b/pkg/project/fs.go index 4961e56..f34a1d3 100644 --- a/pkg/project/fs.go +++ b/pkg/project/fs.go @@ -27,7 +27,7 @@ func (fr *FilesystemRepository) imageFile(slug, filename string) string { func (fr *FilesystemRepository) Exists(slug string) (bool, error) { dir, err := os.Stat(fr.ProjectDir) if err != nil { - return false, err + return false, fmt.Errorf("project directory %s not accessible: %w", fr.ProjectDir, err) } if !dir.IsDir() { return false, fmt.Errorf("project directory %s is not a directory", fr.ProjectDir) diff --git a/pkg/web/api_test.go b/pkg/web/api_test.go index dd1c80b..8bc22c3 100644 --- a/pkg/web/api_test.go +++ b/pkg/web/api_test.go @@ -106,7 +106,7 @@ func TestAPI_createProject(t *testing.T) { resp := tc.Request("POST", "/api/tales/", project.Project{Slug: "foo"}) - AssertError(t, resp, "stat "+tc.dir+": no such file or directory\n", 500) + AssertError(t, resp, tc.dir+" not accessible", 500) }) } @@ -136,7 +136,7 @@ func TestAPI_loadProject(t *testing.T) { resp := tc.Request("GET", "/api/tales/foo", nil) - AssertError(t, resp, "stat "+tc.dir+": no such file or directory\n", 500) + AssertError(t, resp, tc.dir+" not accessible", 500) }) } @@ -158,7 +158,7 @@ func TestAPI_updateProject(t *testing.T) { resp := tc.Request("PUT", "/api/tales/foo", nil) - AssertError(t, resp, "invalid project\n", 400) + AssertError(t, resp, "invalid project", 400) }) t.Run("unknown project", func(t *testing.T) { tc := NewTestClient(t) @@ -175,7 +175,7 @@ func TestAPI_updateProject(t *testing.T) { resp := tc.Request("PUT", "/api/tales/foo", project.Project{Slug: "foo"}) - AssertError(t, resp, "stat "+tc.dir+": no such file or directory\n", 500) + AssertError(t, resp, tc.dir+" not accessible", 500) }) } @@ -199,7 +199,7 @@ func TestAPI_deleteProject(t *testing.T) { resp := tc.Request("DELETE", "/api/tales/foo", nil) - AssertError(t, resp, "project not found\n", 404) + AssertError(t, resp, "project not found", 404) }) t.Run("internal error", func(t *testing.T) { tc := NewTestClient(t) @@ -207,7 +207,7 @@ func TestAPI_deleteProject(t *testing.T) { resp := tc.Request("DELETE", "/api/tales/foo", nil) - AssertError(t, resp, "stat "+tc.dir+": no such file or directory\n", 500) + AssertError(t, resp, tc.dir+" not accessible", 500) }) } @@ -234,7 +234,7 @@ func TestAPI_updateProjectImage(t *testing.T) { resp := tc.Request("PUT", "/api/tales/foo/image", nil) - AssertError(t, resp, "unsupported content-type: \n", 500) + AssertError(t, resp, "unsupported content-type", 500) }) t.Run("unknown project", func(t *testing.T) { tc := NewTestClient(t) @@ -242,7 +242,7 @@ func TestAPI_updateProjectImage(t *testing.T) { resp := tc.Request("PUT", "/api/tales/foo/image", nil) - AssertError(t, resp, "project not found\n", 404) + AssertError(t, resp, "project not found", 404) }) } @@ -259,7 +259,7 @@ func AssertProjectResponse(t *testing.T, resp *http.Response, expected project.P func AssertError(t *testing.T, resp *http.Response, errorMsg string, statusCode int) { AssertHTTPError(t, resp, statusCode) body, _ := io.ReadAll(resp.Body) - assert.Equal(t, errorMsg, string(body)) + assert.Contains(t, string(body), errorMsg) } func AssertHTTPError(t *testing.T, resp *http.Response, statusCode int) {