Skip to content

Commit 3462b2d

Browse files
committed
update test
1 parent 378fc6d commit 3462b2d

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

tests/integration/api_repo_file_create_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func getCreateFileOptions() api.CreateFileOptions {
5050
}
5151
}
5252

53-
func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCommitSHA string) *api.FileResponse {
53+
func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCommitSHA string, latestCommitWhen time.Time) *api.FileResponse {
5454
sha := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
5555
encoding := "base64"
5656
content := "VGhpcyBpcyBuZXcgdGV4dA=="
@@ -60,18 +60,19 @@ func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCo
6060
downloadURL := setting.AppURL + repoFullName + "/raw/branch/master/" + treePath
6161
return &api.FileResponse{
6262
Content: &api.ContentsResponse{
63-
Name: filepath.Base(treePath),
64-
Path: treePath,
65-
SHA: sha,
66-
LastCommitSHA: latestCommitSHA,
67-
Size: 16,
68-
Type: "file",
69-
Encoding: &encoding,
70-
Content: &content,
71-
URL: &selfURL,
72-
HTMLURL: &htmlURL,
73-
GitURL: &gitURL,
74-
DownloadURL: &downloadURL,
63+
Name: filepath.Base(treePath),
64+
Path: treePath,
65+
SHA: sha,
66+
LastCommitSHA: latestCommitSHA,
67+
LastCommitWhen: latestCommitWhen,
68+
Size: 16,
69+
Type: "file",
70+
Encoding: &encoding,
71+
Content: &content,
72+
URL: &selfURL,
73+
HTMLURL: &htmlURL,
74+
GitURL: &gitURL,
75+
DownloadURL: &downloadURL,
7576
Links: &api.FileLinksResponse{
7677
Self: &selfURL,
7778
GitURL: &gitURL,
@@ -170,7 +171,7 @@ func TestAPICreateFile(t *testing.T) {
170171
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
171172
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
172173
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
173-
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String())
174+
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String(), latestCommit.Committer.When)
174175
var fileResponse api.FileResponse
175176
DecodeJSON(t, resp, &fileResponse)
176177
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
@@ -288,7 +289,7 @@ func TestAPICreateFile(t *testing.T) {
288289
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
289290
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
290291
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
291-
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String())
292+
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String(), latestCommit.Committer.When)
292293
DecodeJSON(t, resp, &fileResponse)
293294
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
294295
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)

tests/integration/api_repo_file_update_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"path/filepath"
1313
"testing"
14+
"time"
1415

1516
auth_model "code.gitea.io/gitea/models/auth"
1617
repo_model "code.gitea.io/gitea/models/repo"
@@ -48,7 +49,7 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
4849
}
4950
}
5051

51-
func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string) *api.FileResponse {
52+
func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string, lastCommitWhen time.Time) *api.FileResponse {
5253
sha := "08bd14b2e2852529157324de9c226b3364e76136"
5354
encoding := "base64"
5455
content := "VGhpcyBpcyB1cGRhdGVkIHRleHQ="
@@ -58,18 +59,19 @@ func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string)
5859
downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
5960
return &api.FileResponse{
6061
Content: &api.ContentsResponse{
61-
Name: filepath.Base(treePath),
62-
Path: treePath,
63-
SHA: sha,
64-
LastCommitSHA: lastCommitSHA,
65-
Type: "file",
66-
Size: 20,
67-
Encoding: &encoding,
68-
Content: &content,
69-
URL: &selfURL,
70-
HTMLURL: &htmlURL,
71-
GitURL: &gitURL,
72-
DownloadURL: &downloadURL,
62+
Name: filepath.Base(treePath),
63+
Path: treePath,
64+
SHA: sha,
65+
LastCommitSHA: lastCommitSHA,
66+
LastCommitWhen: lastCommitWhen,
67+
Type: "file",
68+
Size: 20,
69+
Encoding: &encoding,
70+
Content: &content,
71+
URL: &selfURL,
72+
HTMLURL: &htmlURL,
73+
GitURL: &gitURL,
74+
DownloadURL: &downloadURL,
7375
Links: &api.FileLinksResponse{
7476
Self: &selfURL,
7577
GitURL: &gitURL,
@@ -138,7 +140,7 @@ func TestAPIUpdateFile(t *testing.T) {
138140
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
139141
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
140142
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
141-
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
143+
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String(), lasCommit.Committer.When)
142144
var fileResponse api.FileResponse
143145
DecodeJSON(t, resp, &fileResponse)
144146
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)

tests/integration/api_repo_files_change_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func TestAPIChangeFiles(t *testing.T) {
100100
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
101101
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
102102
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
103-
expectedCreateFileResponse := getExpectedFileResponseForCreate(fmt.Sprintf("%v/%v", user2.Name, repo1.Name), commitID, createTreePath, createLasCommit.ID.String())
104-
expectedUpdateFileResponse := getExpectedFileResponseForUpdate(commitID, updateTreePath, updateLastCommit.ID.String())
103+
expectedCreateFileResponse := getExpectedFileResponseForCreate(fmt.Sprintf("%v/%v", user2.Name, repo1.Name), commitID, createTreePath, createLasCommit.ID.String(), createLasCommit.Committer.When)
104+
expectedUpdateFileResponse := getExpectedFileResponseForUpdate(commitID, updateTreePath, updateLastCommit.ID.String(), updateLastCommit.Committer.When)
105105
var filesResponse api.FilesResponse
106106
DecodeJSON(t, resp, &filesResponse)
107107

0 commit comments

Comments
 (0)