package memory import ( "testing" "time" "caj-larsson/bog/dataswamp/namespace" ) func TestUserAgentRepo(t *testing.T) { r := NewRepository() all, err := r.All() if len(all) != 0 && err != nil { t.Errorf("New repo should be empty") } ns := namespace.Namespace {23, "n1", time.Now(), time.Duration(time.Hour * 3), namespace.FileSizeQuota {1000, 0} } ns1, _ := r.Create(ns) ns.Name = "n2" ns2, _ := r.Create(ns) if ns1 == ns2 { 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 ns.ID != 23 { t.Errorf("It does not change the original UserAgent") } ns3, _ := r.GetByName("n2") if ns3 != ns2 { t.Errorf("It the correct ns is acquired") } if r.Delete(ns2.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 NS ") } }