aboutsummaryrefslogtreecommitdiffstats
path: root/repository/repo_testing.go
diff options
context:
space:
mode:
authorKalin Staykov <k.t.staykov@gmail.com>2022-11-26 15:49:59 +0200
committerMichael Muré <batolettre@gmail.com>2023-01-11 14:58:58 +0100
commitfc266b733cf0ea794209031e3500ab3f86db6cee (patch)
treebae1996ec19fb74446429200e52cdb942f60ac54 /repository/repo_testing.go
parent9c50a359704f4edd2f33df6d256e032feae3a576 (diff)
downloadgit-bug-fc266b733cf0ea794209031e3500ab3f86db6cee.tar.gz
add wipe sub-command that remove local bugs and identities
Diffstat (limited to 'repository/repo_testing.go')
-rw-r--r--repository/repo_testing.go34
1 files changed, 32 insertions, 2 deletions
diff --git a/repository/repo_testing.go b/repository/repo_testing.go
index 821eb762..09332e62 100644
--- a/repository/repo_testing.go
+++ b/repository/repo_testing.go
@@ -2,6 +2,7 @@ package repository
import (
"math/rand"
+ "os"
"testing"
"github.com/ProtonMail/go-crypto/openpgp"
@@ -10,8 +11,6 @@ import (
"github.com/MichaelMure/git-bug/util/lamport"
)
-// TODO: add tests for RepoStorage
-
type RepoCreator func(t testing.TB, bare bool) TestedRepo
// Test suite for a Repo implementation
@@ -32,6 +31,10 @@ func RepoTest(t *testing.T, creator RepoCreator) {
RepoConfigTest(t, repo)
})
+ t.Run("Storage", func(t *testing.T) {
+ RepoStorageTest(t, repo)
+ })
+
t.Run("Index", func(t *testing.T) {
RepoIndexTest(t, repo)
})
@@ -48,6 +51,33 @@ func RepoConfigTest(t *testing.T, repo RepoConfig) {
testConfig(t, repo.LocalConfig())
}
+func RepoStorageTest(t *testing.T, repo RepoStorage) {
+ storage := repo.LocalStorage()
+
+ err := storage.MkdirAll("foo/bar", 0755)
+ require.NoError(t, err)
+
+ f, err := storage.Create("foo/bar/foofoo")
+ require.NoError(t, err)
+
+ _, err = f.Write([]byte("hello"))
+ require.NoError(t, err)
+
+ // remove all
+ err = storage.RemoveAll(".")
+ require.NoError(t, err)
+
+ fi, err := storage.ReadDir(".")
+ // a real FS would remove the root directory with RemoveAll and subsequent call would fail
+ // a memory FS would still have a virtual root and subsequent call would succeed
+ // not ideal, but will do for now
+ if err == nil {
+ require.Empty(t, fi)
+ } else {
+ require.True(t, os.IsNotExist(err))
+ }
+}
+
func randomHash() Hash {
var letterRunes = "abcdef0123456789"
b := make([]byte, idLengthSHA256)