Skip to content

Commit 9c47853

Browse files
committed
integration tests: WIP
1 parent f3f4f6d commit 9c47853

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
@@ -12,6 +12,7 @@ import (
1212

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

0 commit comments

Comments
 (0)