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.

59 lines
1.5 KiB

  1. package container
  2. import (
  3. "LAPP_LF_MOM_BACKEND/web/models"
  4. "fmt"
  5. "testing"
  6. )
  7. func TestSessionContext_New(t *testing.T) {
  8. userId := "userId"
  9. user := &models.Usertab{Userid: userId}
  10. sessionContext, err := NewSessionContext(user, transactionHandlerFactoryMock)
  11. if err != nil {
  12. t.Fatalf("意外错误:%s", err.Error())
  13. }
  14. if sessionContext == nil {
  15. t.Fatalf("创建失败!")
  16. }
  17. if sessionContext.user.Userid != userId {
  18. t.Fatalf("用户标识错误!")
  19. }
  20. }
  21. func TestSessionContext_New_NullUser(t *testing.T) {
  22. _, err := NewSessionContext(nil, transactionHandlerFactoryMock)
  23. if err == nil {
  24. t.Fatalf("意外的没有错误!")
  25. }
  26. if err.Error() != fmt.Sprintf("用户信息不能为空!") {
  27. t.Fatalf("意外错误:%s", err.Error())
  28. }
  29. }
  30. func TestSessionContext_New_NullTransactionHandlerFactory(t *testing.T) {
  31. userId := "userId"
  32. user := &models.Usertab{Userid: userId}
  33. _, err := NewSessionContext(user, nil)
  34. if err == nil {
  35. t.Fatalf("意外的没有错误!")
  36. }
  37. if err.Error() != fmt.Sprintf("事务句柄工厂不能为空!") {
  38. t.Fatalf("意外错误:%s", err.Error())
  39. }
  40. }
  41. func TestSessionContext_UserId(t *testing.T) {
  42. userId := "userId1"
  43. user := &models.Usertab{Userid: userId}
  44. sessionContext, err := NewSessionContext(user, transactionHandlerFactoryMock)
  45. if err != nil {
  46. t.Fatalf("意外错误:%s", err.Error())
  47. }
  48. userId = "userId2"
  49. sessionContext.user.Userid = userId
  50. if sessionContext.User().Userid != userId {
  51. t.Fatalf("获取用户标识错误!")
  52. }
  53. }