From 79f68187bf31060040da73c6c51887782cd705c5 Mon Sep 17 00:00:00 2001 From: CPunch Date: Sun, 4 Feb 2024 11:26:48 -0600 Subject: [PATCH] testutil: DummyPeer now holds onto the *is.Is makes SendAndRecv a bit cleaner imo --- internal/testutil/helpers.go | 11 ++++++----- login/login_test.go | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/testutil/helpers.go b/internal/testutil/helpers.go index 3aaaee2..e01a9d8 100644 --- a/internal/testutil/helpers.go +++ b/internal/testutil/helpers.go @@ -19,6 +19,7 @@ import ( type DummyPeer struct { Recv chan *cnet.PacketEvent Peer *cnet.Peer + is *is.I } // MakeDummyPeer creates a new dummy peer and returns it @@ -32,21 +33,21 @@ func MakeDummyPeer(ctx context.Context, is *is.I, port int) *DummyPeer { peer.Handler(recv) }() - return &DummyPeer{Recv: recv, Peer: peer} + return &DummyPeer{Recv: recv, Peer: peer, is: is} } // SendAndRecv sends a packet (sID & out), waits for the expected response (rID) and decodes it into in -func (dp *DummyPeer) SendAndRecv(is *is.I, sID, rID uint32, out, in interface{}) { +func (dp *DummyPeer) SendAndRecv(sID, rID uint32, out, in interface{}) { // send out packet err := dp.Peer.Send(sID, out) - is.NoErr(err) // peer.Send() should not return an error + dp.is.NoErr(err) // peer.Send() should not return an error // receive response evnt := <-dp.Recv defer protocol.PutBuffer(evnt.Pkt) - is.Equal(evnt.PktID, rID) // should receive expected type - is.NoErr(protocol.NewPacket(evnt.Pkt).Decode(in)) // packet.Decode() should not return an error + dp.is.Equal(evnt.PktID, rID) // should receive expected type + dp.is.NoErr(protocol.NewPacket(evnt.Pkt).Decode(in)) // packet.Decode() should not return an error } // Kill closes the peer's connection diff --git a/login/login_test.go b/login/login_test.go index 53d7bc2..e250f0b 100644 --- a/login/login_test.go +++ b/login/login_test.go @@ -87,7 +87,7 @@ func TestLoginSuccSequence(t *testing.T) { // send login request (this should create an account) var resp protocol.SP_LS2CL_REP_LOGIN_SUCC - dummy.SendAndRecv(is, protocol.P_CL2LS_REQ_LOGIN, protocol.P_LS2CL_REP_LOGIN_SUCC, + dummy.SendAndRecv(protocol.P_CL2LS_REQ_LOGIN, protocol.P_LS2CL_REP_LOGIN_SUCC, protocol.SP_CL2LS_REQ_LOGIN{ SzID: "testLoginSequence", SzPassword: "test", @@ -113,7 +113,7 @@ func TestLoginFailSequence(t *testing.T) { // send login request (this should not create an account) var resp protocol.SP_LS2CL_REP_LOGIN_FAIL - dummy.SendAndRecv(is, protocol.P_CL2LS_REQ_LOGIN, protocol.P_LS2CL_REP_LOGIN_FAIL, + dummy.SendAndRecv(protocol.P_CL2LS_REQ_LOGIN, protocol.P_LS2CL_REP_LOGIN_FAIL, protocol.SP_CL2LS_REQ_LOGIN{ SzID: "", SzPassword: "", @@ -135,7 +135,7 @@ func TestCharacterSequence(t *testing.T) { // send login request (this should create an account) var resp protocol.SP_LS2CL_REP_LOGIN_SUCC - dummy.SendAndRecv(is, protocol.P_CL2LS_REQ_LOGIN, protocol.P_LS2CL_REP_LOGIN_SUCC, + dummy.SendAndRecv(protocol.P_CL2LS_REQ_LOGIN, protocol.P_LS2CL_REP_LOGIN_SUCC, protocol.SP_CL2LS_REQ_LOGIN{ SzID: "testCharacterSequence", SzPassword: "test", @@ -159,7 +159,7 @@ func TestCharacterSequence(t *testing.T) { // send character name check request var charResp protocol.SP_LS2CL_REP_SAVE_CHAR_NAME_SUCC - dummy.SendAndRecv(is, protocol.P_CL2LS_REQ_SAVE_CHAR_NAME, protocol.P_LS2CL_REP_SAVE_CHAR_NAME_SUCC, + dummy.SendAndRecv(protocol.P_CL2LS_REQ_SAVE_CHAR_NAME, protocol.P_LS2CL_REP_SAVE_CHAR_NAME_SUCC, protocol.SP_CL2LS_REQ_SAVE_CHAR_NAME{ ISlotNum: 1, IGender: 1, @@ -180,7 +180,7 @@ func TestCharacterSequence(t *testing.T) { charCreate := testCharCreate charCreate.PCStyle.IPC_UID = charResp.IPC_UID var charCreateResp protocol.SP_LS2CL_REP_CHAR_CREATE_SUCC - dummy.SendAndRecv(is, protocol.P_CL2LS_REQ_CHAR_CREATE, protocol.P_LS2CL_REP_CHAR_CREATE_SUCC, + dummy.SendAndRecv(protocol.P_CL2LS_REQ_CHAR_CREATE, protocol.P_LS2CL_REP_CHAR_CREATE_SUCC, charCreate, &charCreateResp) // verify response