當前位置: 首頁>>代碼示例>>Golang>>正文


Golang testhelpers.CreateLobby函數代碼示例

本文整理匯總了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)
	}
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:28,代碼來源:player_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:30,代碼來源:event_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:27,代碼來源:player_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:60,代碼來源:lobby_test.go

示例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)
	}
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:26,代碼來源:lobby_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:34,代碼來源:player_test.go

示例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)
}
開發者ID:TF2Stadium,項目名稱:Helen,代碼行數:16,代碼來源:player_report_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:34,代碼來源:lobby_test.go

示例9: TestStart

func TestStart(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)

	lobby.Start()
	assert.Equal(t, lobby.CurrentState(), LobbyStateInProgress)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:8,代碼來源:lobby_test.go

示例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)
}
開發者ID:TF2Stadium,項目名稱:Helen,代碼行數:18,代碼來源:player_report_test.go

示例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))

}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:11,代碼來源:lobby_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:12,代碼來源:event_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:13,代碼來源:lobby_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:14,代碼來源:lobby_test.go

示例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)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:14,代碼來源:lobby_test.go


注:本文中的github.com/TF2Stadium/Helen/internal/testhelpers.CreateLobby函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。