diff --git a/client.go b/client.go index 60dd5ca..4bcd384 100644 --- a/client.go +++ b/client.go @@ -405,7 +405,9 @@ func (c *Client) handleLine(line string) error { c.channelUserlist[channel][user] = true } } - if strings.Contains(line, "tmi.twitch.tv NOTICE * :Login authentication failed") || strings.Contains(line, "tmi.twitch.tv NOTICE * :Improperly formatted auth") { + if strings.Contains(line, "tmi.twitch.tv NOTICE * :Login authentication failed") || + strings.Contains(line, "tmi.twitch.tv NOTICE * :Improperly formatted auth") || + line == ":tmi.twitch.tv NOTICE * :Invalid NICK" { return ErrLoginAuthenticationFailed } } diff --git a/client_test.go b/client_test.go index 0476815..a7d91b0 100644 --- a/client_test.go +++ b/client_test.go @@ -891,16 +891,50 @@ func TestCanConnectToTwitch(t *testing.T) { client.Disconnect() }) - client.Connect() + err := client.Connect() + assertErrorsEqual(t, ErrClientDisconnected, err) } func TestCanConnectToTwitchWithoutTLS(t *testing.T) { client := NewClient("justinfan123123", "oauth:123123132") client.TLS = false + wait := make(chan struct{}) client.OnConnect(func() { client.Disconnect() }) - client.Connect() + go func() { + err := client.Connect() + assertErrorsEqual(t, ErrClientDisconnected, err) + close(wait) + }() + + select { + case <-wait: + case <-time.After(time.Second * 3): + t.Fatal("Did not establish a connection") + } +} + +func TestCanHandleInvalidNick(t *testing.T) { + client := NewClient("", "") + client.TLS = false + wait := make(chan struct{}) + + client.OnConnect(func() { + t.Fatal("A connection should not be able to be established with an invalid nick") + }) + + go func() { + err := client.Connect() + assertErrorsEqual(t, ErrLoginAuthenticationFailed, err) + close(wait) + }() + + select { + case <-wait: + case <-time.After(time.Second * 3): + t.Fatal("Did not establish a connection") + } } diff --git a/helpers_test.go b/helpers_test.go index 5ad1c3d..3577cba 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -41,3 +41,9 @@ func assertStringSlicesEqual(t *testing.T, expected, actual []string) { } } } + +func assertErrorsEqual(t *testing.T, expected, actual error) { + if expected != actual { + t.Errorf("failed asserting that error \"%s\" is expected \"%s\"", actual, expected) + } +}