Skip to content

Commit b3f6b8c

Browse files
committed
fix tests
1 parent 2cfeb0b commit b3f6b8c

File tree

3 files changed

+33
-55
lines changed

3 files changed

+33
-55
lines changed

tests/integration/api_repo_file_helpers.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919

2020
type createFileInBranchOptions struct {
2121
OldBranch, NewBranch string
22+
CommitMessage string
23+
CommitterName string
24+
CommitterEmail string
2225
}
2326

2427
func testCreateFileInBranch(t *testing.T, user *user_model.User, repo *repo_model.Repository, createOpts createFileInBranchOptions, files map[string]string) *api.FilesResponse {
@@ -29,7 +32,17 @@ func testCreateFileInBranch(t *testing.T, user *user_model.User, repo *repo_mode
2932

3033
func createFileInBranch(user *user_model.User, repo *repo_model.Repository, createOpts createFileInBranchOptions, files map[string]string) (*api.FilesResponse, error) {
3134
ctx := context.TODO()
32-
opts := &files_service.ChangeRepoFilesOptions{OldBranch: createOpts.OldBranch, NewBranch: createOpts.NewBranch}
35+
opts := &files_service.ChangeRepoFilesOptions{
36+
OldBranch: createOpts.OldBranch,
37+
NewBranch: createOpts.NewBranch,
38+
Message: createOpts.CommitMessage,
39+
}
40+
if createOpts.CommitterName != "" || createOpts.CommitterEmail != "" {
41+
opts.Committer = &files_service.IdentityOptions{
42+
GitUserName: createOpts.CommitterName,
43+
GitUserEmail: createOpts.CommitterEmail,
44+
}
45+
}
3346
for path, content := range files {
3447
opts.Files = append(opts.Files, &files_service.ChangeRepoFile{
3548
Operation: "create",

tests/integration/editor_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,6 @@ func testCreateFile(t *testing.T, session *TestSession, user, repo, baseBranchNa
8383
})
8484
}
8585

86-
func testCreateFileWithCommitMessage(t *testing.T, session *TestSession, user, repo, baseBranchName, newBranchName, filePath, content, commitSummary, commitMessage string) {
87-
commitChoice := "direct"
88-
if newBranchName != "" && newBranchName != baseBranchName {
89-
commitChoice = "commit-to-new-branch"
90-
}
91-
testEditorActionEdit(t, session, user, repo, "_new", baseBranchName, "", map[string]string{
92-
"tree_path": filePath,
93-
"content": content,
94-
"commit_choice": commitChoice,
95-
"new_branch_name": newBranchName,
96-
"commit_summary": commitSummary,
97-
"commit_message": commitMessage,
98-
})
99-
}
100-
10186
func testEditorProtectedBranch(t *testing.T) {
10287
session := loginUser(t, "user2")
10388
// Change the "master" branch to "protected"
@@ -154,15 +139,6 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
154139
})
155140
}
156141

157-
func testEditFileWithCommitMessage(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent, commitSummary, commitMessage string) {
158-
testEditorActionEdit(t, session, user, repo, "_edit", branch, filePath, map[string]string{
159-
"content": newContent,
160-
"commit_choice": "direct",
161-
"commit_summary": commitSummary,
162-
"commit_message": commitMessage,
163-
})
164-
}
165-
166142
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) {
167143
testEditorActionEdit(t, session, user, repo, "_edit", branch, filePath, map[string]string{
168144
"content": newContent,

tests/integration/pull_merge_test.go

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
auth_model "code.gitea.io/gitea/models/auth"
2020
git_model "code.gitea.io/gitea/models/git"
2121
issues_model "code.gitea.io/gitea/models/issues"
22-
"code.gitea.io/gitea/models/perm"
2322
pull_model "code.gitea.io/gitea/models/pull"
2423
repo_model "code.gitea.io/gitea/models/repo"
2524
"code.gitea.io/gitea/models/unittest"
@@ -34,6 +33,7 @@ import (
3433
api "code.gitea.io/gitea/modules/structs"
3534
"code.gitea.io/gitea/modules/test"
3635
"code.gitea.io/gitea/modules/translation"
36+
"code.gitea.io/gitea/modules/util"
3737
"code.gitea.io/gitea/services/automerge"
3838
"code.gitea.io/gitea/services/automergequeue"
3939
pull_service "code.gitea.io/gitea/services/pull"
@@ -1186,20 +1186,9 @@ func TestPullSquashMessage(t *testing.T) {
11861186
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
11871187
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
11881188
user2Session := loginUser(t, user2.Name)
1189-
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
1190-
user4Session := loginUser(t, user4.Name)
11911189

1192-
sessions := map[string]*TestSession{
1193-
user2.Name: user2Session,
1194-
user4.Name: user4Session,
1195-
}
1196-
1197-
// Enable POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES
1198-
resetFunc1 := test.MockVariableValue(&setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages, true)
1199-
defer resetFunc1()
1200-
// Set DEFAULT_MERGE_MESSAGE_SIZE
1201-
resetFunc2 := test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 512)
1202-
defer resetFunc2()
1190+
defer test.MockVariableValue(&setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages, true)()
1191+
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 512)()
12031192

12041193
repo, err := repo_service.CreateRepository(t.Context(), user2, user2, repo_service.CreateRepoOptions{
12051194
Name: "squash-message-test",
@@ -1209,7 +1198,6 @@ func TestPullSquashMessage(t *testing.T) {
12091198
DefaultBranch: "main",
12101199
})
12111200
assert.NoError(t, err)
1212-
doAPIAddCollaborator(NewAPITestContext(t, repo.OwnerName, repo.Name, auth_model.AccessTokenScopeWriteRepository), user4.Name, perm.AccessModeWrite)(t)
12131201

12141202
type commitInfo struct {
12151203
userName string
@@ -1280,32 +1268,32 @@ Implements a new email notification module.
12801268
{
12811269
userName: user2.Name,
12821270
commitSummary: "Add advanced validation logic for user onboarding",
1283-
commitMessage: `This commit introduces a comprehensive validation layer for the user onboarding flow.
1284-
The primary goal is to ensure that all input data is strictly validated before being processed by downstream services.
1271+
commitMessage: `This commit introduces a comprehensive validation layer for the user onboarding flow.
1272+
The primary goal is to ensure that all input data is strictly validated before being processed by downstream services.
12851273
This improves system reliability and significantly reduces runtime exceptions in the registration pipeline.
12861274
12871275
The validation logic includes:
12881276
12891277
1. Email format checking using RFC 5322-compliant patterns.
12901278
2. Username length and character limitation enforcement.
12911279
3. Password strength enforcement, including:
1292-
- Minimum length checks
1293-
- Mixed character type detection
1280+
- Minimum length checks
1281+
- Mixed character type detection
12941282
- Optional entropy-based scoring
12951283
4. Optional phone number validation using region-specific rules.
12961284
`,
12971285
},
12981286
},
12991287
expectedMessage: `* Add advanced validation logic for user onboarding
13001288
1301-
This commit introduces a comprehensive validation layer for the user onboarding flow.
1302-
The primary goal is to ensure that all input data is strictly validated before being processed by downstream services.
1289+
This commit introduces a comprehensive validation layer for the user onboarding flow.
1290+
The primary goal is to ensure that all input data is strictly validated before being processed by downstream services.
13031291
This improves system reliability and significantly reduces runtime exceptions in the registration pipeline.
13041292
13051293
The validation logic includes:
13061294
13071295
1. Email format checking using RFC 5322-compliant patterns.
1308-
2. Username length and character limitation enfor...`,
1296+
2. Username length and character limitation enforceme...`,
13091297
},
13101298
{
13111299
name: "Test Co-authored-by",
@@ -1315,7 +1303,7 @@ The validation logic includes:
13151303
commitSummary: "Implement the login endpoint",
13161304
},
13171305
{
1318-
userName: user4.Name,
1306+
userName: "user4",
13191307
commitSummary: "Validate request body",
13201308
},
13211309
},
@@ -1331,16 +1319,17 @@ Co-authored-by: user4 <[email protected]>
13311319
}
13321320

13331321
for tcNum, tc := range testCases {
1334-
branchName := "test-branch-" + strconv.Itoa(tcNum)
1335-
fileName := fmt.Sprintf("test-file-%d.txt", tcNum)
13361322
t.Run(tc.name, func(t *testing.T) {
1323+
branchName := "test-branch-" + strconv.Itoa(tcNum)
13371324
for infoIdx, info := range tc.commitInfos {
1338-
content := "content-" + strconv.Itoa(infoIdx)
1339-
if infoIdx == 0 {
1340-
testCreateFileWithCommitMessage(t, sessions[info.userName], repo.OwnerName, repo.Name, repo.DefaultBranch, branchName, fileName, content, info.commitSummary, info.commitMessage)
1341-
} else {
1342-
testEditFileWithCommitMessage(t, sessions[info.userName], repo.OwnerName, repo.Name, branchName, fileName, content, info.commitSummary, info.commitMessage)
1325+
createFileOpts := createFileInBranchOptions{
1326+
CommitMessage: info.commitSummary + "\n\n" + info.commitMessage,
1327+
CommitterName: info.userName,
1328+
CommitterEmail: util.Iif(info.userName != "", info.userName+"@example.com", ""),
1329+
OldBranch: util.Iif(infoIdx == 0, "main", branchName),
1330+
NewBranch: branchName,
13431331
}
1332+
testCreateFileInBranch(t, user2, repo, createFileOpts, map[string]string{"dummy-file-" + strconv.Itoa(infoIdx): "dummy content"})
13441333
}
13451334
resp := testPullCreateDirectly(t, user2Session, createPullRequestOptions{
13461335
BaseRepoOwner: user2.Name,

0 commit comments

Comments
 (0)