Use is. tests and fmt
parent
8a0e6b80e3
commit
e6e2f372dd
@ -1,57 +1,37 @@
|
|||||||
package namespace
|
package namespace
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/matryer/is"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestQuota(t *testing.T) {
|
func TestQuota(t *testing.T) {
|
||||||
|
is := is.New(t)
|
||||||
quota := FileSizeQuota{1000, 0}
|
quota := FileSizeQuota{1000, 0}
|
||||||
|
|
||||||
if !quota.Allows(1000) {
|
is.True(quota.Allows(1000))
|
||||||
t.Errorf("It should allow filling completely")
|
is.True(!quota.Allows(1001))
|
||||||
}
|
|
||||||
if quota.Allows(1001) {
|
|
||||||
t.Errorf("It should not allow filling completely")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuotaManipulation(t *testing.T) {
|
func TestQuotaManipulation(t *testing.T) {
|
||||||
|
is := is.New(t)
|
||||||
quota := FileSizeQuota{1000, 0}
|
quota := FileSizeQuota{1000, 0}
|
||||||
|
|
||||||
if quota.Add(500) != nil {
|
is.NoErr(quota.Add(500))
|
||||||
t.Errorf("It should allow adding")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.CurrentUsage != 500 {
|
is.Equal(quota.CurrentUsage, int64(500))
|
||||||
t.Errorf("It should add the usage correctly")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.Add(500) != nil {
|
is.NoErr(quota.Add(500))
|
||||||
t.Errorf("It should allow adding up to the limit")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.Add(1) != ErrExceedQuota {
|
is.Equal(quota.Add(1), ErrExceedQuota)
|
||||||
t.Errorf("It should not allow adding beyond limit")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.CurrentUsage != 1000 {
|
is.Equal(quota.CurrentUsage, int64(1000))
|
||||||
t.Errorf("It should not overtaxed after failure to add")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.Remove(1001) != ErrQuotaInvalid {
|
is.Equal(quota.Remove(1001), ErrQuotaInvalid)
|
||||||
t.Errorf("It should not allow reducing further than 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.CurrentUsage != 1000 {
|
is.Equal(quota.CurrentUsage, int64(1000))
|
||||||
t.Errorf("It should not overtaxed after failure to remove")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.Remove(1000) != nil {
|
is.NoErr(quota.Remove(1000))
|
||||||
t.Errorf("It should allow reducing to 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
if quota.CurrentUsage != 0 {
|
is.Equal(quota.CurrentUsage, int64(0))
|
||||||
t.Errorf("It should reduce accurately")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,52 +1,43 @@
|
|||||||
package memory
|
package namespace
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"caj-larsson/bog/dataswamp/namespace"
|
||||||
|
"github.com/matryer/is"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"caj-larsson/bog/dataswamp/namespace"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserAgentRepo(t *testing.T) {
|
func TestUserAgentRepo(t *testing.T) {
|
||||||
|
is := is.New(t)
|
||||||
r := NewRepository()
|
r := NewRepository()
|
||||||
|
|
||||||
all, err := r.All()
|
all, err := r.All()
|
||||||
|
|
||||||
if len(all) != 0 && err != nil {
|
is.NoErr(err)
|
||||||
t.Errorf("New repo should be empty")
|
is.Equal(len(all), 0)
|
||||||
}
|
|
||||||
|
|
||||||
ns := namespace.Namespace{23, "n1", time.Now(), time.Duration(time.Hour * 3), namespace.FileSizeQuota{1000, 0}}
|
ns := namespace.Namespace{23, "n1", time.Now(), time.Duration(time.Hour * 3), namespace.FileSizeQuota{1000, 0}}
|
||||||
|
|
||||||
|
|
||||||
ns1, _ := r.Create(ns)
|
ns1, _ := r.Create(ns)
|
||||||
ns.Name = "n2"
|
ns.Name = "n2"
|
||||||
ns2, _ := r.Create(ns)
|
ns2, _ := r.Create(ns)
|
||||||
if ns1 == ns2 {
|
is.True(ns1 != ns2)
|
||||||
t.Errorf("Must create unique items")
|
|
||||||
}
|
|
||||||
|
|
||||||
all, err = r.All()
|
all, err = r.All()
|
||||||
|
|
||||||
if len(all) != 2 && err != nil {
|
is.NoErr(err)
|
||||||
t.Errorf("After adding there should be two Useragent")
|
is.Equal(len(all), 2)
|
||||||
}
|
|
||||||
|
|
||||||
if ns.ID != 23 {
|
is.Equal(ns.ID, int64(23))
|
||||||
t.Errorf("It does not change the original UserAgent")
|
|
||||||
}
|
|
||||||
|
|
||||||
ns3, _ := r.GetByName("n2")
|
ns3, _ := r.GetByName("n2")
|
||||||
|
|
||||||
if ns3 != ns2 {
|
is.Equal(ns3, ns2)
|
||||||
t.Errorf("It the correct ns is acquired")
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Delete(ns2.ID) != nil {
|
is.NoErr(r.Delete(ns2.ID))
|
||||||
t.Errorf("Must delete without error")
|
|
||||||
}
|
|
||||||
|
|
||||||
all, err = r.All()
|
all, err = r.All()
|
||||||
if len(all) != 1 && err != nil {
|
|
||||||
t.Errorf("After deleting one there should be one NS ")
|
is.NoErr(err)
|
||||||
}
|
is.Equal(len(all), 1)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package swampfile
|
package swampfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"caj-larsson/bog/dataswamp/swampfile"
|
"caj-larsson/bog/dataswamp/swampfile"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestFileRepo(t *testing.T) {
|
func TestFileRepo(t *testing.T) {
|
||||||
swampfile.RepositoryContract(NewRepository, t)
|
swampfile.RepositoryContract(NewRepository, t)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue