-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
always use error interface when returning errors (#8816)
* always use error interface when returning errors Signed-off-by: Jörn Friedrich Dreyer <[email protected]> * fix: use non pointer Error * fix: errorcode evaluation --------- Signed-off-by: Jörn Friedrich Dreyer <[email protected]> Co-authored-by: Florian Schade <[email protected]>
- Loading branch information
Showing
13 changed files
with
142 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package errorcode_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode" | ||
) | ||
|
||
type customErr struct{} | ||
|
||
func (customErr) Error() string { | ||
return "some error" | ||
} | ||
|
||
func TestRenderError(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("errorcode.Error value error", func(t *testing.T) { | ||
r := httptest.NewRequest("GET", "/", nil) | ||
w := httptest.NewRecorder() | ||
err := errorcode.New(errorcode.ItemNotFound, "test error") | ||
errorcode.RenderError(w, r, err) | ||
require.Equal(t, http.StatusNotFound, w.Code) | ||
}) | ||
|
||
t.Run("errorcode.Error zero value error", func(t *testing.T) { | ||
r := httptest.NewRequest("GET", "/", nil) | ||
w := httptest.NewRecorder() | ||
var err errorcode.Error | ||
errorcode.RenderError(w, r, err) | ||
require.Equal(t, http.StatusForbidden, w.Code) | ||
}) | ||
|
||
t.Run("custom error", func(t *testing.T) { | ||
r := httptest.NewRequest("GET", "/", nil) | ||
w := httptest.NewRecorder() | ||
var err customErr | ||
errorcode.RenderError(w, r, err) | ||
require.Equal(t, http.StatusInternalServerError, w.Code) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.