grcon/util/packet_test.go
Augusto Dwenger J. 1cda9ca591
Init commit
Initially it was the idea that this would be version 2 of the
https://github.com/hamburghammer/rcon lib but I changed my mind and
decided to make a new Project out of it.
It has formally nothing to do with the original lib.
2022-02-17 22:33:58 +01:00

37 lines
976 B
Go

package util_test
import (
"testing"
"github.com/hamburghammer/grcon"
"github.com/hamburghammer/grcon/util"
)
func TestNewExecCommandPacket(t *testing.T) {
got := util.NewExecCommandPacket(1, "foo")
if got.Type != grcon.SERVERDATA_EXECCOMMAND {
t.Errorf("type error:\nexpected: %v\ngot: %v\n", grcon.SERVERDATA_EXECCOMMAND, got.Type)
}
if got.Id != 1 {
t.Errorf("type error:\nexpected: %d\ngot: %d\n", 1, got.Id)
}
if string(got.Body) != "foo" {
t.Errorf("body error:\nexpected: %s\ngot: %s\n", "foo", string(got.Body))
}
}
func TestNewEmptyResponseValuePacket(t *testing.T) {
got := util.NewEmptyResponseValuePacket(1)
if got.Type != grcon.SERVERDATA_RESPONSE_VALUE {
t.Errorf("type error:\nexpected: %v\ngot: %v", grcon.SERVERDATA_RESPONSE_VALUE, got.Type)
}
if got.Id != 1 {
t.Errorf("type error:\nexpected: %d\ngot: %d\n", 1, got.Id)
}
if string(got.Body) != "" {
t.Errorf("body error:\nexpected: %s\ngot: %s", "", string(got.Body))
}
}