restapi_test.go 3.1 KB

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