示例#1
0
func TestMetaAction_PlayerLeft(t *testing.T) {
	code := message.MetaActionCodes["player_left"]
	tick := message.Tick(42)
	entityId := message.EntityId(69)

	testMessage(t, message.Types["meta_action"], func(w io.Writer) error {
		return builder.SendPlayerLeft(w, tick, entityId)
	}, func(conn *message.Conn, t *testing.T) {
		rt, id, c, _ := handler.ReadMetaAction(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if id != entityId {
			t.Fatal("Sent entity id", entityId, "but received", id)
		}
		if c != code {
			t.Fatal("Sent code", code, "but received", c)
		}
	})
}
示例#2
0
func TestMetaAction_PlayerJoined(t *testing.T) {
	code := message.MetaActionCodes["player_joined"]
	tick := message.Tick(42)
	entityId := message.EntityId(69)
	username := "******"

	testMessage(t, message.Types["meta_action"], func(w io.Writer) error {
		return builder.SendPlayerJoined(w, tick, entityId, username)
	}, func(conn *message.Conn, t *testing.T) {
		rt, id, c, u := handler.ReadMetaAction(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if id != entityId {
			t.Fatal("Sent entity id", entityId, "but received", id)
		}
		if c != code {
			t.Fatal("Sent code", code, "but received", c)
		}
		if u != username {
			t.Fatal("Sent username", username, "but received", u)
		}
	})
}