123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- // Copyright 2019 The Gitea Authors. All rights reserved.
- // SPDX-License-Identifier: MIT
-
- package integration
-
- import (
- "net/url"
- "path/filepath"
- "strings"
- "testing"
- "time"
-
- repo_model "code.gitea.io/gitea/models/repo"
- "code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/contexttest"
- "code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/setting"
- api "code.gitea.io/gitea/modules/structs"
- files_service "code.gitea.io/gitea/services/repository/files"
-
- "github.com/stretchr/testify/assert"
- )
-
- func getCreateRepoFilesOptions(repo *repo_model.Repository) *files_service.ChangeRepoFilesOptions {
- return &files_service.ChangeRepoFilesOptions{
- Files: []*files_service.ChangeRepoFile{
- {
- Operation: "create",
- TreePath: "new/file.txt",
- ContentReader: strings.NewReader("This is a NEW file"),
- },
- },
- OldBranch: repo.DefaultBranch,
- NewBranch: repo.DefaultBranch,
- Message: "Creates new/file.txt",
- Author: nil,
- Committer: nil,
- }
- }
-
- func getUpdateRepoFilesOptions(repo *repo_model.Repository) *files_service.ChangeRepoFilesOptions {
- return &files_service.ChangeRepoFilesOptions{
- Files: []*files_service.ChangeRepoFile{
- {
- Operation: "update",
- TreePath: "README.md",
- SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
- ContentReader: strings.NewReader("This is UPDATED content for the README file"),
- },
- },
- OldBranch: repo.DefaultBranch,
- NewBranch: repo.DefaultBranch,
- Message: "Updates README.md",
- Author: nil,
- Committer: nil,
- }
- }
-
- func getDeleteRepoFilesOptions(repo *repo_model.Repository) *files_service.ChangeRepoFilesOptions {
- return &files_service.ChangeRepoFilesOptions{
- Files: []*files_service.ChangeRepoFile{
- {
- Operation: "delete",
- TreePath: "README.md",
- SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
- },
- },
- LastCommitID: "",
- OldBranch: repo.DefaultBranch,
- NewBranch: repo.DefaultBranch,
- Message: "Deletes README.md",
- Author: &files_service.IdentityOptions{
- Name: "Bob Smith",
- Email: "bob@smith.com",
- },
- Committer: nil,
- }
- }
-
- func getExpectedFileResponseForRepofilesDelete(u *url.URL) *api.FileResponse {
- // Just returns fields that don't change, i.e. fields with commit SHAs and dates can't be determined
- return &api.FileResponse{
- Content: nil,
- Commit: &api.FileCommitResponse{
- Author: &api.CommitUser{
- Identity: api.Identity{
- Name: "Bob Smith",
- Email: "bob@smith.com",
- },
- },
- Committer: &api.CommitUser{
- Identity: api.Identity{
- Name: "Bob Smith",
- Email: "bob@smith.com",
- },
- },
- Message: "Deletes README.md\n",
- },
- Verification: &api.PayloadCommitVerification{
- Verified: false,
- Reason: "gpg.error.not_signed_commit",
- Signature: "",
- Payload: "",
- },
- }
- }
-
- func getExpectedFileResponseForRepofilesCreate(commitID, lastCommitSHA string) *api.FileResponse {
- treePath := "new/file.txt"
- encoding := "base64"
- content := "VGhpcyBpcyBhIE5FVyBmaWxl"
- selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
- htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + treePath
- gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/103ff9234cefeee5ec5361d22b49fbb04d385885"
- downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
- return &api.FileResponse{
- Content: &api.ContentsResponse{
- Name: filepath.Base(treePath),
- Path: treePath,
- SHA: "103ff9234cefeee5ec5361d22b49fbb04d385885",
- LastCommitSHA: lastCommitSHA,
- Type: "file",
- Size: 18,
- Encoding: &encoding,
- Content: &content,
- URL: &selfURL,
- HTMLURL: &htmlURL,
- GitURL: &gitURL,
- DownloadURL: &downloadURL,
- Links: &api.FileLinksResponse{
- Self: &selfURL,
- GitURL: &gitURL,
- HTMLURL: &htmlURL,
- },
- },
- Commit: &api.FileCommitResponse{
- CommitMeta: api.CommitMeta{
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/commits/" + commitID,
- SHA: commitID,
- },
- HTMLURL: setting.AppURL + "user2/repo1/commit/" + commitID,
- Author: &api.CommitUser{
- Identity: api.Identity{
- Name: "User Two",
- Email: "user2@noreply.example.org",
- },
- Date: time.Now().UTC().Format(time.RFC3339),
- },
- Committer: &api.CommitUser{
- Identity: api.Identity{
- Name: "User Two",
- Email: "user2@noreply.example.org",
- },
- Date: time.Now().UTC().Format(time.RFC3339),
- },
- Parents: []*api.CommitMeta{
- {
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d",
- SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
- },
- },
- Message: "Updates README.md\n",
- Tree: &api.CommitMeta{
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/trees/f93e3a1a1525fb5b91020da86e44810c87a2d7bc",
- SHA: "f93e3a1a1525fb5b91020git dda86e44810c87a2d7bc",
- },
- },
- Verification: &api.PayloadCommitVerification{
- Verified: false,
- Reason: "gpg.error.not_signed_commit",
- Signature: "",
- Payload: "",
- },
- }
- }
-
- func getExpectedFileResponseForRepofilesUpdate(commitID, filename, lastCommitSHA string) *api.FileResponse {
- encoding := "base64"
- content := "VGhpcyBpcyBVUERBVEVEIGNvbnRlbnQgZm9yIHRoZSBSRUFETUUgZmlsZQ=="
- selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + filename + "?ref=master"
- htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + filename
- gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/dbf8d00e022e05b7e5cf7e535de857de57925647"
- downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + filename
- return &api.FileResponse{
- Content: &api.ContentsResponse{
- Name: filename,
- Path: filename,
- SHA: "dbf8d00e022e05b7e5cf7e535de857de57925647",
- LastCommitSHA: lastCommitSHA,
- Type: "file",
- Size: 43,
- Encoding: &encoding,
- Content: &content,
- URL: &selfURL,
- HTMLURL: &htmlURL,
- GitURL: &gitURL,
- DownloadURL: &downloadURL,
- Links: &api.FileLinksResponse{
- Self: &selfURL,
- GitURL: &gitURL,
- HTMLURL: &htmlURL,
- },
- },
- Commit: &api.FileCommitResponse{
- CommitMeta: api.CommitMeta{
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/commits/" + commitID,
- SHA: commitID,
- },
- HTMLURL: setting.AppURL + "user2/repo1/commit/" + commitID,
- Author: &api.CommitUser{
- Identity: api.Identity{
- Name: "User Two",
- Email: "user2@noreply.example.org",
- },
- Date: time.Now().UTC().Format(time.RFC3339),
- },
- Committer: &api.CommitUser{
- Identity: api.Identity{
- Name: "User Two",
- Email: "user2@noreply.example.org",
- },
- Date: time.Now().UTC().Format(time.RFC3339),
- },
- Parents: []*api.CommitMeta{
- {
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d",
- SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
- },
- },
- Message: "Updates README.md\n",
- Tree: &api.CommitMeta{
- URL: setting.AppURL + "api/v1/repos/user2/repo1/git/trees/f93e3a1a1525fb5b91020da86e44810c87a2d7bc",
- SHA: "f93e3a1a1525fb5b91020da86e44810c87a2d7bc",
- },
- },
- Verification: &api.PayloadCommitVerification{
- Verified: false,
- Reason: "gpg.error.not_signed_commit",
- Signature: "",
- Payload: "",
- },
- }
- }
-
- func TestChangeRepoFilesForCreate(t *testing.T) {
- // setup
- onGiteaRun(t, func(t *testing.T, u *url.URL) {
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
-
- repo := ctx.Repo.Repository
- doer := ctx.Doer
- opts := getCreateRepoFilesOptions(repo)
-
- // test
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
-
- // asserts
- assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
- defer gitRepo.Close()
-
- commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
- lastCommit, _ := gitRepo.GetCommitByPath("new/file.txt")
- expectedFileResponse := getExpectedFileResponseForRepofilesCreate(commitID, lastCommit.ID.String())
- assert.NotNil(t, expectedFileResponse)
- if expectedFileResponse != nil {
- assert.EqualValues(t, expectedFileResponse.Content, filesResponse.Files[0])
- assert.EqualValues(t, expectedFileResponse.Commit.SHA, filesResponse.Commit.SHA)
- assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, filesResponse.Commit.HTMLURL)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, filesResponse.Commit.Author.Email)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, filesResponse.Commit.Author.Name)
- }
- })
- }
-
- func TestChangeRepoFilesForUpdate(t *testing.T) {
- // setup
- onGiteaRun(t, func(t *testing.T, u *url.URL) {
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
-
- repo := ctx.Repo.Repository
- doer := ctx.Doer
- opts := getUpdateRepoFilesOptions(repo)
-
- // test
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
-
- // asserts
- assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
- defer gitRepo.Close()
-
- commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
- lastCommit, _ := commit.GetCommitByPath(opts.Files[0].TreePath)
- expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.Files[0].TreePath, lastCommit.ID.String())
- assert.EqualValues(t, expectedFileResponse.Content, filesResponse.Files[0])
- assert.EqualValues(t, expectedFileResponse.Commit.SHA, filesResponse.Commit.SHA)
- assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, filesResponse.Commit.HTMLURL)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, filesResponse.Commit.Author.Email)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, filesResponse.Commit.Author.Name)
- })
- }
-
- func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) {
- // setup
- onGiteaRun(t, func(t *testing.T, u *url.URL) {
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
-
- repo := ctx.Repo.Repository
- doer := ctx.Doer
- opts := getUpdateRepoFilesOptions(repo)
- opts.Files[0].FromTreePath = "README.md"
- opts.Files[0].TreePath = "README_new.md" // new file name, README_new.md
-
- // test
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
-
- // asserts
- assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
- defer gitRepo.Close()
-
- commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
- lastCommit, _ := commit.GetCommitByPath(opts.Files[0].TreePath)
- expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.Files[0].TreePath, lastCommit.ID.String())
- // assert that the old file no longer exists in the last commit of the branch
- fromEntry, err := commit.GetTreeEntryByPath(opts.Files[0].FromTreePath)
- switch err.(type) {
- case git.ErrNotExist:
- // correct, continue
- default:
- t.Fatalf("expected git.ErrNotExist, got:%v", err)
- }
- toEntry, err := commit.GetTreeEntryByPath(opts.Files[0].TreePath)
- assert.NoError(t, err)
- assert.Nil(t, fromEntry) // Should no longer exist here
- assert.NotNil(t, toEntry) // Should exist here
- // assert SHA has remained the same but paths use the new file name
- assert.EqualValues(t, expectedFileResponse.Content.SHA, filesResponse.Files[0].SHA)
- assert.EqualValues(t, expectedFileResponse.Content.Name, filesResponse.Files[0].Name)
- assert.EqualValues(t, expectedFileResponse.Content.Path, filesResponse.Files[0].Path)
- assert.EqualValues(t, expectedFileResponse.Content.URL, filesResponse.Files[0].URL)
- assert.EqualValues(t, expectedFileResponse.Commit.SHA, filesResponse.Commit.SHA)
- assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, filesResponse.Commit.HTMLURL)
- })
- }
-
- // Test opts with branch names removed, should get same results as above test
- func TestChangeRepoFilesWithoutBranchNames(t *testing.T) {
- // setup
- onGiteaRun(t, func(t *testing.T, u *url.URL) {
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
-
- repo := ctx.Repo.Repository
- doer := ctx.Doer
- opts := getUpdateRepoFilesOptions(repo)
- opts.OldBranch = ""
- opts.NewBranch = ""
-
- // test
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
-
- // asserts
- assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
- defer gitRepo.Close()
-
- commit, _ := gitRepo.GetBranchCommit(repo.DefaultBranch)
- lastCommit, _ := commit.GetCommitByPath(opts.Files[0].TreePath)
- expectedFileResponse := getExpectedFileResponseForRepofilesUpdate(commit.ID.String(), opts.Files[0].TreePath, lastCommit.ID.String())
- assert.EqualValues(t, expectedFileResponse.Content, filesResponse.Files[0])
- })
- }
-
- func TestChangeRepoFilesForDelete(t *testing.T) {
- onGiteaRun(t, testDeleteRepoFiles)
- }
-
- func testDeleteRepoFiles(t *testing.T, u *url.URL) {
- // setup
- unittest.PrepareTestEnv(t)
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
- repo := ctx.Repo.Repository
- doer := ctx.Doer
- opts := getDeleteRepoFilesOptions(repo)
-
- t.Run("Delete README.md file", func(t *testing.T) {
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.NoError(t, err)
- expectedFileResponse := getExpectedFileResponseForRepofilesDelete(u)
- assert.NotNil(t, filesResponse)
- assert.Nil(t, filesResponse.Files[0])
- assert.EqualValues(t, expectedFileResponse.Commit.Message, filesResponse.Commit.Message)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Identity, filesResponse.Commit.Author.Identity)
- assert.EqualValues(t, expectedFileResponse.Commit.Committer.Identity, filesResponse.Commit.Committer.Identity)
- assert.EqualValues(t, expectedFileResponse.Verification, filesResponse.Verification)
- })
-
- t.Run("Verify README.md has been deleted", func(t *testing.T) {
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Nil(t, filesResponse)
- expectedError := "repository file does not exist [path: " + opts.Files[0].TreePath + "]"
- assert.EqualError(t, err, expectedError)
- })
- }
-
- // Test opts with branch names removed, same results
- func TestChangeRepoFilesForDeleteWithoutBranchNames(t *testing.T) {
- onGiteaRun(t, testDeleteRepoFilesWithoutBranchNames)
- }
-
- func testDeleteRepoFilesWithoutBranchNames(t *testing.T, u *url.URL) {
- // setup
- unittest.PrepareTestEnv(t)
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
-
- repo := ctx.Repo.Repository
- doer := ctx.Doer
- opts := getDeleteRepoFilesOptions(repo)
- opts.OldBranch = ""
- opts.NewBranch = ""
-
- t.Run("Delete README.md without Branch Name", func(t *testing.T) {
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.NoError(t, err)
- expectedFileResponse := getExpectedFileResponseForRepofilesDelete(u)
- assert.NotNil(t, filesResponse)
- assert.Nil(t, filesResponse.Files[0])
- assert.EqualValues(t, expectedFileResponse.Commit.Message, filesResponse.Commit.Message)
- assert.EqualValues(t, expectedFileResponse.Commit.Author.Identity, filesResponse.Commit.Author.Identity)
- assert.EqualValues(t, expectedFileResponse.Commit.Committer.Identity, filesResponse.Commit.Committer.Identity)
- assert.EqualValues(t, expectedFileResponse.Verification, filesResponse.Verification)
- })
- }
-
- func TestChangeRepoFilesErrors(t *testing.T) {
- // setup
- onGiteaRun(t, func(t *testing.T, u *url.URL) {
- ctx, _ := contexttest.MockContext(t, "user2/repo1")
- ctx.SetParams(":id", "1")
- contexttest.LoadRepo(t, ctx, 1)
- contexttest.LoadRepoCommit(t, ctx)
- contexttest.LoadUser(t, ctx, 2)
- contexttest.LoadGitRepo(t, ctx)
- defer ctx.Repo.GitRepo.Close()
-
- repo := ctx.Repo.Repository
- doer := ctx.Doer
-
- t.Run("bad branch", func(t *testing.T) {
- opts := getUpdateRepoFilesOptions(repo)
- opts.OldBranch = "bad_branch"
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Error(t, err)
- assert.Nil(t, filesResponse)
- expectedError := "branch does not exist [name: " + opts.OldBranch + "]"
- assert.EqualError(t, err, expectedError)
- })
-
- t.Run("bad SHA", func(t *testing.T) {
- opts := getUpdateRepoFilesOptions(repo)
- origSHA := opts.Files[0].SHA
- opts.Files[0].SHA = "bad_sha"
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Nil(t, filesResponse)
- assert.Error(t, err)
- expectedError := "sha does not match [given: " + opts.Files[0].SHA + ", expected: " + origSHA + "]"
- assert.EqualError(t, err, expectedError)
- })
-
- t.Run("new branch already exists", func(t *testing.T) {
- opts := getUpdateRepoFilesOptions(repo)
- opts.NewBranch = "develop"
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Nil(t, filesResponse)
- assert.Error(t, err)
- expectedError := "branch already exists [name: " + opts.NewBranch + "]"
- assert.EqualError(t, err, expectedError)
- })
-
- t.Run("treePath is empty:", func(t *testing.T) {
- opts := getUpdateRepoFilesOptions(repo)
- opts.Files[0].TreePath = ""
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Nil(t, filesResponse)
- assert.Error(t, err)
- expectedError := "path contains a malformed path component [path: ]"
- assert.EqualError(t, err, expectedError)
- })
-
- t.Run("treePath is a git directory:", func(t *testing.T) {
- opts := getUpdateRepoFilesOptions(repo)
- opts.Files[0].TreePath = ".git"
- filesResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Nil(t, filesResponse)
- assert.Error(t, err)
- expectedError := "path contains a malformed path component [path: " + opts.Files[0].TreePath + "]"
- assert.EqualError(t, err, expectedError)
- })
-
- t.Run("create file that already exists", func(t *testing.T) {
- opts := getCreateRepoFilesOptions(repo)
- opts.Files[0].TreePath = "README.md" // already exists
- fileResponse, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, doer, opts)
- assert.Nil(t, fileResponse)
- assert.Error(t, err)
- expectedError := "repository file already exists [path: " + opts.Files[0].TreePath + "]"
- assert.EqualError(t, err, expectedError)
- })
- })
- }
|