Skip to content

Commit e1e660a

Browse files
committed
integration tests: WIP
1 parent 5511709 commit e1e660a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/integration/compare_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/models/db"
1414
"code.gitea.io/gitea/models/unittest"
1515
user_model "code.gitea.io/gitea/models/user"
16+
"code.gitea.io/gitea/modules/gitrepo"
1617
"code.gitea.io/gitea/modules/test"
1718
repo_service "code.gitea.io/gitea/services/repository"
1819
"code.gitea.io/gitea/tests"
@@ -158,3 +159,41 @@ func TestCompareCodeExpand(t *testing.T) {
158159
}
159160
})
160161
}
162+
163+
func TestCompareRawDiff(t *testing.T) {
164+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
165+
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
166+
repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{
167+
Name: "test_raw_diff",
168+
Readme: "Default",
169+
AutoInit: true,
170+
DefaultBranch: "main",
171+
}, true)
172+
assert.NoError(t, err)
173+
session := loginUser(t, user1.Name)
174+
r, _ := gitrepo.OpenRepository(db.DefaultContext, repo)
175+
oldRef, _ := r.GetBranchCommit(repo.DefaultBranch)
176+
testEditFile(t, session, user1.Name, repo.Name, "main", "README.md", strings.Repeat("a\n", 2))
177+
newRef, _ := r.GetBranchCommit(repo.DefaultBranch)
178+
fmt.Println("oldRef", oldRef.ID.String())
179+
fmt.Println("newRef", newRef.ID.String())
180+
181+
req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.diff", oldRef.ID.String(), newRef.ID.String()))
182+
resp := session.MakeRequest(t, req, http.StatusOK)
183+
fmt.Println("resp", resp.Body.String())
184+
185+
expected := fmt.Sprintf(`diff --git a/README.md b/README.md
186+
index %s..%s 100644
187+
--- a/README.md
188+
+++ b/README.md
189+
@@ -1,2 +1,2 @@
190+
-# test_raw_diff
191+
-
192+
+a
193+
+a
194+
`,
195+
oldRef.ID.String()[:7], newRef.ID.String()[:7])
196+
197+
assert.Equal(t, resp.Body.String(), expected)
198+
})
199+
}

0 commit comments

Comments
 (0)