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.
bog/test/mock/user_agent_test.go

53 lines
968 B
Go

package mock
import (
"testing"
"time"
"caj-larsson/bog/domain"
)
func TestMockUserAgentRepo(t *testing.T) {
r := NewMockUserAgentRepository()
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 ")
}
}