Exemplo n.º 1
0
func TestGetJoinedPlayers(t *testing.T) {
	dao := NewLobbyDAO()

	joinedPlayers := dao.GetJoinedPlayers()
	assert.True(t, len(joinedPlayers) == 0, "Should be 0 players")

	for i := 0; i < 3; i++ {
		{
			player := model.NewPlayer()
			player.PlayerName = "aron" + string(i)
			player.JoinedTs = 1234

			dao.SavePlayer(player)
		}
	}

	joinedPlayers = dao.GetJoinedPlayers()
	assert.True(t, len(joinedPlayers) == 3, "Should be 3 players")

	for i := 0; i < 3; i++ {
		{
			dao.RemovePlayer("aron" + string(i))
		}
	}
	joinedPlayers = dao.GetJoinedPlayers()
	assert.True(t, len(joinedPlayers) == 0, "Should be 0 players")
}
Exemplo n.º 2
0
/**
 * Join a named player to the lobby, indicating that they are ready for a game challenge
 * @param playerName
 * @return
 */
func (self *LobbyAPI) JoinPlayer(playerName string) *model.Player {
	player := self.lobbyDAO.GetPlayer(playerName)
	if player == nil {
		player = model.NewPlayer()
		player.PlayerName = playerName
		player.JoinedTs = util.Now()
		self.lobbyDAO.SavePlayer(player)
	}

	return player
}
Exemplo n.º 3
0
func TestRemovePlayer(t *testing.T) {
	dao := NewLobbyDAO()

	player := model.NewPlayer()
	player.PlayerName = "aron"
	player.JoinedTs = 1234

	dao.SavePlayer(player)
	dao.RemovePlayer(player.PlayerName)
	savedPlayer := dao.GetPlayer(player.PlayerName)

	assert.Nil(t, savedPlayer, "The original player should be destroyed")
}
Exemplo n.º 4
0
func TestGetSavePlayer(t *testing.T) {
	dao := NewLobbyDAO()

	player := model.NewPlayer()
	player.PlayerName = "aron"
	player.JoinedTs = 1234

	dao.SavePlayer(player)
	savedPlayer := dao.GetPlayer(player.PlayerName)

	assert.NotEmpty(t, savedPlayer, "The original player should be rehydratable")
	assert.Equal(t, player.PlayerName, savedPlayer.PlayerName, "The rehydrated player name should be the same as the originally saved player")
	assert.Equal(t, player.JoinedTs, savedPlayer.JoinedTs, "The rehydrated player joined ts should be the same as the originally saved player")
}