You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.2 KiB
Go
76 lines
1.2 KiB
Go
package swampfile
|
|
|
|
import (
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
"path"
|
|
"os"
|
|
"testing"
|
|
"github.com/matryer/is"
|
|
)
|
|
|
|
func newRepoDir(t *testing.T) string {
|
|
r := t.TempDir()
|
|
d := path.Join(r, "fs")
|
|
|
|
err := os.Mkdir(d, 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return d
|
|
}
|
|
|
|
|
|
func TestFsFileRepo(t *testing.T) {
|
|
|
|
var fac = func() swampfile.Repository {
|
|
repo, err := NewRepository(newRepoDir(t))
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return repo
|
|
}
|
|
|
|
swampfile.RepositoryContract(fac, t)
|
|
}
|
|
|
|
|
|
func TestEmptyDir(t *testing.T) {
|
|
is := is.New(t)
|
|
dir_path := newRepoDir(t)
|
|
_, err := NewRepository(dir_path)
|
|
|
|
is.NoErr(err)
|
|
|
|
_, err = os.OpenFile(path.Join(dir_path, ".bogrepo"), os.O_RDONLY, 0)
|
|
is.NoErr(err)
|
|
}
|
|
|
|
|
|
func TestDirtyDir(t *testing.T) {
|
|
is := is.New(t)
|
|
dir_path := newRepoDir(t)
|
|
|
|
_, err := os.OpenFile(path.Join(dir_path, "randomfile"), os.O_CREATE, 0644)
|
|
is.NoErr(err)
|
|
|
|
_, err = NewRepository(dir_path)
|
|
|
|
is.Equal(err, ErrDirtyRepo)
|
|
}
|
|
|
|
|
|
func TestDirtyWithFlag(t *testing.T) {
|
|
is := is.New(t)
|
|
dir_path := newRepoDir(t)
|
|
|
|
_, err := os.OpenFile(path.Join(dir_path, "randomfile"), os.O_CREATE, 0644)
|
|
is.NoErr(err)
|
|
|
|
_, err = os.OpenFile(path.Join(dir_path, ".bogrepo"), os.O_CREATE, 0644)
|
|
is.NoErr(err)
|
|
|
|
_, err = NewRepository(dir_path)
|
|
is.NoErr(err)
|
|
}
|