Added isConnected helper func
This commit is contained in:
parent
aebe839e13
commit
4f3b4b7a4b
1 changed files with 30 additions and 1 deletions
|
@ -43,6 +43,26 @@ func waitBoolEqual(timeout time.Duration, check *bool, want bool) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if we're connected to Discord
|
||||||
|
func isConnected() bool {
|
||||||
|
|
||||||
|
if dg == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if dg.Token == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need a way to see if the ws connection is nil
|
||||||
|
|
||||||
|
if !waitBoolEqual(10*time.Second, &dg.DataReady, true) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////// START OF TESTS
|
/////////////////////////////////////////////////////////////// START OF TESTS
|
||||||
|
|
||||||
|
@ -60,6 +80,11 @@ func TestNew(t *testing.T) {
|
||||||
// This should return a valid Session{}, a valid Session.Token, and open
|
// This should return a valid Session{}, a valid Session.Token, and open
|
||||||
// a websocket connection to Discord.
|
// a websocket connection to Discord.
|
||||||
func TestNewUserPass(t *testing.T) {
|
func TestNewUserPass(t *testing.T) {
|
||||||
|
|
||||||
|
if isConnected() {
|
||||||
|
t.Skip("Skipping New(username,password), already connected.")
|
||||||
|
}
|
||||||
|
|
||||||
if envUsername == "" || envPassword == "" {
|
if envUsername == "" || envPassword == "" {
|
||||||
t.Skip("Skipping New(username,password), DG_USERNAME or DG_PASSWORD not set")
|
t.Skip("Skipping New(username,password), DG_USERNAME or DG_PASSWORD not set")
|
||||||
return
|
return
|
||||||
|
@ -70,9 +95,13 @@ func TestNewUserPass(t *testing.T) {
|
||||||
// TestNewToken tests the New() function with a Token. This should return
|
// TestNewToken tests the New() function with a Token. This should return
|
||||||
// the same as the TestNewUserPass function.
|
// the same as the TestNewUserPass function.
|
||||||
func TestNewToken(t *testing.T) {
|
func TestNewToken(t *testing.T) {
|
||||||
|
|
||||||
|
if isConnected() {
|
||||||
|
t.Skip("Skipping New(token), already connected.")
|
||||||
|
}
|
||||||
|
|
||||||
if envToken == "" {
|
if envToken == "" {
|
||||||
t.Skip("Skipping New(token), DG_TOKEN not set")
|
t.Skip("Skipping New(token), DG_TOKEN not set")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := New(envToken)
|
d, err := New(envToken)
|
||||||
|
|
Loading…
Reference in a new issue