Browse Source

Add test for u/p/token login.

Chris Rhodes 9 năm trước cách đây
mục cha
commit
7d984e7df6
1 tập tin đã thay đổi với 24 bổ sung2 xóa
  1. 24 2
      discord_test.go

+ 24 - 2
discord_test.go

@@ -122,8 +122,7 @@ func TestInvalidPass(t *testing.T) {
 }
 
 // TestNewUserPass tests the New() function with a username and password.
-// This should return a valid Session{}, a valid Session.Token, and open
-// a websocket connection to Discord.
+// This should return a valid Session{}, a valid Session.Token.
 func TestNewUserPass(t *testing.T) {
 
 	if envEmail == "" || envPassword == "" {
@@ -167,6 +166,29 @@ func TestNewToken(t *testing.T) {
 	}
 }
 
+// TestNewUserPassToken tests the New() function with a username, password and token.
+// This should return the same as the TestNewUserPass function.
+func TestNewUserPassToken(t *testing.T) {
+
+	if envEmail == "" || envPassword == "" || envToken == "" {
+		t.Skip("Skipping New(username,password,token), DG_EMAIL, DG_PASSWORD or DG_TOKEN not set")
+		return
+	}
+
+	d, err := New(envEmail, envPassword, envToken)
+	if err != nil {
+		t.Fatalf("New(user,pass,token) returned error: %+v", err)
+	}
+
+	if d == nil {
+		t.Fatal("New(user,pass,token), d is nil, should be Session{}")
+	}
+
+	if d.Token == "" {
+		t.Fatal("New(user,pass,token), d.Token is empty, should be a valid Token.")
+	}
+}
+
 func TestOpenClose(t *testing.T) {
 	if envToken == "" {
 		t.Skip("Skipping TestClose, DG_TOKEN not set")