PageRenderTime 50ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/model/user_access_token_test.go

https://gitlab.com/unofficial-mirrors/mattermost-platform
Go | 58 lines | 43 code | 13 blank | 2 comment | 22 complexity | 21ec62b727f57589e80bb7e39f70dc34 MD5 | raw file
  1. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
  2. // See License.txt for license information.
  3. package model
  4. import (
  5. "strings"
  6. "testing"
  7. )
  8. func TestUserAccessTokenJson(t *testing.T) {
  9. a1 := UserAccessToken{}
  10. a1.UserId = NewId()
  11. a1.Token = NewId()
  12. json := a1.ToJson()
  13. ra1 := UserAccessTokenFromJson(strings.NewReader(json))
  14. if a1.Token != ra1.Token {
  15. t.Fatal("tokens didn't match")
  16. }
  17. tokens := []*UserAccessToken{&a1}
  18. json = UserAccessTokenListToJson(tokens)
  19. tokens = UserAccessTokenListFromJson(strings.NewReader(json))
  20. if tokens[0].Token != a1.Token {
  21. t.Fatal("tokens didn't match")
  22. }
  23. }
  24. func TestUserAccessTokenIsValid(t *testing.T) {
  25. ad := UserAccessToken{}
  26. if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.id.app_error" {
  27. t.Fatal(err)
  28. }
  29. ad.Id = NewRandomString(26)
  30. if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.token.app_error" {
  31. t.Fatal(err)
  32. }
  33. ad.Token = NewRandomString(26)
  34. if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.user_id.app_error" {
  35. t.Fatal(err)
  36. }
  37. ad.UserId = NewRandomString(26)
  38. if err := ad.IsValid(); err != nil {
  39. t.Fatal(err)
  40. }
  41. ad.Description = NewRandomString(256)
  42. if err := ad.IsValid(); err == nil || err.Id != "model.user_access_token.is_valid.description.app_error" {
  43. t.Fatal(err)
  44. }
  45. }