aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/api_repo_file_update_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/api_repo_file_update_test.go')
-rw-r--r--tests/integration/api_repo_file_update_test.go86
1 files changed, 49 insertions, 37 deletions
diff --git a/tests/integration/api_repo_file_update_test.go b/tests/integration/api_repo_file_update_test.go
index c8ce94a3f5..9a56711da6 100644
--- a/tests/integration/api_repo_file_update_test.go
+++ b/tests/integration/api_repo_file_update_test.go
@@ -8,7 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
- "path/filepath"
+ "path"
"testing"
auth_model "code.gitea.io/gitea/models/auth"
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context"
"github.com/stretchr/testify/assert"
@@ -27,7 +28,7 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
content := "This is updated text"
contentEncoded := base64.StdEncoding.EncodeToString([]byte(content))
return &api.UpdateFileOptions{
- DeleteFileOptions: api.DeleteFileOptions{
+ FileOptionsWithSHA: api.FileOptionsWithSHA{
FileOptions: api.FileOptions{
BranchName: "master",
NewBranchName: "master",
@@ -47,28 +48,30 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
}
}
-func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string) *api.FileResponse {
+func getExpectedFileResponseForUpdate(info apiFileResponseInfo) *api.FileResponse {
sha := "08bd14b2e2852529157324de9c226b3364e76136"
encoding := "base64"
content := "VGhpcyBpcyB1cGRhdGVkIHRleHQ="
- selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
- htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + treePath
+ selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + info.treePath + "?ref=master"
+ htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + info.treePath
gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/" + sha
- downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
- return &api.FileResponse{
+ downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + info.treePath
+ ret := &api.FileResponse{
Content: &api.ContentsResponse{
- Name: filepath.Base(treePath),
- Path: treePath,
- SHA: sha,
- LastCommitSHA: lastCommitSHA,
- Type: "file",
- Size: 20,
- Encoding: &encoding,
- Content: &content,
- URL: &selfURL,
- HTMLURL: &htmlURL,
- GitURL: &gitURL,
- DownloadURL: &downloadURL,
+ Name: path.Base(info.treePath),
+ Path: info.treePath,
+ SHA: sha,
+ LastCommitSHA: util.ToPointer(info.lastCommitSHA),
+ LastCommitterDate: util.ToPointer(info.lastCommitterWhen),
+ LastAuthorDate: util.ToPointer(info.lastAuthorWhen),
+ Type: "file",
+ Size: 20,
+ Encoding: &encoding,
+ Content: &content,
+ URL: &selfURL,
+ HTMLURL: &htmlURL,
+ GitURL: &gitURL,
+ DownloadURL: &downloadURL,
Links: &api.FileLinksResponse{
Self: &selfURL,
GitURL: &gitURL,
@@ -77,10 +80,10 @@ func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string)
},
Commit: &api.FileCommitResponse{
CommitMeta: api.CommitMeta{
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/commits/" + commitID,
- SHA: commitID,
+ URL: setting.AppURL + "api/v1/repos/user2/repo1/git/commits/" + info.commitID,
+ SHA: info.commitID,
},
- HTMLURL: setting.AppURL + "user2/repo1/commit/" + commitID,
+ HTMLURL: setting.AppURL + "user2/repo1/commit/" + info.commitID,
Author: &api.CommitUser{
Identity: api.Identity{
Name: "John Doe",
@@ -102,6 +105,8 @@ func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string)
Payload: "",
},
}
+ normalizeFileContentResponseCommitTime(ret.Content)
+ return ret
}
func TestAPIUpdateFile(t *testing.T) {
@@ -135,17 +140,24 @@ func TestAPIUpdateFile(t *testing.T) {
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK)
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
+ defer gitRepo.Close()
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
- expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
+ expectedFileResponse := getExpectedFileResponseForUpdate(apiFileResponseInfo{
+ commitID: commitID,
+ treePath: treePath,
+ lastCommitSHA: lasCommit.ID.String(),
+ lastCommitterWhen: lasCommit.Committer.When,
+ lastAuthorWhen: lasCommit.Author.When,
+ })
var fileResponse api.FileResponse
DecodeJSON(t, resp, &fileResponse)
- assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
- assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
- assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
- gitRepo.Close()
+ normalizeFileContentResponseCommitTime(fileResponse.Content)
+ assert.Equal(t, expectedFileResponse.Content, fileResponse.Content)
+ assert.Equal(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
+ assert.Equal(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
+ assert.Equal(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
+ assert.Equal(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
}
// Test updating a file in a new branch
@@ -163,10 +175,10 @@ func TestAPIUpdateFile(t *testing.T) {
expectedSHA := "08bd14b2e2852529157324de9c226b3364e76136"
expectedHTMLURL := fmt.Sprintf(setting.AppURL+"user2/repo1/src/branch/new_branch/update/file%d.txt", fileID)
expectedDownloadURL := fmt.Sprintf(setting.AppURL+"user2/repo1/raw/branch/new_branch/update/file%d.txt", fileID)
- assert.EqualValues(t, expectedSHA, fileResponse.Content.SHA)
- assert.EqualValues(t, expectedHTMLURL, *fileResponse.Content.HTMLURL)
- assert.EqualValues(t, expectedDownloadURL, *fileResponse.Content.DownloadURL)
- assert.EqualValues(t, updateFileOptions.Message+"\n", fileResponse.Commit.Message)
+ assert.Equal(t, expectedSHA, fileResponse.Content.SHA)
+ assert.Equal(t, expectedHTMLURL, *fileResponse.Content.HTMLURL)
+ assert.Equal(t, expectedDownloadURL, *fileResponse.Content.DownloadURL)
+ assert.Equal(t, updateFileOptions.Message+"\n", fileResponse.Commit.Message)
// Test updating a file and renaming it
updateFileOptions = getUpdateFileOptions()
@@ -183,9 +195,9 @@ func TestAPIUpdateFile(t *testing.T) {
expectedSHA = "08bd14b2e2852529157324de9c226b3364e76136"
expectedHTMLURL = fmt.Sprintf(setting.AppURL+"user2/repo1/src/branch/master/rename/update/file%d.txt", fileID)
expectedDownloadURL = fmt.Sprintf(setting.AppURL+"user2/repo1/raw/branch/master/rename/update/file%d.txt", fileID)
- assert.EqualValues(t, expectedSHA, fileResponse.Content.SHA)
- assert.EqualValues(t, expectedHTMLURL, *fileResponse.Content.HTMLURL)
- assert.EqualValues(t, expectedDownloadURL, *fileResponse.Content.DownloadURL)
+ assert.Equal(t, expectedSHA, fileResponse.Content.SHA)
+ assert.Equal(t, expectedHTMLURL, *fileResponse.Content.HTMLURL)
+ assert.Equal(t, expectedDownloadURL, *fileResponse.Content.DownloadURL)
// Test updating a file without a message
updateFileOptions = getUpdateFileOptions()
@@ -199,7 +211,7 @@ func TestAPIUpdateFile(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse)
expectedMessage := "Update " + treePath + "\n"
- assert.EqualValues(t, expectedMessage, fileResponse.Commit.Message)
+ assert.Equal(t, expectedMessage, fileResponse.Commit.Message)
// Test updating a file with the wrong SHA
fileID++