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.
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
"caj-larsson/bog/domain"
|
|
)
|
|
|
|
func TestMockUserAgentRepo(t *testing.T) {
|
|
r := new(MockUserAgentRepository)
|
|
r.NextId = 0
|
|
r.IdIdx = make(map[int64]*domain.UserAgent)
|
|
r.NameIdx = make(map[string]*domain.UserAgent)
|
|
|
|
all, err := r.All()
|
|
|
|
if len(all) != 0 && err != nil {
|
|
t.Errorf("New repo should be empty")
|
|
}
|
|
|
|
ua := domain.UserAgent {23, "n1", time.Now(), time.Duration(time.Hour * 3), domain.FileSizeQuota {1000, 0} }
|
|
|
|
|
|
ua1, _ := r.Create(ua)
|
|
ua.Name = "n2"
|
|
ua2, _ := r.Create(ua)
|
|
if ua1 == ua2 {
|
|
t.Errorf("Must create unique items")
|
|
}
|
|
|
|
all, err = r.All()
|
|
|
|
if len(all) != 2 && err != nil {
|
|
t.Errorf("After adding there should be two Useragent")
|
|
}
|
|
|
|
if ua.ID != 23 {
|
|
t.Errorf("It does not change the original UserAgent")
|
|
}
|
|
|
|
ua3, _ := r.GetByName("n2")
|
|
|
|
if ua3 != ua2 {
|
|
t.Errorf("It the correct ua is acquired")
|
|
}
|
|
|
|
if r.Delete(ua2.ID) != nil {
|
|
t.Errorf("Must delete without error")
|
|
}
|
|
|
|
all, err = r.All()
|
|
if len(all) != 1 && err != nil {
|
|
t.Errorf("After deleting one there should be one UA ")
|
|
}
|
|
}
|