|
|
|
@@ -9,7 +9,6 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
@@ -158,7 +157,7 @@ diff --git "\\a/README.md" "\\b/README.md"
|
|
|
|
|
}
|
|
|
|
|
for _, testcase := range tests {
|
|
|
|
|
t.Run(testcase.name, func(t *testing.T) {
|
|
|
|
|
got, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), testcase.skipTo)
|
|
|
|
|
got, err := ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), testcase.skipTo)
|
|
|
|
|
if (err != nil) != testcase.wantErr {
|
|
|
|
|
t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr)
|
|
|
|
|
return
|
|
|
|
@@ -377,7 +376,7 @@ index 6961180..9ba1a00 100644
|
|
|
|
|
|
|
|
|
|
for _, testcase := range tests {
|
|
|
|
|
t.Run(testcase.name, func(t *testing.T) {
|
|
|
|
|
got, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
|
|
|
|
got, err := ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
|
|
|
|
if (err != nil) != testcase.wantErr {
|
|
|
|
|
t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr)
|
|
|
|
|
return
|
|
|
|
@@ -420,21 +419,21 @@ index 0000000..6bb8f39
|
|
|
|
|
diffBuilder.WriteString("+line" + strconv.Itoa(i) + "\n")
|
|
|
|
|
}
|
|
|
|
|
diff = diffBuilder.String()
|
|
|
|
|
result, err := ParsePatch(db.DefaultContext, 20, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
result, err := ParsePatch(t.Context(), 20, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("There should not be an error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if !result.Files[0].IsIncomplete {
|
|
|
|
|
t.Errorf("Files should be incomplete! %v", result.Files[0])
|
|
|
|
|
}
|
|
|
|
|
result, err = ParsePatch(db.DefaultContext, 40, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
result, err = ParsePatch(t.Context(), 40, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("There should not be an error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if result.Files[0].IsIncomplete {
|
|
|
|
|
t.Errorf("Files should not be incomplete! %v", result.Files[0])
|
|
|
|
|
}
|
|
|
|
|
result, err = ParsePatch(db.DefaultContext, 40, 5, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
result, err = ParsePatch(t.Context(), 40, 5, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("There should not be an error: %v", err)
|
|
|
|
|
}
|
|
|
|
@@ -465,14 +464,14 @@ index 0000000..6bb8f39
|
|
|
|
|
diffBuilder.WriteString("+line" + strconv.Itoa(35) + "\n")
|
|
|
|
|
diff = diffBuilder.String()
|
|
|
|
|
|
|
|
|
|
result, err = ParsePatch(db.DefaultContext, 20, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
result, err = ParsePatch(t.Context(), 20, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("There should not be an error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if !result.Files[0].IsIncomplete {
|
|
|
|
|
t.Errorf("Files should be incomplete! %v", result.Files[0])
|
|
|
|
|
}
|
|
|
|
|
result, err = ParsePatch(db.DefaultContext, 40, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
result, err = ParsePatch(t.Context(), 40, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("There should not be an error: %v", err)
|
|
|
|
|
}
|
|
|
|
@@ -491,7 +490,7 @@ index 0000000..6bb8f39
|
|
|
|
|
Docker Pulls
|
|
|
|
|
+ cut off
|
|
|
|
|
+ cut off`
|
|
|
|
|
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("ParsePatch failed: %s", err)
|
|
|
|
|
}
|
|
|
|
@@ -507,7 +506,7 @@ index 0000000..6bb8f39
|
|
|
|
|
Docker Pulls
|
|
|
|
|
+ cut off
|
|
|
|
|
+ cut off`
|
|
|
|
|
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "")
|
|
|
|
|
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("ParsePatch failed: %s", err)
|
|
|
|
|
}
|
|
|
|
@@ -523,7 +522,7 @@ index 0000000..6bb8f39
|
|
|
|
|
Docker Pulls
|
|
|
|
|
+ cut off
|
|
|
|
|
+ cut off`
|
|
|
|
|
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "")
|
|
|
|
|
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("ParsePatch failed: %s", err)
|
|
|
|
|
}
|
|
|
|
@@ -539,7 +538,7 @@ index 0000000..6bb8f39
|
|
|
|
|
Docker Pulls
|
|
|
|
|
+ cut off
|
|
|
|
|
+ cut off`
|
|
|
|
|
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "")
|
|
|
|
|
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("ParsePatch failed: %s", err)
|
|
|
|
|
}
|
|
|
|
@@ -571,7 +570,7 @@ func TestDiff_LoadCommentsNoOutdated(t *testing.T) {
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
|
diff := setupDefaultDiff()
|
|
|
|
|
assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user, false))
|
|
|
|
|
assert.NoError(t, diff.LoadComments(t.Context(), issue, user, false))
|
|
|
|
|
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -581,7 +580,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
|
diff := setupDefaultDiff()
|
|
|
|
|
assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user, true))
|
|
|
|
|
assert.NoError(t, diff.LoadComments(t.Context(), issue, user, true))
|
|
|
|
|
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 3)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -637,6 +636,6 @@ func TestNoCrashes(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
for _, testcase := range tests {
|
|
|
|
|
// It shouldn't crash, so don't care about the output.
|
|
|
|
|
ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
|
|
|
|
ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|