restapi_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package discordgo
  2. import (
  3. "testing"
  4. )
  5. //////////////////////////////////////////////////////////////////////////////
  6. /////////////////////////////////////////////////////////////// START OF TESTS
  7. // TestLogout tests the Logout() function. This should not return an error.
  8. func TestLogout(t *testing.T) {
  9. if dg == nil || dg.Token == "" {
  10. t.Skip("Cannot test logout, dg.Token not set.")
  11. }
  12. err := dg.Logout()
  13. if err != nil {
  14. t.Errorf("Logout() returned error: %+v", err)
  15. }
  16. }
  17. func TestUserAvatar(t *testing.T) {
  18. if !isConnected() {
  19. t.Skip("Skipped, Not connected to Discord.")
  20. }
  21. a, err := dg.UserAvatar("@me")
  22. if err != nil {
  23. if err.Error() == `HTTP 404 NOT FOUND, {"message": ""}` {
  24. t.Skip("Skipped, @me doesn't have an Avatar")
  25. }
  26. t.Errorf(err.Error())
  27. }
  28. if a == nil {
  29. t.Errorf("a == nil, should be image.Image")
  30. }
  31. }
  32. func TestUserUpdate(t *testing.T) {
  33. if envEmail == "" || envPassword == "" {
  34. t.Skip("Skipping, DG_USERNAME or DG_PASSWORD not set")
  35. return
  36. }
  37. if !isConnected() {
  38. t.Skip("Skipped, Not connected to Discord.")
  39. }
  40. u, err := dg.User("@me")
  41. if err != nil {
  42. t.Errorf(err.Error())
  43. }
  44. s, err := dg.UserUpdate(envEmail, envPassword, "testname", u.Avatar, "")
  45. if err != nil {
  46. t.Error(err.Error())
  47. }
  48. if s.Username != "testname" {
  49. t.Error("Username != testname")
  50. }
  51. s, err = dg.UserUpdate(envEmail, envPassword, u.Username, u.Avatar, "")
  52. if err != nil {
  53. t.Error(err.Error())
  54. }
  55. if s.Username != u.Username {
  56. t.Error("Username != " + u.Username)
  57. }
  58. }
  59. //func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) {
  60. func TestUserChannelCreate(t *testing.T) {
  61. if !isConnected() {
  62. t.Skip("Skipped, Not connected to Discord.")
  63. }
  64. if envAdmin == "" {
  65. t.Skip("Skipped, DG_ADMIN not set.")
  66. }
  67. _, err := dg.UserChannelCreate(envAdmin)
  68. if err != nil {
  69. t.Errorf(err.Error())
  70. }
  71. // TODO make sure the channel was added
  72. }
  73. func TestUserChannels(t *testing.T) {
  74. if !isConnected() {
  75. t.Skip("Skipped, Not connected to Discord.")
  76. }
  77. _, err := dg.UserChannels()
  78. if err != nil {
  79. t.Errorf(err.Error())
  80. }
  81. }
  82. func TestUserGuilds(t *testing.T) {
  83. if !isConnected() {
  84. t.Skip("Skipped, Not connected to Discord.")
  85. }
  86. _, err := dg.UserGuilds()
  87. if err != nil {
  88. t.Errorf(err.Error())
  89. }
  90. }
  91. func TestUserSettings(t *testing.T) {
  92. if !isConnected() {
  93. t.Skip("Skipped, Not connected to Discord.")
  94. }
  95. _, err := dg.UserSettings()
  96. if err != nil {
  97. t.Errorf(err.Error())
  98. }
  99. }