summaryrefslogtreecommitdiffstats
path: root/services/repository
diff options
context:
space:
mode:
Diffstat (limited to 'services/repository')
-rw-r--r--services/repository/adopt_test.go20
-rw-r--r--services/repository/archiver/archiver_test.go32
-rw-r--r--services/repository/avatar_test.go15
-rw-r--r--services/repository/collaboration_test.go10
-rw-r--r--services/repository/contributors_graph_test.go9
-rw-r--r--services/repository/create_test.go27
-rw-r--r--services/repository/files/content_test.go29
-rw-r--r--services/repository/files/diff_test.go13
-rw-r--r--services/repository/files/file_test.go3
-rw-r--r--services/repository/files/temp_repo_test.go8
-rw-r--r--services/repository/files/tree_test.go3
-rw-r--r--services/repository/fork_test.go5
-rw-r--r--services/repository/lfs_test.go21
-rw-r--r--services/repository/repository_test.go7
-rw-r--r--services/repository/review_test.go7
-rw-r--r--services/repository/transfer_test.go37
16 files changed, 127 insertions, 119 deletions
diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go
index 454d9a76b9..71fb1fc885 100644
--- a/services/repository/adopt_test.go
+++ b/services/repository/adopt_test.go
@@ -37,13 +37,13 @@ func TestCheckUnadoptedRepositories_Add(t *testing.T) {
}
func TestCheckUnadoptedRepositories(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
//
// Non existent user
//
unadopted := &unadoptedRepositories{start: 0, end: 100}
err := checkUnadoptedRepositories(db.DefaultContext, "notauser", []string{"repo"}, unadopted)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, unadopted.repositories)
//
// Unadopted repository is returned
@@ -54,20 +54,20 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
unadoptedRepoName := "unadopted"
unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(db.DefaultContext, userName, []string{repoName, unadoptedRepoName}, unadopted)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, []string{path.Join(userName, unadoptedRepoName)}, unadopted.repositories)
//
// Existing (adopted) repository is not returned
//
unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(db.DefaultContext, userName, []string{repoName}, unadopted)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, unadopted.repositories)
assert.Equal(t, 0, unadopted.index)
}
func TestListUnadoptedRepositories_ListOptions(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
username := "user2"
unadoptedList := []string{path.Join(username, "unadopted1"), path.Join(username, "unadopted2")}
for _, unadopted := range unadoptedList {
@@ -76,23 +76,23 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) {
opts := db.ListOptions{Page: 1, PageSize: 1}
repoNames, count, err := ListUnadoptedRepositories(db.DefaultContext, "", &opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, 2, count)
assert.Equal(t, unadoptedList[0], repoNames[0])
opts = db.ListOptions{Page: 2, PageSize: 1}
repoNames, count, err = ListUnadoptedRepositories(db.DefaultContext, "", &opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, 2, count)
assert.Equal(t, unadoptedList[1], repoNames[0])
}
func TestAdoptRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
username := "user2"
unadopted := "unadopted"
- assert.NoError(t, unittest.CopyDir(
+ require.NoError(t, unittest.CopyDir(
"../../modules/git/tests/repos/repo1_bare",
path.Join(setting.RepoRootPath, username, unadopted+".git"),
))
@@ -110,6 +110,6 @@ func TestAdoptRepository(t *testing.T) {
IsPrivate: false,
AutoInit: true,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, git.Sha1ObjectFormat.Name(), repo.ObjectFormatName)
}
diff --git a/services/repository/archiver/archiver_test.go b/services/repository/archiver/archiver_test.go
index dbd4d9b3c7..9f822a31ce 100644
--- a/services/repository/archiver/archiver_test.go
+++ b/services/repository/archiver/archiver_test.go
@@ -4,7 +4,6 @@
package archiver
import (
- "errors"
"testing"
"time"
@@ -15,6 +14,7 @@ import (
_ "code.gitea.io/gitea/models/actions"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
@@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
}
func TestArchive_Basic(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
ctx, _ := contexttest.MockContext(t, "user27/repo49")
firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4"
@@ -32,47 +32,47 @@ func TestArchive_Basic(t *testing.T) {
defer ctx.Repo.GitRepo.Close()
bogusReq, err := NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, bogusReq)
assert.EqualValues(t, firstCommit+".zip", bogusReq.GetArchiveName())
// Check a series of bogus requests.
// Step 1, valid commit with a bad extension.
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".dilbert")
- assert.Error(t, err)
+ require.Error(t, err)
assert.Nil(t, bogusReq)
// Step 2, missing commit.
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, "dbffff.zip")
- assert.Error(t, err)
+ require.Error(t, err)
assert.Nil(t, bogusReq)
// Step 3, doesn't look like branch/tag/commit.
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, "db.zip")
- assert.Error(t, err)
+ require.Error(t, err)
assert.Nil(t, bogusReq)
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, "master.zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, bogusReq)
assert.EqualValues(t, "master.zip", bogusReq.GetArchiveName())
bogusReq, err = NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, "test/archive.zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, bogusReq)
assert.EqualValues(t, "test-archive.zip", bogusReq.GetArchiveName())
// Now two valid requests, firstCommit with valid extensions.
zipReq, err := NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, zipReq)
tgzReq, err := NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".tar.gz")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, tgzReq)
secondReq, err := NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, secondCommit+".zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, secondReq)
inFlight := make([]*ArchiveRequest, 3)
@@ -92,7 +92,7 @@ func TestArchive_Basic(t *testing.T) {
time.Sleep(2 * time.Second)
zipReq2, err := NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
// This zipReq should match what's sitting in the queue, as we haven't
// let it release yet. From the consumer's point of view, this looks like
// a long-running archive task.
@@ -107,12 +107,12 @@ func TestArchive_Basic(t *testing.T) {
// after we release it. We should trigger both the timeout and non-timeout
// cases.
timedReq, err := NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, secondCommit+".tar.gz")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, timedReq)
ArchiveRepository(db.DefaultContext, timedReq)
zipReq2, err = NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip")
- assert.NoError(t, err)
+ require.NoError(t, err)
// Now, we're guaranteed to have released the original zipReq from the queue.
// Ensure that we don't get handed back the released entry somehow, but they
// should remain functionally equivalent in all fields. The exception here
@@ -120,7 +120,7 @@ func TestArchive_Basic(t *testing.T) {
// It's fine to go ahead and set it to nil now.
assert.Equal(t, zipReq, zipReq2)
- assert.False(t, zipReq == zipReq2)
+ assert.NotSame(t, zipReq, zipReq2)
// Same commit, different compression formats should have different names.
// Ideally, the extension would match what we originally requested.
@@ -130,5 +130,5 @@ func TestArchive_Basic(t *testing.T) {
func TestErrUnknownArchiveFormat(t *testing.T) {
err := ErrUnknownArchiveFormat{RequestFormat: "master"}
- assert.True(t, errors.Is(err, ErrUnknownArchiveFormat{}))
+ assert.ErrorIs(t, err, ErrUnknownArchiveFormat{})
}
diff --git a/services/repository/avatar_test.go b/services/repository/avatar_test.go
index 4a0ba61853..f0fe991de8 100644
--- a/services/repository/avatar_test.go
+++ b/services/repository/avatar_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/avatar"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestUploadAvatar(t *testing.T) {
@@ -23,11 +24,11 @@ func TestUploadAvatar(t *testing.T) {
var buff bytes.Buffer
png.Encode(&buff, myImage)
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
err := UploadAvatar(db.DefaultContext, repo, buff.Bytes())
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, avatar.HashAvatar(10, buff.Bytes()), repo.Avatar)
}
@@ -37,11 +38,11 @@ func TestUploadBigAvatar(t *testing.T) {
var buff bytes.Buffer
png.Encode(&buff, myImage)
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
err := UploadAvatar(db.DefaultContext, repo, buff.Bytes())
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestDeleteAvatar(t *testing.T) {
@@ -50,14 +51,14 @@ func TestDeleteAvatar(t *testing.T) {
var buff bytes.Buffer
png.Encode(&buff, myImage)
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
err := UploadAvatar(db.DefaultContext, repo, buff.Bytes())
- assert.NoError(t, err)
+ require.NoError(t, err)
err = DeleteAvatar(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "", repo.Avatar)
}
diff --git a/services/repository/collaboration_test.go b/services/repository/collaboration_test.go
index c3d006bfd8..c087018be4 100644
--- a/services/repository/collaboration_test.go
+++ b/services/repository/collaboration_test.go
@@ -10,18 +10,18 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepository_DeleteCollaboration(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
- assert.NoError(t, repo.LoadOwner(db.DefaultContext))
- assert.NoError(t, DeleteCollaboration(db.DefaultContext, repo, 4))
+ require.NoError(t, repo.LoadOwner(db.DefaultContext))
+ require.NoError(t, DeleteCollaboration(db.DefaultContext, repo, 4))
unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4})
- assert.NoError(t, DeleteCollaboration(db.DefaultContext, repo, 4))
+ require.NoError(t, DeleteCollaboration(db.DefaultContext, repo, 4))
unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4})
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repo.ID})
diff --git a/services/repository/contributors_graph_test.go b/services/repository/contributors_graph_test.go
index a04587e243..3caffa190c 100644
--- a/services/repository/contributors_graph_test.go
+++ b/services/repository/contributors_graph_test.go
@@ -17,17 +17,18 @@ import (
"gitea.com/go-chi/cache"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepository_ContributorsGraph(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
- assert.NoError(t, repo.LoadOwner(db.DefaultContext))
+ require.NoError(t, repo.LoadOwner(db.DefaultContext))
mockCache, err := cache.NewCacher(cache.Options{
Adapter: "memory",
Interval: 24 * 60,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
lc, cleanup := test.NewLogChecker(log.DEFAULT, log.INFO)
lc.StopMark(`getExtendedCommitStats[repo="user2/repo2" revision="404ref"]: object does not exist [id: 404ref, rel_path: ]`)
@@ -45,7 +46,7 @@ func TestRepository_ContributorsGraph(t *testing.T) {
assert.EqualValues(t, `{"ethantkoenig@gmail.com":{"name":"Ethan Koenig","login":"","avatar_link":"https://secure.gravatar.com/avatar/b42fb195faa8c61b8d88abfefe30e9e3?d=identicon","home_link":"","total_commits":1,"weeks":{"1511654400000":{"week":1511654400000,"additions":3,"deletions":0,"commits":1}}},"jimmy.praet@telenet.be":{"name":"Jimmy Praet","login":"","avatar_link":"https://secure.gravatar.com/avatar/93c49b7c89eb156971d11161c9b52795?d=identicon","home_link":"","total_commits":1,"weeks":{"1624752000000":{"week":1624752000000,"additions":2,"deletions":0,"commits":1}}},"jon@allspice.io":{"name":"Jon","login":"","avatar_link":"https://secure.gravatar.com/avatar/00388ce725e6886f3e07c3733007289b?d=identicon","home_link":"","total_commits":1,"weeks":{"1607817600000":{"week":1607817600000,"additions":10,"deletions":0,"commits":1}}},"total":{"name":"Total","login":"","avatar_link":"","home_link":"","total_commits":3,"weeks":{"1511654400000":{"week":1511654400000,"additions":3,"deletions":0,"commits":1},"1607817600000":{"week":1607817600000,"additions":10,"deletions":0,"commits":1},"1624752000000":{"week":1624752000000,"additions":2,"deletions":0,"commits":1}}}}`, dataString)
var data map[string]*ContributorData
- assert.NoError(t, json.Unmarshal([]byte(dataString), &data))
+ require.NoError(t, json.Unmarshal([]byte(dataString), &data))
var keys []string
for k := range data {
diff --git a/services/repository/create_test.go b/services/repository/create_test.go
index 131249ad9c..9cde285181 100644
--- a/services/repository/create_test.go
+++ b/services/repository/create_test.go
@@ -16,14 +16,15 @@ import (
"code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestIncludesAllRepositoriesTeams(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
testTeamRepositories := func(teamID int64, repoIds []int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, team.LoadRepositories(db.DefaultContext), "%s: GetRepositories", team.Name)
+ require.NoError(t, team.LoadRepositories(db.DefaultContext), "%s: GetRepositories", team.Name)
assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name)
assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name)
for i, rid := range repoIds {
@@ -35,7 +36,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
// Get an admin user.
user, err := user_model.GetUserByID(db.DefaultContext, 1)
- assert.NoError(t, err, "GetUserByID")
+ require.NoError(t, err, "GetUserByID")
// Create org.
org := &organization.Organization{
@@ -44,25 +45,25 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
Type: user_model.UserTypeOrganization,
Visibility: structs.VisibleTypePublic,
}
- assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, user), "CreateOrganization")
+ require.NoError(t, organization.CreateOrganization(db.DefaultContext, org, user), "CreateOrganization")
// Check Owner team.
ownerTeam, err := org.GetOwnerTeam(db.DefaultContext)
- assert.NoError(t, err, "GetOwnerTeam")
+ require.NoError(t, err, "GetOwnerTeam")
assert.True(t, ownerTeam.IncludesAllRepositories, "Owner team includes all repositories")
// Create repos.
repoIDs := make([]int64, 0)
for i := 0; i < 3; i++ {
r, err := CreateRepositoryDirectly(db.DefaultContext, user, org.AsUser(), CreateRepoOptions{Name: fmt.Sprintf("repo-%d", i)})
- assert.NoError(t, err, "CreateRepository %d", i)
+ require.NoError(t, err, "CreateRepository %d", i)
if r != nil {
repoIDs = append(repoIDs, r.ID)
}
}
// Get fresh copy of Owner team after creating repos.
ownerTeam, err = org.GetOwnerTeam(db.DefaultContext)
- assert.NoError(t, err, "GetOwnerTeam")
+ require.NoError(t, err, "GetOwnerTeam")
// Create teams and check repositories.
teams := []*organization.Team{
@@ -101,7 +102,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
}
for i, team := range teams {
if i > 0 { // first team is Owner.
- assert.NoError(t, models.NewTeam(db.DefaultContext, team), "%s: NewTeam", team.Name)
+ require.NoError(t, models.NewTeam(db.DefaultContext, team), "%s: NewTeam", team.Name)
}
testTeamRepositories(team.ID, teamRepos[i])
}
@@ -111,13 +112,13 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
teams[4].IncludesAllRepositories = true
teamRepos[4] = repoIDs
for i, team := range teams {
- assert.NoError(t, models.UpdateTeam(db.DefaultContext, team, false, true), "%s: UpdateTeam", team.Name)
+ require.NoError(t, models.UpdateTeam(db.DefaultContext, team, false, true), "%s: UpdateTeam", team.Name)
testTeamRepositories(team.ID, teamRepos[i])
}
// Create repo and check teams repositories.
r, err := CreateRepositoryDirectly(db.DefaultContext, user, org.AsUser(), CreateRepoOptions{Name: "repo-last"})
- assert.NoError(t, err, "CreateRepository last")
+ require.NoError(t, err, "CreateRepository last")
if r != nil {
repoIDs = append(repoIDs, r.ID)
}
@@ -129,7 +130,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
}
// Remove repo and check teams repositories.
- assert.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, repoIDs[0]), "DeleteRepository")
+ require.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, repoIDs[0]), "DeleteRepository")
teamRepos[0] = repoIDs[1:]
teamRepos[1] = repoIDs[1:]
teamRepos[3] = repoIDs[1:3]
@@ -141,8 +142,8 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
// Wipe created items.
for i, rid := range repoIDs {
if i > 0 { // first repo already deleted.
- assert.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, rid), "DeleteRepository %d", i)
+ require.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, rid), "DeleteRepository %d", i)
}
}
- assert.NoError(t, organization.DeleteOrganization(db.DefaultContext, org), "DeleteOrganization")
+ require.NoError(t, organization.DeleteOrganization(db.DefaultContext, org), "DeleteOrganization")
}
diff --git a/services/repository/files/content_test.go b/services/repository/files/content_test.go
index 4811f9d327..768d6d2f39 100644
--- a/services/repository/files/content_test.go
+++ b/services/repository/files/content_test.go
@@ -14,6 +14,7 @@ import (
_ "code.gitea.io/gitea/models/actions"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
@@ -68,13 +69,13 @@ func TestGetContents(t *testing.T) {
t.Run("Get README.md contents with GetContents(ctx, )", func(t *testing.T) {
fileContentResponse, err := GetContents(ctx, ctx.Repo.Repository, treePath, ref, false)
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Get README.md contents with ref as empty string (should then use the repo's default branch) with GetContents(ctx, )", func(t *testing.T) {
fileContentResponse, err := GetContents(ctx, ctx.Repo.Repository, treePath, "", false)
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
@@ -103,13 +104,13 @@ func TestGetContentsOrListForDir(t *testing.T) {
t.Run("Get root dir contents with GetContentsOrList(ctx, )", func(t *testing.T) {
fileContentResponse, err := GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref)
assert.EqualValues(t, expectedContentsListResponse, fileContentResponse)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Get root dir contents with ref as empty string (should then use the repo's default branch) with GetContentsOrList(ctx, )", func(t *testing.T) {
fileContentResponse, err := GetContentsOrList(ctx, ctx.Repo.Repository, treePath, "")
assert.EqualValues(t, expectedContentsListResponse, fileContentResponse)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
@@ -131,13 +132,13 @@ func TestGetContentsOrListForFile(t *testing.T) {
t.Run("Get README.md contents with GetContentsOrList(ctx, )", func(t *testing.T) {
fileContentResponse, err := GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref)
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
t.Run("Get README.md contents with ref as empty string (should then use the repo's default branch) with GetContentsOrList(ctx, )", func(t *testing.T) {
fileContentResponse, err := GetContentsOrList(ctx, ctx.Repo.Repository, treePath, "")
assert.EqualValues(t, expectedContentsResponse, fileContentResponse)
- assert.NoError(t, err)
+ require.NoError(t, err)
})
}
@@ -158,16 +159,14 @@ func TestGetContentsErrors(t *testing.T) {
t.Run("bad treePath", func(t *testing.T) {
badTreePath := "bad/tree.md"
fileContentResponse, err := GetContents(ctx, repo, badTreePath, ref, false)
- assert.Error(t, err)
- assert.EqualError(t, err, "object does not exist [id: , rel_path: bad]")
+ require.EqualError(t, err, "object does not exist [id: , rel_path: bad]")
assert.Nil(t, fileContentResponse)
})
t.Run("bad ref", func(t *testing.T) {
badRef := "bad_ref"
fileContentResponse, err := GetContents(ctx, repo, treePath, badRef, false)
- assert.Error(t, err)
- assert.EqualError(t, err, "object does not exist [id: "+badRef+", rel_path: ]")
+ require.EqualError(t, err, "object does not exist [id: "+badRef+", rel_path: ]")
assert.Nil(t, fileContentResponse)
})
}
@@ -189,16 +188,14 @@ func TestGetContentsOrListErrors(t *testing.T) {
t.Run("bad treePath", func(t *testing.T) {
badTreePath := "bad/tree.md"
fileContentResponse, err := GetContentsOrList(ctx, repo, badTreePath, ref)
- assert.Error(t, err)
- assert.EqualError(t, err, "object does not exist [id: , rel_path: bad]")
+ require.EqualError(t, err, "object does not exist [id: , rel_path: bad]")
assert.Nil(t, fileContentResponse)
})
t.Run("bad ref", func(t *testing.T) {
badRef := "bad_ref"
fileContentResponse, err := GetContentsOrList(ctx, repo, treePath, badRef)
- assert.Error(t, err)
- assert.EqualError(t, err, "object does not exist [id: "+badRef+", rel_path: ]")
+ require.EqualError(t, err, "object does not exist [id: "+badRef+", rel_path: ]")
assert.Nil(t, fileContentResponse)
})
}
@@ -216,7 +213,7 @@ func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
t.Run("empty repo", func(t *testing.T) {
contents, err := GetContentsOrList(ctx, repo, "", "")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, contents)
})
}
@@ -247,6 +244,6 @@ func TestGetBlobBySHA(t *testing.T) {
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
Size: 180,
}
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, expectedGBR, gbr)
}
diff --git a/services/repository/files/diff_test.go b/services/repository/files/diff_test.go
index 7cec979d72..1ea4a170cc 100644
--- a/services/repository/files/diff_test.go
+++ b/services/repository/files/diff_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/services/gitdiff"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestGetDiffPreview(t *testing.T) {
@@ -118,21 +119,21 @@ func TestGetDiffPreview(t *testing.T) {
t.Run("with given branch", func(t *testing.T) {
diff, err := GetDiffPreview(ctx, ctx.Repo.Repository, branch, treePath, content)
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedBs, err := json.Marshal(expectedDiff)
- assert.NoError(t, err)
+ require.NoError(t, err)
bs, err := json.Marshal(diff)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, string(expectedBs), string(bs))
})
t.Run("empty branch, same results", func(t *testing.T) {
diff, err := GetDiffPreview(ctx, ctx.Repo.Repository, "", treePath, content)
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedBs, err := json.Marshal(expectedDiff)
- assert.NoError(t, err)
+ require.NoError(t, err)
bs, err := json.Marshal(diff)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, expectedBs, bs)
})
}
diff --git a/services/repository/files/file_test.go b/services/repository/files/file_test.go
index a5b3aad91e..2c6a169da1 100644
--- a/services/repository/files/file_test.go
+++ b/services/repository/files/file_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/services/contexttest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestCleanUploadFileName(t *testing.T) {
@@ -115,6 +116,6 @@ func TestGetFileResponseFromCommit(t *testing.T) {
expectedFileResponse := getExpectedFileResponse()
fileResponse, err := GetFileResponseFromCommit(ctx, repo, commit, branch, treePath)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, expectedFileResponse, fileResponse)
}
diff --git a/services/repository/files/temp_repo_test.go b/services/repository/files/temp_repo_test.go
index 2e31996c40..e7d85ea3cc 100644
--- a/services/repository/files/temp_repo_test.go
+++ b/services/repository/files/temp_repo_test.go
@@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRemoveFilesFromIndexSha256(t *testing.T) {
@@ -22,7 +22,7 @@ func TestRemoveFilesFromIndexSha256(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
temp, err := NewTemporaryUploadRepository(db.DefaultContext, repo)
- assert.NoError(t, err)
- assert.NoError(t, temp.Init("sha256"))
- assert.NoError(t, temp.RemoveFilesFromIndex("README.md"))
+ require.NoError(t, err)
+ require.NoError(t, temp.Init("sha256"))
+ require.NoError(t, temp.RemoveFilesFromIndex("README.md"))
}
diff --git a/services/repository/files/tree_test.go b/services/repository/files/tree_test.go
index 508f20090d..faa9b8e29e 100644
--- a/services/repository/files/tree_test.go
+++ b/services/repository/files/tree_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/services/contexttest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestGetTreeBySHA(t *testing.T) {
@@ -29,7 +30,7 @@ func TestGetTreeBySHA(t *testing.T) {
ctx.SetParams(":sha", sha)
tree, err := GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Params(":sha"), page, perPage, true)
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedTree := &api.GitTreeResponse{
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/65f1bf27bc3bf70f64657658635e66094edbcb4d",
diff --git a/services/repository/fork_test.go b/services/repository/fork_test.go
index 452798b25b..4680d99a32 100644
--- a/services/repository/fork_test.go
+++ b/services/repository/fork_test.go
@@ -13,10 +13,11 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestForkRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// user 13 has already forked repo10
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13})
@@ -28,7 +29,7 @@ func TestForkRepository(t *testing.T) {
Description: "test",
})
assert.Nil(t, fork)
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, IsErrForkAlreadyExist(err))
// user not reached maximum limit of repositories
diff --git a/services/repository/lfs_test.go b/services/repository/lfs_test.go
index 52ee05a147..a0c01dff8f 100644
--- a/services/repository/lfs_test.go
+++ b/services/repository/lfs_test.go
@@ -19,6 +19,7 @@ import (
repo_service "code.gitea.io/gitea/services/repository"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestGarbageCollectLFSMetaObjects(t *testing.T) {
@@ -26,13 +27,13 @@ func TestGarbageCollectLFSMetaObjects(t *testing.T) {
setting.LFS.StartServer = true
err := storage.Init()
- assert.NoError(t, err)
+ require.NoError(t, err)
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "lfs")
- assert.NoError(t, err)
+ require.NoError(t, err)
validLFSObjects, err := db.GetEngine(db.DefaultContext).Count(git_model.LFSMetaObject{RepositoryID: repo.ID})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Greater(t, validLFSObjects, int64(1))
// add lfs object
@@ -46,29 +47,29 @@ func TestGarbageCollectLFSMetaObjects(t *testing.T) {
UpdatedLessRecentlyThan: time.Time{}, // ensure that the models/fixtures/lfs_meta_object.yml objects are considered as well
LogDetail: t.Logf,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
// lfs meta has been deleted
_, err = git_model.GetLFSMetaObjectByOid(db.DefaultContext, repo.ID, lfsOid)
- assert.ErrorIs(t, err, git_model.ErrLFSObjectNotExist)
+ require.ErrorIs(t, err, git_model.ErrLFSObjectNotExist)
remainingLFSObjects, err := db.GetEngine(db.DefaultContext).Count(git_model.LFSMetaObject{RepositoryID: repo.ID})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, validLFSObjects-1, remainingLFSObjects)
}
func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string {
pointer, err := lfs.GeneratePointer(bytes.NewReader(*content))
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = git_model.NewLFSMetaObject(db.DefaultContext, repositoryID, pointer)
- assert.NoError(t, err)
+ require.NoError(t, err)
contentStore := lfs.NewContentStore()
exist, err := contentStore.Exists(pointer)
- assert.NoError(t, err)
+ require.NoError(t, err)
if !exist {
err := contentStore.Put(pointer, bytes.NewReader(*content))
- assert.NoError(t, err)
+ require.NoError(t, err)
}
return pointer.Oid
}
diff --git a/services/repository/repository_test.go b/services/repository/repository_test.go
index 892a11a23e..a5c0b3efcd 100644
--- a/services/repository/repository_test.go
+++ b/services/repository/repository_test.go
@@ -12,10 +12,11 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestLinkedRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
testCases := []struct {
name string
attachID int64
@@ -30,9 +31,9 @@ func TestLinkedRepository(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
attach, err := repo_model.GetAttachmentByID(db.DefaultContext, tc.attachID)
- assert.NoError(t, err)
+ require.NoError(t, err)
repo, unitType, err := LinkedRepository(db.DefaultContext, attach)
- assert.NoError(t, err)
+ require.NoError(t, err)
if tc.expectedRepo != nil {
assert.Equal(t, tc.expectedRepo.ID, repo.ID)
}
diff --git a/services/repository/review_test.go b/services/repository/review_test.go
index 2db56d4e8a..eb1712c2ce 100644
--- a/services/repository/review_test.go
+++ b/services/repository/review_test.go
@@ -11,18 +11,19 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoGetReviewerTeams(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
teams, err := GetReviewerTeams(db.DefaultContext, repo2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, teams)
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
teams, err = GetReviewerTeams(db.DefaultContext, repo3)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, teams, 2)
}
diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go
index b201b5cb98..cc51a05781 100644
--- a/services/repository/transfer_test.go
+++ b/services/repository/transfer_test.go
@@ -20,6 +20,7 @@ import (
notify_service "code.gitea.io/gitea/services/notify"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
var notifySync sync.Once
@@ -33,21 +34,21 @@ func registerNotifier() {
func TestTransferOwnership(t *testing.T) {
registerNotifier()
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
- assert.NoError(t, TransferOwnership(db.DefaultContext, doer, doer, repo, nil))
+ require.NoError(t, TransferOwnership(db.DefaultContext, doer, doer, repo, nil))
transferredRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
assert.EqualValues(t, 2, transferredRepo.OwnerID)
exist, err := util.IsExist(repo_model.RepoPath("org3", "repo3"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, exist)
exist, err = util.IsExist(repo_model.RepoPath("user2", "repo3"))
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, exist)
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
OpType: activities_model.ActionTransferRepo,
@@ -60,7 +61,7 @@ func TestTransferOwnership(t *testing.T) {
}
func TestStartRepositoryTransferSetPermission(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
@@ -68,56 +69,56 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) {
repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
hasAccess, err := access_model.HasAccess(db.DefaultContext, recipient.ID, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, hasAccess)
- assert.NoError(t, StartRepositoryTransfer(db.DefaultContext, doer, recipient, repo, nil))
+ require.NoError(t, StartRepositoryTransfer(db.DefaultContext, doer, recipient, repo, nil))
hasAccess, err = access_model.HasAccess(db.DefaultContext, recipient.ID, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, hasAccess)
unittest.CheckConsistencyFor(t, &repo_model.Repository{}, &user_model.User{}, &organization.Team{})
}
func TestRepositoryTransfer(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
transfer, err := models.GetPendingRepositoryTransfer(db.DefaultContext, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, transfer)
// Cancel transfer
- assert.NoError(t, CancelRepositoryTransfer(db.DefaultContext, repo))
+ require.NoError(t, CancelRepositoryTransfer(db.DefaultContext, repo))
transfer, err = models.GetPendingRepositoryTransfer(db.DefaultContext, repo)
- assert.Error(t, err)
+ require.Error(t, err)
assert.Nil(t, transfer)
assert.True(t, models.IsErrNoPendingTransfer(err))
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
- assert.NoError(t, models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, user2, repo.ID, nil))
+ require.NoError(t, models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, user2, repo.ID, nil))
transfer, err = models.GetPendingRepositoryTransfer(db.DefaultContext, repo)
- assert.Nil(t, err)
- assert.NoError(t, transfer.LoadAttributes(db.DefaultContext))
+ require.NoError(t, err)
+ require.NoError(t, transfer.LoadAttributes(db.DefaultContext))
assert.Equal(t, "user2", transfer.Recipient.Name)
org6 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
// Only transfer can be started at any given time
err = models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, org6, repo.ID, nil)
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, models.IsErrRepoTransferInProgress(err))
// Unknown user
err = models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, &user_model.User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
- assert.Error(t, err)
+ require.Error(t, err)
// Cancel transfer
- assert.NoError(t, CancelRepositoryTransfer(db.DefaultContext, repo))
+ require.NoError(t, CancelRepositoryTransfer(db.DefaultContext, repo))
}