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

7 years ago
  1. package auth
  2. import "testing"
  3. func TestSession(t *testing.T) {
  4. auther := testAuther{FullName: "Test"}
  5. user := NewUser(&auther, "Tester", "Tester", "member", nil)
  6. sessions := []*Session{OpenSession(user), OpenSession(user), OpenSession(user)}
  7. ids := []string{sessions[0].ID, sessions[1].ID, sessions[2].ID}
  8. t.Run("Find", func(t *testing.T) {
  9. for i, id := range ids {
  10. found := FindSession(id)
  11. if found != sessions[i] {
  12. t.Errorf("Find(\"%s\") == %+v", id, found)
  13. t.Fail()
  14. }
  15. }
  16. })
  17. t.Run("Close", func(t *testing.T) {
  18. CloseSession(ids[2])
  19. if FindSession(ids[0]) == nil || FindSession(ids[1]) == nil || FindSession(ids[2]) != nil {
  20. t.Errorf("Find(\"%s\") == %+v", ids[0], FindSession(ids[0]))
  21. t.Errorf("Find(\"%s\") == %+v", ids[1], FindSession(ids[1]))
  22. t.Errorf("Find(\"%s\") == %+v", ids[2], FindSession(ids[2]))
  23. t.Fail()
  24. }
  25. })
  26. t.Run("Clear", func(t *testing.T) {
  27. ClearSessions(user)
  28. if FindSession(ids[0]) != nil || FindSession(ids[1]) != nil || FindSession(ids[2]) != nil {
  29. t.Errorf("Find(\"%s\") == %+v", ids[0], FindSession(ids[0]))
  30. t.Errorf("Find(\"%s\") == %+v", ids[1], FindSession(ids[1]))
  31. t.Errorf("Find(\"%s\") == %+v", ids[2], FindSession(ids[2]))
  32. t.Fail()
  33. }
  34. })
  35. }