forked from pothtonswer/discordmuffin
Clean up tests further.
This commit is contained in:
parent
13086b8da3
commit
5f9326d165
2 changed files with 26 additions and 57 deletions
|
@ -21,6 +21,16 @@ var (
|
||||||
envAdmin string = os.Getenv("DG_ADMIN") // User ID of admin user to use for tests
|
envAdmin string = os.Getenv("DG_ADMIN") // User ID of admin user to use for tests
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if envEmail == "" || envPassword == "" || envToken == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if d, err := New(envEmail, envPassword, envToken); err == nil {
|
||||||
|
dg = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////// HELPER FUNCTIONS USED FOR TESTING
|
//////////////////////////////////////////// HELPER FUNCTIONS USED FOR TESTING
|
||||||
|
|
||||||
|
@ -76,15 +86,10 @@ func TestNew(t *testing.T) {
|
||||||
|
|
||||||
// TestInvalidToken tests the New() function with an invalid token
|
// TestInvalidToken tests the New() function with an invalid token
|
||||||
func TestInvalidToken(t *testing.T) {
|
func TestInvalidToken(t *testing.T) {
|
||||||
d, err := New("asjkldhflkjasdh")
|
_, err := New("asjkldhflkjasdh")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("New(InvalidToken) returned error: %+v", err)
|
t.Fatalf("New(InvalidToken) returned error: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = d.OpenAndListen(); err == nil {
|
|
||||||
t.Fatalf("New(InvalidToken), d.OpenAndListen did not fail.")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestInvalidUserPass tests the New() function with an invalid Email and Pass
|
// TestInvalidUserPass tests the New() function with an invalid Email and Pass
|
||||||
|
@ -132,20 +137,6 @@ func TestNewUserPass(t *testing.T) {
|
||||||
if d.Token == "" {
|
if d.Token == "" {
|
||||||
t.Fatal("New(user,pass), d.Token is empty, should be a valid Token.")
|
t.Fatal("New(user,pass), d.Token is empty, should be a valid Token.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = d.OpenAndListen(); err != nil {
|
|
||||||
t.Fatalf("New(user,pass), d.OpenAndListen failed: %+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !waitBoolEqual(10*time.Second, &d.DataReady, true) {
|
|
||||||
t.Fatal("New(user,pass), d.DataReady is false after 10 seconds. Should be true.")
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Log("Successfully connected to Discord via New(user,pass).")
|
|
||||||
dg = d
|
|
||||||
if envToken == "" {
|
|
||||||
envToken = dg.Token
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNewToken tests the New() function with a Token. This should return
|
// TestNewToken tests the New() function with a Token. This should return
|
||||||
|
@ -168,21 +159,9 @@ func TestNewToken(t *testing.T) {
|
||||||
if d.Token == "" {
|
if d.Token == "" {
|
||||||
t.Fatal("New(envToken), d.Token is empty, should be a valid Token.")
|
t.Fatal("New(envToken), d.Token is empty, should be a valid Token.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = d.OpenAndListen(); err != nil {
|
|
||||||
t.Fatalf("New(envToken), d.OpenAndListen failed: %+v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !waitBoolEqual(10*time.Second, &d.DataReady, true) {
|
func TestOpenClose(t *testing.T) {
|
||||||
t.Fatal("New(envToken), d.DataReady is false after 10 seconds. Should be true.")
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Log("Successfully connected to Discord via New(token).")
|
|
||||||
dg = d
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestClose(t *testing.T) {
|
|
||||||
if envToken == "" {
|
if envToken == "" {
|
||||||
t.Skip("Skipping TestClose, DG_TOKEN not set")
|
t.Skip("Skipping TestClose, DG_TOKEN not set")
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
// TestLogout tests the Logout() function. This should not return an error.
|
// TestLogout tests the Logout() function. This should not return an error.
|
||||||
func TestLogout(t *testing.T) {
|
func TestLogout(t *testing.T) {
|
||||||
|
|
||||||
if dg == nil || dg.Token == "" {
|
if dg == nil {
|
||||||
t.Skip("Cannot test logout, dg.Token not set.")
|
t.Skip("Cannot TestLogout, dg not set.")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dg.Logout()
|
err := dg.Logout()
|
||||||
|
@ -21,8 +21,8 @@ func TestLogout(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserAvatar(t *testing.T) {
|
func TestUserAvatar(t *testing.T) {
|
||||||
if !isConnected() {
|
if dg == nil {
|
||||||
t.Skip("Skipped, Not connected to Discord.")
|
t.Skip("Cannot TestUserAvatar, dg not set.")
|
||||||
}
|
}
|
||||||
|
|
||||||
a, err := dg.UserAvatar("@me")
|
a, err := dg.UserAvatar("@me")
|
||||||
|
@ -39,14 +39,8 @@ func TestUserAvatar(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserUpdate(t *testing.T) {
|
func TestUserUpdate(t *testing.T) {
|
||||||
|
if dg == nil {
|
||||||
if envEmail == "" || envPassword == "" {
|
t.Skip("Cannot test logout, dg not set.")
|
||||||
t.Skip("Skipping, DG_USERNAME or DG_PASSWORD not set")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isConnected() {
|
|
||||||
t.Skip("Skipped, Not connected to Discord.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := dg.User("@me")
|
u, err := dg.User("@me")
|
||||||
|
@ -73,9 +67,8 @@ func TestUserUpdate(t *testing.T) {
|
||||||
//func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) {
|
//func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) {
|
||||||
|
|
||||||
func TestUserChannelCreate(t *testing.T) {
|
func TestUserChannelCreate(t *testing.T) {
|
||||||
|
if dg == nil {
|
||||||
if !isConnected() {
|
t.Skip("Cannot TestUserChannelCreate, dg not set.")
|
||||||
t.Skip("Skipped, Not connected to Discord.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if envAdmin == "" {
|
if envAdmin == "" {
|
||||||
|
@ -91,9 +84,8 @@ func TestUserChannelCreate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserChannels(t *testing.T) {
|
func TestUserChannels(t *testing.T) {
|
||||||
|
if dg == nil {
|
||||||
if !isConnected() {
|
t.Skip("Cannot TestUserChannels, dg not set.")
|
||||||
t.Skip("Skipped, Not connected to Discord.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := dg.UserChannels()
|
_, err := dg.UserChannels()
|
||||||
|
@ -103,9 +95,8 @@ func TestUserChannels(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserGuilds(t *testing.T) {
|
func TestUserGuilds(t *testing.T) {
|
||||||
|
if dg == nil {
|
||||||
if !isConnected() {
|
t.Skip("Cannot TestUserGuilds, dg not set.")
|
||||||
t.Skip("Skipped, Not connected to Discord.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := dg.UserGuilds()
|
_, err := dg.UserGuilds()
|
||||||
|
@ -115,9 +106,8 @@ func TestUserGuilds(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserSettings(t *testing.T) {
|
func TestUserSettings(t *testing.T) {
|
||||||
|
if dg == nil {
|
||||||
if !isConnected() {
|
t.Skip("Cannot TestUserSettings, dg not set.")
|
||||||
t.Skip("Skipped, Not connected to Discord.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := dg.UserSettings()
|
_, err := dg.UserSettings()
|
||||||
|
|
Loading…
Reference in a new issue