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

	db, err := openDB()

	defer db.Close()

	team_id := 10
	advisory_text := "advisory text"
	score := 40
	amount := 5

	var ids []int

	for i := 0; i < amount; i++ {
		entry_text := fmt.Sprintf("%s%d", advisory_text, i)
		id, err := steward.AddAdvisory(db.db, team_id, entry_text)
		if err != nil {
			log.Fatalln("Add advisory failed:", err)
		}
		ids = append(ids, id)
		steward.ReviewAdvisory(db.db, id, score)
	}

	team_score, err := steward.GetAdvisoryScore(db.db, team_id)
	if err != nil {
		log.Fatalln("Get team advisory score fail:", err)
	}

	if team_score != score*amount {
		log.Fatalf("Team advisory score (%d) not equal of sum of "+
			"entries (%d)", team_score, score*amount)
	}
}
Пример #2
0
func collectTeamResult(db *sql.DB, team steward.Team,
	services []steward.Service) (tr TeamResult, err error) {

	tr.ID = team.ID
	tr.Name = team.Name

	rr, err := steward.GetLastResult(db, team.ID)
	if err != nil {
		// At game start, no result exist
		rr = steward.RoundResult{AttackScore: 0, DefenceScore: 0}
	}

	tr.Attack = rr.AttackScore
	tr.Defence = rr.DefenceScore

	advisory, err := steward.GetAdvisoryScore(db, team.ID)
	if err != nil {
		tr.Advisory = 0
	} else {
		tr.Advisory = advisory
	}

	round, err := steward.CurrentRound(db)
	if err != nil {
		// At game start, no round exist
		return tr, nil
	}

	for _, svc := range services {
		s := steward.Status{round.ID, team.ID, svc.ID, -1}
		state, err := steward.GetState(db, s)
		if err != nil {
			// Try to get status from previous round
			s.Round--
			state, err = steward.GetState(db, s)
			if err != nil {
				state = steward.StatusDown
			}
		}

		tr.Status = append(tr.Status, state)
	}

	return
}