-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix admin config page error, use tests to cover the admin config and 500 error page #24965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
79118aa
fix
wxiaoguang 04f6848
Merge branch 'main' into fix-admin-config
GiteaBot f1a5616
Merge branch 'main' into fix-admin-config
GiteaBot afd4bbd
Merge branch 'main' into fix-admin-config
GiteaBot 17a94df
Merge branch 'main' into fix-admin-config
GiteaBot 6a6a02a
Merge branch 'main' into fix-admin-config
GiteaBot ed7da72
Merge branch 'main' into fix-admin-config
GiteaBot 1724ad6
Merge branch 'main' into fix-admin-config
GiteaBot f492eab
Merge branch 'main' into fix-admin-config
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,41 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"path/filepath" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/unittest" | ||
"code.gitea.io/gitea/modules/test" | ||
"code.gitea.io/gitea/modules/web/middleware" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRenderPanicErrorPage(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
req := &http.Request{URL: &url.URL{}} | ||
req = req.WithContext(middleware.WithContextData(context.Background())) | ||
RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)")) | ||
respContent := w.Body.String() | ||
assert.Contains(t, respContent, `class="page-content status-page-500"`) | ||
assert.Contains(t, respContent, `</html>`) | ||
|
||
// the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page. | ||
// especially when a sub-template causes page error, the HTTP response code is still 200, | ||
// the different "footer" is the only way to know whether a page is fully rendered without error. | ||
assert.False(t, test.IsNormalPageCompleted(respContent)) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
unittest.MainTest(m, &unittest.TestOptions{ | ||
GiteaRootPath: filepath.Join("..", ".."), | ||
}) | ||
} |
This file contains hidden or 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 hidden or 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,23 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package integration | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/test" | ||
"code.gitea.io/gitea/tests" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAdminConfig(t *testing.T) { | ||
defer tests.PrepareTestEnv(t)() | ||
|
||
session := loginUser(t, "user1") | ||
req := NewRequest(t, "GET", "/admin/config") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have more links from |
||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
assert.True(t, test.IsNormalPageCompleted(resp.Body.String())) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.