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.

49 satır
1.3KB

  1. package main
  2. import (
  3. "log"
  4. "testing"
  5. "time"
  6. )
  7. func TestSession(t *testing.T) {
  8. id := "testopenid"
  9. procedure := "test procedure"
  10. //delete any existing
  11. deleteSession(id)
  12. path := getSessionPath(id)
  13. AssertEqual(t, isFileExist(path), false, "Session file should not exist")
  14. //create new
  15. setSessionProcedure(id, procedure, 100)
  16. //wait 1 sec
  17. log.Print("wait for 1 sec for testing timestamp ......")
  18. time.Sleep(1 * time.Second)
  19. log.Print("......waiting done")
  20. //read back , check state
  21. s, _ := getCurrentSesssion(id)
  22. AssertEqual(t, s.Procedure, procedure, "")
  23. now := int32(time.Now().Unix())
  24. //check timing
  25. AssertEqual(t, s.Expire > now, true, "Expire should be in future")
  26. AssertEqual(t, s.UpdateAt < now, true, "Update should be in pass")
  27. AssertEqual(t, s.CreateAt == s.UpdateAt, true, "Update should be equal to create")
  28. AssertEqual(t, isExpired(now), false, "current time should not be expired")
  29. //update existing session
  30. s, _ = setSessionProcedure(id, procedure, 100)
  31. //timeing should be exactly 1s diff
  32. AssertEqual(t, s.CreateAt+1 == s.UpdateAt, true, "second Update should be bigger create")
  33. n, _ := getCurrentSesssion(id)
  34. AssertEqual(t, s, n, "session should be equal")
  35. //delete session, for clean up
  36. deleteSession(id)
  37. path = getSessionPath(id)
  38. AssertEqual(t, isFileExist(path), false, "Session file should not exist")
  39. }