Initial commit
This commit is contained in:
38
utils/tests/client_test.go
Normal file
38
utils/tests/client_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"kerma/helpers"
|
||||
"kerma/models"
|
||||
"kerma/utils"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
host := "127.0.0.1:1338"
|
||||
net.Listen("tcp", host)
|
||||
conn, _ := net.Dial("tcp", host)
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
var config helpers.Config
|
||||
config.Construct()
|
||||
|
||||
var handler utils.TCPHandler
|
||||
handler.Construct(conn)
|
||||
|
||||
var state models.State
|
||||
state.Construct()
|
||||
|
||||
Convey("Given a new client", t, func() {
|
||||
var client utils.Client
|
||||
client.Construct(&state, handler)
|
||||
|
||||
Convey("When Construct is called, a new object is returned", func() {
|
||||
So(client.State, ShouldResemble, &state)
|
||||
So(client.Handler, ShouldResemble, handler)
|
||||
})
|
||||
})
|
||||
}
|
51
utils/tests/handler_test.go
Normal file
51
utils/tests/handler_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"kerma/helpers"
|
||||
"kerma/utils"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestHandler(t *testing.T) {
|
||||
host := "127.0.0.1:1337"
|
||||
net.Listen("tcp", host)
|
||||
conn, _ := net.Dial("tcp", host)
|
||||
scanner := bufio.NewScanner(conn)
|
||||
|
||||
var config helpers.Config
|
||||
config.Construct()
|
||||
|
||||
Convey("Given a new handler", t, func() {
|
||||
var handler utils.TCPHandler
|
||||
handler.Construct(conn)
|
||||
|
||||
Convey("When Construct is called, a new object is returned", func() {
|
||||
So(handler.Conn, ShouldResemble, conn)
|
||||
So(handler.Config, ShouldResemble, config)
|
||||
})
|
||||
|
||||
Convey("When Output is called, a JSON string should be returned on the connection", func() {
|
||||
jsonString := `{"foo": "bar"}`
|
||||
handler.Output([]byte(jsonString))
|
||||
resp := string(scanner.Bytes())
|
||||
|
||||
So(resp, ShouldEqual, resp)
|
||||
})
|
||||
|
||||
Convey("When Input is called, a JSON string and no error should be obtained from the connection", func() {
|
||||
jsonString := `{"foo": "bar"}`
|
||||
resp, err := handler.Input([]byte(jsonString))
|
||||
|
||||
So(resp, ShouldEqual, resp)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("When GetRemotePeer is called, the local connection should be returned", func() {
|
||||
So(handler.GetRemotePeer(), ShouldEqual, host)
|
||||
})
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user