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.
54 lines
779 B
Go
54 lines
779 B
Go
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},
|
|
Usage{1, 2, 3, 4, 5},
|
|
}
|
|
|
|
ns1, _ := r.Create(ns)
|
|
ns.Name = "n2"
|
|
ns2, _ := r.Create(ns)
|
|
is.True(ns1 != ns2)
|
|
|
|
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)
|
|
}
|