diff --git a/person/person._test.go b/person/person._test.go new file mode 100644 index 0000000..32c596f --- /dev/null +++ b/person/person._test.go @@ -0,0 +1,59 @@ +package person + +import ( + "testing" +) + +func TestPerson(t *testing.T) { + person := NewPersonWithCustomID("test") + + person.AddPermission("test") + if !person.HasPermission("test") { + t.Error("person should have permission") + } + + person.RemovePermission("test") + if person.HasPermission("test") { + t.Error("person should not have permission") + } + + person.AddFriend("test") + if len(person.Friends) != 1 { + t.Error("person should have 1 friend") + } + + person.RemoveFriend("test") + if len(person.Friends) != 0 { + t.Error("person should have no friends") + } + + if person.ID != "test" { + t.Error("person should have id of test") + } + + profilesToTest := []string{ "common_core", "athena", "common_public", "profile0", "collections", "creative" } + for _, profile := range profilesToTest { + if person.GetProfileFromType(profile) == nil { + t.Error("person should have profile") + } + + if person.GetProfileFromType(profile).Type != profile { + t.Error("person should have profile with id of " + profile) + } + + if person.GetProfileFromType(profile).PersonID != person.ID { + t.Error("person should have profile with person id of " + person.ID) + } + } + + item := NewItem("Test:Test", 1) + + person.AthenaProfile.Items.AddItem(item) + if person.AthenaProfile.Items.GetItemByTemplateID("Test:Test") == nil { + t.Error("person should have item") + } + + if person.AthenaProfile.Items.GetItem(item.ID) == nil { + t.Error("person should have item") + } +} \ No newline at end of file diff --git a/storage/memory.go b/storage/memory.go deleted file mode 100644 index 7a4f7f0..0000000 --- a/storage/memory.go +++ /dev/null @@ -1,46 +0,0 @@ -package storage - -import ( - "sync" -) - -type personsMutex struct { - sync.Map -} - -func newPersonsMutex() *personsMutex { - return &personsMutex{} -} - -func (m *personsMutex) GetPerson(id string) *DB_Person { - p, ok := m.Load(id) - if !ok { - return nil - } - - return p.(*DB_Person) -} - -func (m *personsMutex) SavePerson(person *DB_Person) { - m.Store(person.ID, person) -} - -type MemoryStorage struct { - Persons *personsMutex -} - -func NewMemoryStorage() *MemoryStorage { - return &MemoryStorage{ - Persons: newPersonsMutex(), - } -} - -func (s *MemoryStorage) Migrate(table interface{}, tableName string) {} // not needed for memory storage as there is no db - -func (s *MemoryStorage) GetPerson(id string) *DB_Person { - return s.Persons.GetPerson(id) -} - -func (s *MemoryStorage) SavePerson(person *DB_Person) { - s.Persons.SavePerson(person) -} \ No newline at end of file