Add tests for webhook and fix some webhook bugs (#33396)

This PR created a mock webhook server in the tests and added integration
tests for generic webhooks.
It also fixes bugs in package webhooks and pull request comment
webhooks.
This commit is contained in:
Lunny Xiao 2025-01-29 19:09:48 -08:00 committed by GitHub
parent 256b94e9e9
commit 75940a0191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 630 additions and 89 deletions

View file

@ -172,6 +172,19 @@ func TestAPIListWikiPages(t *testing.T) {
assert.Equal(t, dummymeta, meta)
}
func testAPICreateWikiPage(t *testing.T, session *TestSession, userName, repoName, title string, status int) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/new", userName, repoName)
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateWikiPageOptions{
Title: title,
ContentBase64: base64.StdEncoding.EncodeToString([]byte("Wiki page content for API unit tests")),
Message: "",
}).AddTokenAuth(token)
MakeRequest(t, req, status)
}
func TestAPINewWikiPage(t *testing.T) {
for _, title := range []string{
"New page",
@ -180,16 +193,7 @@ func TestAPINewWikiPage(t *testing.T) {
defer tests.PrepareTestEnv(t)()
username := "user2"
session := loginUser(t, username)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/new", username, "repo1")
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateWikiPageOptions{
Title: title,
ContentBase64: base64.StdEncoding.EncodeToString([]byte("Wiki page content for API unit tests")),
Message: "",
}).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated)
testAPICreateWikiPage(t, session, username, "repo1", title, http.StatusCreated)
}
}