Made match creation use auto-incrementing ID.

This commit is contained in:
Patrick Fairbank
2014-05-26 17:07:55 -07:00
parent 834842f1d2
commit a4d461c795
4 changed files with 16 additions and 17 deletions

View File

@@ -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")

View File

@@ -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)

View File

@@ -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

View File

@@ -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])
}