mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-02 15:09:33 -05:00
update test
This commit is contained in:
parent
378fc6d8dc
commit
3462b2d296
@ -50,7 +50,7 @@ func getCreateFileOptions() api.CreateFileOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCommitSHA string) *api.FileResponse {
|
func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCommitSHA string, latestCommitWhen time.Time) *api.FileResponse {
|
||||||
sha := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
|
sha := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
|
||||||
encoding := "base64"
|
encoding := "base64"
|
||||||
content := "VGhpcyBpcyBuZXcgdGV4dA=="
|
content := "VGhpcyBpcyBuZXcgdGV4dA=="
|
||||||
@ -64,6 +64,7 @@ func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCo
|
|||||||
Path: treePath,
|
Path: treePath,
|
||||||
SHA: sha,
|
SHA: sha,
|
||||||
LastCommitSHA: latestCommitSHA,
|
LastCommitSHA: latestCommitSHA,
|
||||||
|
LastCommitWhen: latestCommitWhen,
|
||||||
Size: 16,
|
Size: 16,
|
||||||
Type: "file",
|
Type: "file",
|
||||||
Encoding: &encoding,
|
Encoding: &encoding,
|
||||||
@ -170,7 +171,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String(), latestCommit.Committer.When)
|
||||||
var fileResponse api.FileResponse
|
var fileResponse api.FileResponse
|
||||||
DecodeJSON(t, resp, &fileResponse)
|
DecodeJSON(t, resp, &fileResponse)
|
||||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||||
@ -288,7 +289,7 @@ func TestAPICreateFile(t *testing.T) {
|
|||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
|
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String(), latestCommit.Committer.When)
|
||||||
DecodeJSON(t, resp, &fileResponse)
|
DecodeJSON(t, resp, &fileResponse)
|
||||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
|
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
@ -48,7 +49,7 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string) *api.FileResponse {
|
func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string, lastCommitWhen time.Time) *api.FileResponse {
|
||||||
sha := "08bd14b2e2852529157324de9c226b3364e76136"
|
sha := "08bd14b2e2852529157324de9c226b3364e76136"
|
||||||
encoding := "base64"
|
encoding := "base64"
|
||||||
content := "VGhpcyBpcyB1cGRhdGVkIHRleHQ="
|
content := "VGhpcyBpcyB1cGRhdGVkIHRleHQ="
|
||||||
@ -62,6 +63,7 @@ func getExpectedFileResponseForUpdate(commitID, treePath, lastCommitSHA string)
|
|||||||
Path: treePath,
|
Path: treePath,
|
||||||
SHA: sha,
|
SHA: sha,
|
||||||
LastCommitSHA: lastCommitSHA,
|
LastCommitSHA: lastCommitSHA,
|
||||||
|
LastCommitWhen: lastCommitWhen,
|
||||||
Type: "file",
|
Type: "file",
|
||||||
Size: 20,
|
Size: 20,
|
||||||
Encoding: &encoding,
|
Encoding: &encoding,
|
||||||
@ -138,7 +140,7 @@ func TestAPIUpdateFile(t *testing.T) {
|
|||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
|
||||||
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
|
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
|
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String(), lasCommit.Committer.When)
|
||||||
var fileResponse api.FileResponse
|
var fileResponse api.FileResponse
|
||||||
DecodeJSON(t, resp, &fileResponse)
|
DecodeJSON(t, resp, &fileResponse)
|
||||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||||
|
@ -100,8 +100,8 @@ func TestAPIChangeFiles(t *testing.T) {
|
|||||||
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
|
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
|
||||||
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
|
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
|
||||||
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
|
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
|
||||||
expectedCreateFileResponse := getExpectedFileResponseForCreate(fmt.Sprintf("%v/%v", user2.Name, repo1.Name), commitID, createTreePath, createLasCommit.ID.String())
|
expectedCreateFileResponse := getExpectedFileResponseForCreate(fmt.Sprintf("%v/%v", user2.Name, repo1.Name), commitID, createTreePath, createLasCommit.ID.String(), createLasCommit.Committer.When)
|
||||||
expectedUpdateFileResponse := getExpectedFileResponseForUpdate(commitID, updateTreePath, updateLastCommit.ID.String())
|
expectedUpdateFileResponse := getExpectedFileResponseForUpdate(commitID, updateTreePath, updateLastCommit.ID.String(), updateLastCommit.Committer.When)
|
||||||
var filesResponse api.FilesResponse
|
var filesResponse api.FilesResponse
|
||||||
DecodeJSON(t, resp, &filesResponse)
|
DecodeJSON(t, resp, &filesResponse)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user