add basic testing
This commit is contained in:
parent
933ac5be66
commit
f2b4d353fe
59
person/person._test.go
Normal file
59
person/person._test.go
Normal file
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user