本文整理汇总了Golang中github.com/TF2Stadium/Helen/internal/testhelpers.CreateLobby函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateLobby函数的具体用法?Golang CreateLobby怎么用?Golang CreateLobby使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateLobby函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGetSpectatingIds
func TestGetSpectatingIds(t *testing.T) {
t.Parallel()
player := testhelpers.CreatePlayer()
specIds, specErr := player.GetSpectatingIds()
assert.Nil(t, specErr)
assert.Equal(t, len(specIds), 0)
//assert.Equal(t, []uint{lobby.ID, lobby2.ID}, specIds)
lobby1 := testhelpers.CreateLobby()
database.DB.Save(lobby1)
lobby1.AddSpectator(player)
specIds, specErr = player.GetSpectatingIds()
assert.Nil(t, specErr)
assert.Equal(t, specIds[0], lobby1.ID)
lobby2 := testhelpers.CreateLobby()
database.DB.Save(lobby2)
lobby2.AddSpectator(player)
specIds, specErr = player.GetSpectatingIds()
assert.Nil(t, specErr)
for _, specID := range specIds {
assert.True(t, lobby1.ID == specID || lobby2.ID == specID)
}
}
示例2: TestMatchEnded
func TestMatchEnded(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
player := testhelpers.CreatePlayer()
lobby.Type = models.LobbyTypeBball
lobby.Save()
lobby.AddPlayer(player, 0, "")
e := rpc.Event{
Name: rpc.MatchEnded,
LobbyID: lobby.ID,
}
e.Handle(e, &struct{}{})
db.DB.Preload("Stats").First(player, player.ID)
assert.Equal(t, player.Stats.PlayedBballCount, 1)
lobby = testhelpers.CreateLobby()
lobby.Type = models.LobbyTypeBball
lobby.Save()
lobby.AddPlayer(player, 0, "")
e.LobbyID = lobby.ID
e.Handle(e, &struct{}{})
db.DB.Preload("Stats").First(player, player.ID)
assert.Equal(t, player.Stats.PlayedBballCount, 2)
assert.Equal(t, player.Stats.TotalLobbies(), 2)
}
示例3: TestIsSpectating
func TestIsSpectating(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
database.DB.Save(lobby)
lobby2 := testhelpers.CreateLobby()
database.DB.Save(lobby2)
player := testhelpers.CreatePlayer()
isSpectating := player.IsSpectatingID(lobby.ID)
assert.False(t, isSpectating)
lobby.AddSpectator(player)
isSpectating = player.IsSpectatingID(lobby.ID)
assert.True(t, isSpectating)
lobby2.AddSpectator(player)
isSpectating2 := player.IsSpectatingID(lobby2.ID)
assert.True(t, isSpectating2)
lobby.RemoveSpectator(player, false)
isSpectating = player.IsSpectatingID(lobby.ID)
assert.False(t, isSpectating)
}
示例4: TestLobbyAdd
func TestLobbyAdd(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby.Save()
var players []*Player
for i := 0; i < 12; i++ {
player := testhelpers.CreatePlayer()
players = append(players, player)
}
// add player
err := lobby.AddPlayer(players[0], 0, "")
assert.Nil(t, err)
slot, err2 := lobby.GetPlayerSlot(players[0])
assert.Zero(t, slot)
assert.Nil(t, err2)
id, err3 := lobby.GetPlayerIDBySlot(0)
assert.Equal(t, id, players[0].ID)
assert.Nil(t, err3)
// try to switch slots
err = lobby.AddPlayer(players[0], 1, "")
assert.Nil(t, err)
slot, err2 = lobby.GetPlayerSlot(players[0])
assert.Equal(t, slot, 1)
assert.Nil(t, err2)
// this should be empty now
id, err3 = lobby.GetPlayerIDBySlot(0)
assert.NotNil(t, err3)
// try to add a second player to the same slot
err = lobby.AddPlayer(players[1], 1, "")
assert.NotNil(t, err)
// try to add a player to a wrong slot slot
err = lobby.AddPlayer(players[2], 55, "")
assert.NotNil(t, err)
lobby2 := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby2.Save()
// try to add a player while they're in another lobby
//player should be substituted
lobby.State = LobbyStateInProgress
lobby.Save()
err = lobby2.AddPlayer(players[0], 1, "")
assert.Nil(t, err)
var count int
db.DB.Table("lobby_slots").Where("lobby_id = ? AND needs_sub = ?", lobby.ID, true).Count(&count)
assert.Equal(t, count, 1)
}
示例5: TestRemoveUnreadyPlayers
func TestRemoveUnreadyPlayers(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby.Save()
var players []*Player
for i := 0; i < 12; i++ {
player := testhelpers.CreatePlayer()
lobby.AddPlayer(player, i, "")
players = append(players, player)
}
err := lobby.RemoveUnreadyPlayers(true)
assert.Nil(t, err)
for i := 0; i < 12; i++ {
var count int
_, err := lobby.GetPlayerIDBySlot(i)
assert.Error(t, err)
db.DB.Table("spectators_players_lobbies").Where("lobby_id = ? AND player_id = ?", lobby.ID, players[i].ID).Count(&count)
assert.Equal(t, count, 1)
}
}
示例6: TestGetLobbyID
func TestGetLobbyID(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
lobby.Save()
player := testhelpers.CreatePlayer()
player.Save()
lobby.AddPlayer(player, 0, "")
lobby.Save()
id, err := player.GetLobbyID(false)
assert.NoError(t, err)
assert.Equal(t, id, lobby.ID)
lobby.State = LobbyStateEnded
lobby.Save()
id, err = player.GetLobbyID(false)
assert.Error(t, err)
assert.Equal(t, id, uint(0))
lobby.State = LobbyStateInProgress
lobby.Save()
//Exclude lobbies in progress
id, err = player.GetLobbyID(true)
assert.Error(t, err)
assert.Equal(t, id, uint(0))
//Include lobbies in progress
id, err = player.GetLobbyID(false)
assert.NoError(t, err)
assert.Equal(t, id, lobby.ID)
}
示例7: TestReportVoted
func TestReportVoted(t *testing.T) {
t.Parallel()
p := testhelpers.CreatePlayer()
l1 := testhelpers.CreateLobby()
defer l1.Close(false, false)
l2 := testhelpers.CreateLobby()
defer l2.Close(false, false)
// RageQuit = Vote + 1, so we don't need to test that
p.NewReport(Vote, l1.ID)
p.NewReport(Vote, l2.ID)
banned, until := p.IsBannedWithTime(BanJoin)
assert.True(t, banned, "Player should be banned from joining lobbies")
assert.WithinDuration(t, until, time.Now(), 30*time.Minute)
}
示例8: TestNotInGameSub
func TestNotInGameSub(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
var (
players []*Player
ingame, subbed, subcount int
//subs []int
)
for i := 0; i < 12; i++ {
players = append(players, testhelpers.CreatePlayer())
}
for i, player := range players {
err := lobby.AddPlayer(player, i, "")
assert.NoError(t, err)
r := rand.Intn(3)
if r == 1 {
ingame++
lobby.SetInGame(player)
} else if r == 2 {
lobby.Substitute(player)
subbed++
}
}
t.Logf("%d players are in-game, %d player have been substituted", ingame, subbed)
lobby.SubNotInGamePlayers()
db.DB.Table("lobby_slots").Where("lobby_id = ? AND needs_sub = ?", lobby.ID, true).Count(&subcount)
//assert.Equal(t, subcount, len(subs))
lobby.Close(false)
}
示例9: TestStart
func TestStart(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby.Start()
assert.Equal(t, lobby.CurrentState(), LobbyStateInProgress)
}
示例10: TestReportSubs
func TestReportSubs(t *testing.T) {
t.Parallel()
p := testhelpers.CreatePlayer()
l1 := testhelpers.CreateLobby()
defer l1.Close(false, false)
l2 := testhelpers.CreateLobby()
defer l2.Close(false, false)
// l3 := testhelpers.CreateLobby()
// defer l3.Close(false, false)
p.NewReport(Substitute, l1.ID)
p.NewReport(Substitute, l2.ID)
banned, until := p.IsBannedWithTime(BanJoin)
assert.True(t, banned, "Player should be banned from joining lobbies")
assert.WithinDuration(t, until, time.Now(), 30*time.Minute)
}
示例11: TestIsSubNeeded
func TestIsSubNeeded(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
player := testhelpers.CreatePlayer()
lobby.AddPlayer(player, 1, "")
lobby.Substitute(player)
assert.True(t, lobby.SlotNeedsSubstitute(1))
}
示例12: TestDisconnectedFromServer
func TestDisconnectedFromServer(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
e := rpc.Event{
Name: rpc.DisconnectedFromServer,
LobbyID: lobby.ID,
}
e.Handle(e, &struct{}{})
assert.Equal(t, lobby.CurrentState(), models.LobbyStateEnded)
}
示例13: TestDeleteUnusedServerRecords
func TestDeleteUnusedServerRecords(t *testing.T) {
var count int
lobby := testhelpers.CreateLobby()
lobby.Close(false)
db.DB.Save(&ServerRecord{})
DeleteUnusedServerRecords()
err := db.DB.Table("server_records").Count(&count).Error
assert.NoError(t, err)
assert.Zero(t, count)
}
示例14: TestIsPlayerInGame
func TestIsPlayerInGame(t *testing.T) {
t.Parallel()
player := testhelpers.CreatePlayer()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby.Save()
lobby.AddPlayer(player, 0, "")
lobby.SetInGame(player)
ingame, err := lobby.IsPlayerInGame(player)
assert.NoError(t, err)
assert.True(t, ingame)
}
示例15: TestSetInGame
func TestSetInGame(t *testing.T) {
t.Parallel()
player := testhelpers.CreatePlayer()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby.Save()
lobby.AddPlayer(player, 0, "")
lobby.SetInGame(player)
slot, err := lobby.GetPlayerSlotObj(player)
assert.Nil(t, err)
assert.True(t, slot.InGame)
}