123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- package discordgo
- import (
- "errors"
- "testing"
- )
- //////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////// START OF TESTS
- // TestChannelMessageSend tests the ChannelMessageSend() function. This should not return an error.
- func TestChannelMessageSend(t *testing.T) {
- if envChannel == "" {
- t.Skip("Skipping, DG_CHANNEL not set.")
- }
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.ChannelMessageSend(envChannel, "Running REST API Tests!")
- if err != nil {
- t.Errorf("ChannelMessageSend returned error: %+v", err)
- }
- }
- /*
- // removed for now, only works on BOT accounts now
- func TestUserAvatar(t *testing.T) {
- if dg == nil {
- t.Skip("Cannot TestUserAvatar, dg not set.")
- }
- u, err := dg.User("@me")
- if err != nil {
- t.Error("error fetching @me user,", err)
- }
- a, err := dg.UserAvatar(u.ID)
- if err != nil {
- if err.Error() == `HTTP 404 NOT FOUND, {"code": 0, "message": "404: Not Found"}` {
- t.Skip("Skipped, @me doesn't have an Avatar")
- }
- t.Errorf(err.Error())
- }
- if a == nil {
- t.Errorf("a == nil, should be image.Image")
- }
- }
- */
- /* Running this causes an error due to 2/hour rate limit on username changes
- func TestUserUpdate(t *testing.T) {
- if dg == nil {
- t.Skip("Cannot test logout, dg not set.")
- }
- u, err := dg.User("@me")
- if err != nil {
- t.Errorf(err.Error())
- }
- s, err := dg.UserUpdate(envEmail, envPassword, "testname", u.Avatar, "")
- if err != nil {
- t.Error(err.Error())
- }
- if s.Username != "testname" {
- t.Error("Username != testname")
- }
- s, err = dg.UserUpdate(envEmail, envPassword, u.Username, u.Avatar, "")
- if err != nil {
- t.Error(err.Error())
- }
- if s.Username != u.Username {
- t.Error("Username != " + u.Username)
- }
- }
- */
- //func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) {
- func TestUserChannelCreate(t *testing.T) {
- if dg == nil {
- t.Skip("Cannot TestUserChannelCreate, dg not set.")
- }
- if envAdmin == "" {
- t.Skip("Skipped, DG_ADMIN not set.")
- }
- _, err := dg.UserChannelCreate(envAdmin)
- if err != nil {
- t.Errorf(err.Error())
- }
- // TODO make sure the channel was added
- }
- func TestUserGuilds(t *testing.T) {
- if dg == nil {
- t.Skip("Cannot TestUserGuilds, dg not set.")
- }
- _, err := dg.UserGuilds(10, "", "")
- if err != nil {
- t.Errorf(err.Error())
- }
- }
- func TestGateway(t *testing.T) {
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.Gateway()
- if err != nil {
- t.Errorf("Gateway() returned error: %+v", err)
- }
- }
- func TestGatewayBot(t *testing.T) {
- if dgBot == nil {
- t.Skip("Skipping, dgBot not set.")
- }
- _, err := dgBot.GatewayBot()
- if err != nil {
- t.Errorf("GatewayBot() returned error: %+v", err)
- }
- }
- func TestVoiceRegions(t *testing.T) {
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.VoiceRegions()
- if err != nil {
- t.Errorf("VoiceRegions() returned error: %+v", err)
- }
- }
- func TestGuildRoles(t *testing.T) {
- if envGuild == "" {
- t.Skip("Skipping, DG_GUILD not set.")
- }
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.GuildRoles(envGuild)
- if err != nil {
- t.Errorf("GuildRoles(envGuild) returned error: %+v", err)
- }
- }
- func TestGuildMemberNickname(t *testing.T) {
- if envGuild == "" {
- t.Skip("Skipping, DG_GUILD not set.")
- }
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- err := dg.GuildMemberNickname(envGuild, "@me/nick", "B1nzyRocks")
- if err != nil {
- t.Errorf("GuildNickname returned error: %+v", err)
- }
- }
- // TestChannelMessageSend2 tests the ChannelMessageSend() function. This should not return an error.
- func TestChannelMessageSend2(t *testing.T) {
- if envChannel == "" {
- t.Skip("Skipping, DG_CHANNEL not set.")
- }
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.ChannelMessageSend(envChannel, "All done running REST API Tests!")
- if err != nil {
- t.Errorf("ChannelMessageSend returned error: %+v", err)
- }
- }
- // TestGuildPruneCount tests GuildPruneCount() function. This should not return an error.
- func TestGuildPruneCount(t *testing.T) {
- if envGuild == "" {
- t.Skip("Skipping, DG_GUILD not set.")
- }
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.GuildPruneCount(envGuild, 1)
- if err != nil {
- t.Errorf("GuildPruneCount returned error: %+v", err)
- }
- }
- /*
- // TestGuildPrune tests GuildPrune() function. This should not return an error.
- func TestGuildPrune(t *testing.T) {
- if envGuild == "" {
- t.Skip("Skipping, DG_GUILD not set.")
- }
- if dg == nil {
- t.Skip("Skipping, dg not set.")
- }
- _, err := dg.GuildPrune(envGuild, 1)
- if err != nil {
- t.Errorf("GuildPrune returned error: %+v", err)
- }
- }
- */
- func Test_unmarshal(t *testing.T) {
- err := unmarshal([]byte{}, &struct{}{})
- if !errors.Is(err, ErrJSONUnmarshal) {
- t.Errorf("Unexpected error type: %T", err)
- }
- }
|