Skip to content

Commit

Permalink
Merge 394311f into cfbe679
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Jan 27, 2019
2 parents cfbe679 + 394311f commit e5e3ece
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion client.go
Expand Up @@ -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
}
}
Expand Down
38 changes: 36 additions & 2 deletions client_test.go
Expand Up @@ -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")
}
}
6 changes: 6 additions & 0 deletions helpers_test.go
Expand Up @@ -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)
}
}

0 comments on commit e5e3ece

Please sign in to comment.