[BUG] Reflect Cargo index state in settings
- Currently in the Cargo section of the packages setting menu two buttons are always shown, "Initalize index" and "Rebuild index", however only of these should be shown depending on the state of the index, if there's no index the "Initalize index" button should be shown and if there's an index the "Rebuild index" button should be shown. This patch does exactly that. - Resolves #2628
This commit is contained in:
parent
17ef8145a8
commit
461f925554
5 changed files with 87 additions and 10 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
cargo_module "code.gitea.io/gitea/modules/packages/cargo"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
cargo_router "code.gitea.io/gitea/routers/api/packages/cargo"
|
||||
gitea_context "code.gitea.io/gitea/services/context"
|
||||
cargo_service "code.gitea.io/gitea/services/packages/cargo"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
|
@ -385,3 +386,62 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
|
|||
assert.Equal(t, user.DisplayName(), owners.Users[0].Name)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRebuildCargo(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *neturl.URL) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
session := loginUser(t, user.Name)
|
||||
unittest.AssertExistsIf(t, false, &repo_model.Repository{OwnerID: user.ID, Name: cargo_service.IndexRepositoryName})
|
||||
|
||||
t.Run("No index", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequestWithValues(t, "POST", "/user/settings/packages/cargo/rebuild", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings/packages"),
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
flashCookie := session.GetCookie(gitea_context.CookieNameFlash)
|
||||
assert.NotNil(t, flashCookie)
|
||||
assert.EqualValues(t, "error%3DCannot%2Brebuild%252C%2Bno%2Bindex%2Bis%2Binitialized.", flashCookie.Value)
|
||||
unittest.AssertExistsIf(t, false, &repo_model.Repository{OwnerID: user.ID, Name: cargo_service.IndexRepositoryName})
|
||||
})
|
||||
|
||||
t.Run("Initialize Cargo", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user/settings/packages")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
htmlDoc.AssertElement(t, `form[action="/user/settings/packages/cargo/rebuild"]`, false)
|
||||
htmlDoc.AssertElement(t, `form[action="/user/settings/packages/cargo/initialize"]`, true)
|
||||
|
||||
req = NewRequestWithValues(t, "POST", "/user/settings/packages/cargo/initialize", map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
unittest.AssertExistsIf(t, true, &repo_model.Repository{OwnerID: user.ID, Name: cargo_service.IndexRepositoryName})
|
||||
|
||||
req = NewRequest(t, "GET", "/user/settings/packages")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
|
||||
htmlDoc.AssertElement(t, `form[action="/user/settings/packages/cargo/rebuild"]`, true)
|
||||
htmlDoc.AssertElement(t, `form[action="/user/settings/packages/cargo/initialize"]`, false)
|
||||
})
|
||||
|
||||
t.Run("With index", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequestWithValues(t, "POST", "/user/settings/packages/cargo/rebuild", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings/packages"),
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
flashCookie := session.GetCookie(gitea_context.CookieNameFlash)
|
||||
assert.NotNil(t, flashCookie)
|
||||
assert.EqualValues(t, "success%3DThe%2BCargo%2Bindex%2Bwas%2Bsuccessfully%2Brebuild.", flashCookie.Value)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue