From a4d461c795d722cbdd764382ecc5c44b0ef1d106 Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Mon, 26 May 2014 17:07:55 -0700 Subject: [PATCH] Made match creation use auto-incrementing ID. --- database.go | 2 +- match_test.go | 18 +++++++++--------- schedule.go | 1 - schedule_test.go | 12 ++++++------ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/database.go b/database.go index 3657b02..32dd9ee 100644 --- a/database.go +++ b/database.go @@ -59,7 +59,7 @@ func (database *Database) mapTables() { database.eventSettingsMap.AddTableWithName(EventSettings{}, "event_settings").SetKeys(false, "Id") database.matchMap = modl.NewDbMap(database.db, dialect) - database.matchMap.AddTableWithName(Match{}, "matches").SetKeys(false, "Id") + database.matchMap.AddTableWithName(Match{}, "matches").SetKeys(true, "Id") database.teamMap = modl.NewDbMap(database.db, dialect) database.teamMap.AddTableWithName(Team{}, "teams").SetKeys(false, "Id") diff --git a/match_test.go b/match_test.go index 8b9e71d..e57ef58 100644 --- a/match_test.go +++ b/match_test.go @@ -28,21 +28,21 @@ func TestMatchCrud(t *testing.T) { assert.Nil(t, err) defer db.Close() - match := Match{254, "qualification", "254", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, + match := Match{0, "qualification", "254", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, false, 6, false, "", time.Now().UTC()} db.CreateMatch(&match) - match2, err := db.GetMatchById(254) + match2, err := db.GetMatchById(1) assert.Nil(t, err) assert.Equal(t, match, *match2) match.Status = "started" db.SaveMatch(&match) - match2, err = db.GetMatchById(254) + match2, err = db.GetMatchById(1) assert.Nil(t, err) assert.Equal(t, match.Status, match2.Status) db.DeleteMatch(&match) - match2, err = db.GetMatchById(254) + match2, err = db.GetMatchById(1) assert.Nil(t, err) assert.Nil(t, match2) } @@ -54,11 +54,11 @@ func TestTruncateMatches(t *testing.T) { assert.Nil(t, err) defer db.Close() - match := Match{254, "qualification", "254", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, + match := Match{0, "qualification", "254", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, false, 6, false, "", time.Now().UTC()} db.CreateMatch(&match) db.TruncateMatches() - match2, err := db.GetMatchById(254) + match2, err := db.GetMatchById(1) assert.Nil(t, err) assert.Nil(t, match2) } @@ -70,13 +70,13 @@ func TestGetMatchesByType(t *testing.T) { assert.Nil(t, err) defer db.Close() - match := Match{1, "qualification", "1", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, + match := Match{0, "qualification", "1", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, false, 6, false, "", time.Now().UTC()} db.CreateMatch(&match) - match2 := Match{2, "practice", "1", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, + match2 := Match{0, "practice", "1", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, false, 6, false, "", time.Now().UTC()} db.CreateMatch(&match2) - match3 := Match{3, "practice", "2", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, + match3 := Match{0, "practice", "2", time.Now().UTC(), 1, false, 2, false, 3, false, 4, false, 5, false, 6, false, "", time.Now().UTC()} db.CreateMatch(&match3) diff --git a/schedule.go b/schedule.go index 024f873..9334c87 100644 --- a/schedule.go +++ b/schedule.go @@ -57,7 +57,6 @@ func BuildRandomSchedule(teams []Team, scheduleBlocks []ScheduleBlock, matchType teamShuffle := rand.Perm(numTeams) matches := make([]Match, numMatches) for i, anonMatch := range anonSchedule { - matches[i].Id = i + 1 matches[i].Type = matchType matches[i].DisplayName = strconv.Itoa(i + 1) matches[i].Red1 = teams[teamShuffle[anonMatch[0]-1]].Id diff --git a/schedule_test.go b/schedule_test.go index a56778d..af83dbe 100644 --- a/schedule_test.go +++ b/schedule_test.go @@ -55,17 +55,17 @@ func TestScheduleTeams(t *testing.T) { scheduleBlocks := []ScheduleBlock{{time.Unix(0, 0).UTC(), 6, 60}} matches, err := BuildRandomSchedule(teams, scheduleBlocks, "test") assert.Nil(t, err) - assert.Equal(t, Match{1, "test", "1", time.Unix(0, 0).UTC(), 107, false, 102, false, 117, false, 115, + assert.Equal(t, Match{0, "test", "1", time.Unix(0, 0).UTC(), 107, false, 102, false, 117, false, 115, false, 106, false, 116, false, "", time.Unix(0, 0).UTC()}, matches[0]) - assert.Equal(t, Match{2, "test", "2", time.Unix(60, 0).UTC(), 109, false, 113, false, 104, false, 108, + assert.Equal(t, Match{0, "test", "2", time.Unix(60, 0).UTC(), 109, false, 113, false, 104, false, 108, false, 112, false, 118, false, "", time.Unix(0, 0).UTC()}, matches[1]) - assert.Equal(t, Match{3, "test", "3", time.Unix(120, 0).UTC(), 103, false, 111, false, 105, false, 114, + assert.Equal(t, Match{0, "test", "3", time.Unix(120, 0).UTC(), 103, false, 111, false, 105, false, 114, false, 101, false, 110, false, "", time.Unix(0, 0).UTC()}, matches[2]) - assert.Equal(t, Match{4, "test", "4", time.Unix(180, 0).UTC(), 102, false, 104, false, 115, false, 117, + assert.Equal(t, Match{0, "test", "4", time.Unix(180, 0).UTC(), 102, false, 104, false, 115, false, 117, false, 118, false, 113, false, "", time.Unix(0, 0).UTC()}, matches[3]) - assert.Equal(t, Match{5, "test", "5", time.Unix(240, 0).UTC(), 108, false, 114, false, 106, false, 103, + assert.Equal(t, Match{0, "test", "5", time.Unix(240, 0).UTC(), 108, false, 114, false, 106, false, 103, false, 101, false, 116, false, "", time.Unix(0, 0).UTC()}, matches[4]) - assert.Equal(t, Match{6, "test", "6", time.Unix(300, 0).UTC(), 109, false, 112, false, 111, false, 110, + assert.Equal(t, Match{0, "test", "6", time.Unix(300, 0).UTC(), 109, false, 112, false, 111, false, 110, false, 107, false, 105, false, "", time.Unix(0, 0).UTC()}, matches[5]) }