diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-05-14 16:21:23 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-05-17 09:42:52 +0300 |
commit | d4356c84bd457624c8b998b5a02d9be4a1431061 (patch) | |
tree | 89f641708f2fcd4ae0f65deb02309f8886336535 | |
parent | abaef510285b7295859ae703f6ff203b2d141d0f (diff) |
Use github.com/stretchr/testify package to check dir and file existence
The change simplifies check of file or directory existence
by replacing calling for the file stats and checking returned
error with a single verification function.
-rw-r--r-- | internal/cache/walker_test.go | 3 | ||||
-rw-r--r-- | internal/git/objectpool/link_test.go | 4 | ||||
-rw-r--r-- | internal/git/objectpool/pool_test.go | 3 | ||||
-rw-r--r-- | internal/gitaly/service/objectpool/create_test.go | 4 | ||||
-rw-r--r-- | internal/gitaly/service/repository/commit_graph_test.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/repository/gc_test.go | 9 | ||||
-rw-r--r-- | internal/praefect/replicator_test.go | 3 |
7 files changed, 10 insertions, 22 deletions
diff --git a/internal/cache/walker_test.go b/internal/cache/walker_test.go index 8cbeed449..5ff0a9b9c 100644 --- a/internal/cache/walker_test.go +++ b/internal/cache/walker_test.go @@ -63,8 +63,7 @@ func TestDiskCacheObjectWalker(t *testing.T) { } for _, p := range shouldNotExist { - _, err := os.Stat(p) - require.True(t, os.IsNotExist(err), "expected %s not to exist", p) + require.NoFileExists(t, p) } } diff --git a/internal/git/objectpool/link_test.go b/internal/git/objectpool/link_test.go index c1c2ab29c..0413e41e1 100644 --- a/internal/git/objectpool/link_test.go +++ b/internal/git/objectpool/link_test.go @@ -2,7 +2,6 @@ package objectpool import ( "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -23,8 +22,7 @@ func TestLink(t *testing.T) { altPath, err := pool.locator.InfoAlternatesPath(testRepo) require.NoError(t, err) - _, err = os.Stat(altPath) - require.True(t, os.IsNotExist(err)) + require.NoFileExists(t, altPath) require.NoError(t, pool.Link(ctx, testRepo)) diff --git a/internal/git/objectpool/pool_test.go b/internal/git/objectpool/pool_test.go index f62fb255d..4dc51a9b6 100644 --- a/internal/git/objectpool/pool_test.go +++ b/internal/git/objectpool/pool_test.go @@ -109,8 +109,7 @@ func TestCreate(t *testing.T) { require.True(t, pool.IsValid()) // No hooks - _, err = os.Stat(filepath.Join(pool.FullPath(), "hooks")) - assert.True(t, os.IsNotExist(err)) + assert.NoDirExists(t, filepath.Join(pool.FullPath(), "hooks")) // origin is set out := gittest.Exec(t, pool.cfg, "-C", pool.FullPath(), "remote", "get-url", "origin") diff --git a/internal/gitaly/service/objectpool/create_test.go b/internal/gitaly/service/objectpool/create_test.go index 82674ac4f..d45143589 100644 --- a/internal/gitaly/service/objectpool/create_test.go +++ b/internal/gitaly/service/objectpool/create_test.go @@ -1,7 +1,6 @@ package objectpool import ( - "os" "path/filepath" "strings" "testing" @@ -41,8 +40,7 @@ func TestCreate(t *testing.T) { require.True(t, pool.IsValid()) // No hooks - _, err = os.Stat(filepath.Join(pool.FullPath(), "hooks")) - assert.True(t, os.IsNotExist(err)) + assert.NoDirExists(t, filepath.Join(pool.FullPath(), "hooks")) // No problems out := gittest.Exec(t, cfg, "-C", pool.FullPath(), "cat-file", "-s", "55bc176024cfa3baaceb71db584c7e5df900ea65") diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go index 287065c7b..a48d146a7 100644 --- a/internal/gitaly/service/repository/commit_graph_test.go +++ b/internal/gitaly/service/repository/commit_graph_test.go @@ -20,8 +20,7 @@ func TestWriteCommitGraph(t *testing.T) { commitGraphPath := filepath.Join(repoPath, CommitGraphRelPath) - _, err := os.Stat(commitGraphPath) - assert.True(t, os.IsNotExist(err)) + assert.NoFileExists(t, commitGraphPath) gittest.WriteCommit( t, @@ -47,8 +46,7 @@ func TestUpdateCommitGraph(t *testing.T) { commitGraphPath := filepath.Join(repoPath, CommitGraphRelPath) - _, err := os.Stat(commitGraphPath) - assert.True(t, os.IsNotExist(err)) + assert.NoFileExists(t, commitGraphPath) res, err := client.WriteCommitGraph(ctx, &gitalypb.WriteCommitGraphRequest{Repository: repo}) assert.NoError(t, err) diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go index 7151c0fb4..bd9bc6013 100644 --- a/internal/gitaly/service/repository/gc_test.go +++ b/internal/gitaly/service/repository/gc_test.go @@ -141,8 +141,7 @@ func TestGarbageCollectWithPrune(t *testing.T) { require.NoError(t, err) require.NotNil(t, c) - _, err = os.Stat(oldDanglingObjFile) - require.True(t, os.IsNotExist(err), "blob should be removed from object storage as it is too old and there are no references to it") + require.NoFileExists(t, oldDanglingObjFile, "blob should be removed from object storage as it is too old and there are no references to it") require.FileExists(t, newDanglingObjFile, "blob should not be removed from object storage as it is fresh enough despite there are no references to it") require.FileExists(t, oldReferencedObjFile, "blob should not be removed from object storage as it is referenced by something despite it is too old") } @@ -296,16 +295,14 @@ func TestCleanupInvalidKeepAroundRefs(t *testing.T) { require.Equal(t, existingSha, text.ChompBytes(commitSha)) //The invalid one was removed - _, err = os.Stat(bogusPath) - require.True(t, os.IsNotExist(err), "expected 'does not exist' error, got %v", err) + require.NoFileExists(t, bogusPath) if testcase.shouldExist { keepAroundName := fmt.Sprintf("refs/keep-around/%s", testcase.refName) commitSha := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", keepAroundName) require.Equal(t, testcase.refName, text.ChompBytes(commitSha)) } else { - _, err := os.Stat(refPath) - require.True(t, os.IsNotExist(err), "expected 'does not exist' error, got %v", err) + require.NoFileExists(t, refPath) } }) } diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index 8e96476b1..293d7d400 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -797,8 +797,7 @@ func TestProcessBacklog_Success(t *testing.T) { t.Fatal("time limit expired for job to complete") } - _, serr := os.Stat(fullNewPath1) - require.True(t, os.IsNotExist(serr), "repository must be moved from %q to the new location", fullNewPath1) + require.NoDirExists(t, fullNewPath1, "repository must be moved from %q to the new location", fullNewPath1) require.True(t, storage.IsGitDirectory(fullNewPath2), "repository must exist at new last RenameRepository location") } |