Archived
2
0

Initial commit

This commit is contained in:
2023-03-02 15:28:43 +01:00
commit 2d4d7759e0
40 changed files with 4249 additions and 0 deletions

View 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)
})
})
}

View 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)
})
})
}