Browse Source

Added missing error checks in tests (#7554)

Whenever we assign a value to err, check for it being nil.
tags/v1.11.0-dev
Christian Muehlhaeuser zeripath 6 years ago
parent
commit
b651c9775a
4 changed files with 8 additions and 1 deletions
  1. +2
    -0
      models/release_test.go
  2. +1
    -0
      models/repo_test.go
  3. +4
    -1
      modules/git/repo_commit_test.go
  4. +1
    -0
      modules/git/repo_stats_test.go

+ 2
- 0
models/release_test.go View File

@@ -139,6 +139,7 @@ func TestRelease_MirrorDelete(t *testing.T) {
assert.True(t, ok) assert.True(t, ok)


count, err := GetReleaseCountByRepoID(mirror.ID, findOptions) count, err := GetReleaseCountByRepoID(mirror.ID, findOptions)
assert.NoError(t, err)
assert.EqualValues(t, initCount+1, count) assert.EqualValues(t, initCount+1, count)


release, err := GetRelease(repo.ID, "v0.2") release, err := GetRelease(repo.ID, "v0.2")
@@ -149,5 +150,6 @@ func TestRelease_MirrorDelete(t *testing.T) {
assert.True(t, ok) assert.True(t, ok)


count, err = GetReleaseCountByRepoID(mirror.ID, findOptions) count, err = GetReleaseCountByRepoID(mirror.ID, findOptions)
assert.NoError(t, err)
assert.EqualValues(t, initCount, count) assert.EqualValues(t, initCount, count)
} }

+ 1
- 0
models/repo_test.go View File

@@ -88,6 +88,7 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) {


// Get sample repo and change visibility // Get sample repo and change visibility
repo, err := GetRepositoryByID(9) repo, err := GetRepositoryByID(9)
assert.NoError(t, err)
repo.IsPrivate = true repo.IsPrivate = true


// Update it // Update it


+ 4
- 1
modules/git/repo_commit_test.go View File

@@ -40,8 +40,9 @@ func TestRepository_GetCommitBranches(t *testing.T) {
func TestGetTagCommitWithSignature(t *testing.T) { func TestGetTagCommitWithSignature(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path) bareRepo1, err := OpenRepository(bareRepo1Path)
commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
assert.NoError(t, err)


commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, commit) assert.NotNil(t, commit)
assert.NotNil(t, commit.Signature) assert.NotNil(t, commit.Signature)
@@ -52,6 +53,8 @@ func TestGetTagCommitWithSignature(t *testing.T) {
func TestGetCommitWithBadCommitID(t *testing.T) { func TestGetCommitWithBadCommitID(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path) bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)

commit, err := bareRepo1.GetCommit("bad_branch") commit, err := bareRepo1.GetCommit("bad_branch")
assert.Nil(t, commit) assert.Nil(t, commit)
assert.Error(t, err) assert.Error(t, err)


+ 1
- 0
modules/git/repo_stats_test.go View File

@@ -18,6 +18,7 @@ func TestRepository_GetCodeActivityStats(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)


timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00") timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00")
assert.NoError(t, err)


code, err := bareRepo1.GetCodeActivityStats(timeFrom, "") code, err := bareRepo1.GetCodeActivityStats(timeFrom, "")
assert.NoError(t, err) assert.NoError(t, err)


Loading…
Cancel
Save