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.
|
|
|
package namespace
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/matryer/is"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RepositoryContract(fac func() Repository, t *testing.T) {
|
|
|
|
basicNamespaceContract(fac, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func basicNamespaceContract(fac func() Repository, t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
r := fac()
|
|
|
|
|
|
|
|
all, err := r.All()
|
|
|
|
|
|
|
|
is.NoErr(err)
|
|
|
|
is.Equal(len(all), 0)
|
|
|
|
|
|
|
|
ns := Namespace{
|
|
|
|
23,
|
|
|
|
"n1",
|
|
|
|
time.Now(),
|
|
|
|
time.Duration(time.Hour * 3),
|
|
|
|
FileSizeQuota{1000, 0},
|
|
|
|
FileStat{1, 2},
|
|
|
|
FileStat{3, 4},
|
|
|
|
}
|
|
|
|
|
|
|
|
ns1, err := r.Create(ns)
|
|
|
|
is.NoErr(err)
|
|
|
|
ns.Name = "n2"
|
|
|
|
ns2, err := r.Create(ns)
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
is.True(ns1.ID != ns2.ID)
|
|
|
|
|
|
|
|
all, err = r.All()
|
|
|
|
|
|
|
|
is.NoErr(err)
|
|
|
|
is.Equal(len(all), 2)
|
|
|
|
|
|
|
|
is.Equal(ns.ID, int64(23))
|
|
|
|
|
|
|
|
ns3, _ := r.GetByName("n2")
|
|
|
|
|
|
|
|
is.Equal(*ns3, *ns2)
|
|
|
|
|
|
|
|
is.NoErr(r.Delete(ns2.ID))
|
|
|
|
|
|
|
|
all, err = r.All()
|
|
|
|
|
|
|
|
is.NoErr(err)
|
|
|
|
is.Equal(len(all), 1)
|
|
|
|
}
|