Пример #1
0
func TestGetTeam(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	team1 := steward.Team{
		ID: -1, Name: "MySuperTeam", Subnet: "192.168.111/24",
		Vulnbox: "pl.hold1", UseNetbox: false, Netbox: "nb.hold1"}

	team1.ID, _ = steward.AddTeam(db.db, team1)

	_team1, err := steward.GetTeam(db.db, team1.ID)
	if err != nil {
		log.Fatalln("Get team failed:", err)
	}

	if _team1 != team1 {
		log.Fatalln("Added team broken")
	}

	_, err = steward.GetTeam(db.db, 10) // invalid team id
	if err == nil {
		log.Fatalln("Get invalid team broken")
	}
}
Пример #2
0
// CountRound count round result
func CountRound(db *sql.DB, round int, teams []steward.Team,
	services []steward.Service) (err error) {

	roundRes := make(map[steward.Team]steward.RoundResult)

	for _, team := range teams {

		res := steward.RoundResult{TeamID: team.ID, Round: round}

		def, err := CountDefenceResult(db, round, team.ID, services)
		if err != nil {
			return err
		}

		res.DefenceScore = def * 2

		roundRes[team] = res
	}

	perService := 1.0 / float64(len(services))

	for _, team := range teams {

		cflags, err := steward.GetCapturedFlags(db, round, team.ID)
		if err != nil {
			return err
		}

		for _, flag := range cflags {

			attackedTeam, err := steward.GetTeam(db, flag.TeamID)
			if err != nil {
				return err
			}

			res := roundRes[attackedTeam]
			res.DefenceScore -= perService
			if res.DefenceScore < 0 {
				res.DefenceScore = 0
			}
			roundRes[attackedTeam] = res

			attackRes := roundRes[team]
			attackRes.AttackScore += perService
			roundRes[team] = attackRes
		}
	}

	for _, res := range roundRes {
		_, err := steward.AddRoundResult(db, res)
		if err != nil {
			return err
		}

	}

	return
}