Core functionality for new aiterp.net servers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

package auth
import "testing"
func TestSession(t *testing.T) {
auther := testAuther{FullName: "Test"}
user := NewUser(&auther, "Tester", "Tester", "member", nil)
sessions := []*Session{OpenSession(user), OpenSession(user), OpenSession(user)}
ids := []string{sessions[0].ID, sessions[1].ID, sessions[2].ID}
t.Run("Find", func(t *testing.T) {
for i, id := range ids {
found := FindSession(id)
if found != sessions[i] {
t.Errorf("Find(\"%s\") == %+v", id, found)
t.Fail()
}
}
})
t.Run("Close", func(t *testing.T) {
CloseSession(ids[2])
if FindSession(ids[0]) == nil || FindSession(ids[1]) == nil || FindSession(ids[2]) != nil {
t.Errorf("Find(\"%s\") == %+v", ids[0], FindSession(ids[0]))
t.Errorf("Find(\"%s\") == %+v", ids[1], FindSession(ids[1]))
t.Errorf("Find(\"%s\") == %+v", ids[2], FindSession(ids[2]))
t.Fail()
}
})
t.Run("Clear", func(t *testing.T) {
ClearSessions(user)
if FindSession(ids[0]) != nil || FindSession(ids[1]) != nil || FindSession(ids[2]) != nil {
t.Errorf("Find(\"%s\") == %+v", ids[0], FindSession(ids[0]))
t.Errorf("Find(\"%s\") == %+v", ids[1], FindSession(ids[1]))
t.Errorf("Find(\"%s\") == %+v", ids[2], FindSession(ids[2]))
t.Fail()
}
})
}