Skip to content

Commit

Permalink
added a few more irc client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jriddick committed Nov 9, 2016
1 parent a4e6d02 commit b7fd3b4
Showing 1 changed file with 88 additions and 12 deletions.
100 changes: 88 additions & 12 deletions irc/irc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ var (
)

func TestClient(t *testing.T) {
Convey("With the default IRC client", t, func() {
// Create the mockd server
mockd := mockd.NewMockd(5000)
// Create the mockd server
mockd := mockd.NewMockd(5000)

// Start listening
So(mockd.Listen(), ShouldBeNil)
// Start listening
mockd.Listen()

// Start accepting connections
go mockd.Handle()
// Start accepting connections
go mockd.Handle()

Convey("With the default IRC client", t, func() {
Convey("It should be able to connect", func() {
// Open client
client := NewIRC(defaultConfig)

// Connect the client
So(client.Connect(), ShouldBeNil)
defer client.Disconnect()

// Get the reader channel
reader := client.Reader()
Expand All @@ -51,7 +50,6 @@ func TestClient(t *testing.T) {

// Connect to the server
So(client.Connect(), ShouldBeNil)
defer client.Disconnect()

// Get the reader and writer channel
reader := client.Reader()
Expand All @@ -78,7 +76,6 @@ func TestClient(t *testing.T) {

// Connect
So(client.Connect(), ShouldBeNil)
defer client.Disconnect()

// Get the reader
reader := client.Reader()
Expand All @@ -93,8 +90,87 @@ func TestClient(t *testing.T) {
So(<-reader, ShouldNotBeNil)
})

Reset(func() {
So(mockd.Stop(), ShouldBeNil)
Convey("It should reject empty hostname", func() {
// Open client
client := NewIRC(Config{
Hostname: "",
Port: defaultConfig.Port,
Secure: defaultConfig.Secure,
InsecureSkipVerify: defaultConfig.InsecureSkipVerify,
Timeout: defaultConfig.Timeout,
TimeoutLimit: defaultConfig.TimeoutLimit,
})

// Should fail to connect
So(client.Connect(), ShouldNotBeNil)
})

Convey("It should fail to connect securely to non-ssl server", func() {
// Create the client
client := NewIRC(Config{
Hostname: defaultConfig.Hostname,
Port: defaultConfig.Port,
Secure: true,
InsecureSkipVerify: defaultConfig.InsecureSkipVerify,
Timeout: defaultConfig.Timeout,
TimeoutLimit: defaultConfig.TimeoutLimit,
})

// Should fail to connect
So(client.Connect(), ShouldNotBeNil)
})

Convey("It should not be able to connect twice", func() {
// Create the client
client := NewIRC(defaultConfig)

// Should succeed to connect
So(client.Connect(), ShouldBeNil)

// Should not succeed a second time
So(client.Connect(), ShouldNotBeNil)
})

Convey("It should not be able to send empty messages", func() {
// Create the client
client := NewIRC(defaultConfig)

// Should succeed to connect
So(client.Connect(), ShouldBeNil)

// Get the writer
writer := client.Writer()

// Send empty message
writer <- ""

// Get error channel
errors := client.Errors()

// We should receive error
err := <-errors

// Check the error
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "tried to send empty message")
})

Convey("It should be able to disconnect", func() {
// Create the client
client := NewIRC(Config{
Hostname: defaultConfig.Hostname,
Port: defaultConfig.Port,
Secure: defaultConfig.Secure,
InsecureSkipVerify: defaultConfig.InsecureSkipVerify,
Timeout: time.Second * 1,
TimeoutLimit: defaultConfig.TimeoutLimit,
})

// Should connect
So(client.Connect(), ShouldBeNil)

// Should disconnect
client.Disconnect()
})
})
}

0 comments on commit b7fd3b4

Please sign in to comment.