Files
cheesy-arena-lite/model/match_result_test.go

65 lines
1.7 KiB
Go
Raw Normal View History

2014-05-26 20:16:36 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
package model
2014-05-26 20:16:36 -07:00
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetNonexistentMatchResult(t *testing.T) {
db := setupTestDb(t)
2014-05-26 20:16:36 -07:00
match, err := db.GetMatchResultForMatch(1114)
assert.Nil(t, err)
assert.Nil(t, match)
}
func TestMatchResultCrud(t *testing.T) {
db := setupTestDb(t)
2014-05-26 20:16:36 -07:00
matchResult := BuildTestMatchResult(254, 5)
db.CreateMatchResult(matchResult)
2014-05-26 20:16:36 -07:00
matchResult2, err := db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Equal(t, matchResult, matchResult2)
2014-05-26 20:16:36 -07:00
db.SaveMatchResult(matchResult)
2014-05-26 20:16:36 -07:00
matchResult2, err = db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Equal(t, matchResult, matchResult2)
2014-05-26 20:16:36 -07:00
db.DeleteMatchResult(matchResult)
2014-05-26 20:16:36 -07:00
matchResult2, err = db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Nil(t, matchResult2)
}
func TestTruncateMatchResults(t *testing.T) {
db := setupTestDb(t)
2014-05-26 20:16:36 -07:00
matchResult := BuildTestMatchResult(254, 1)
db.CreateMatchResult(matchResult)
2014-05-26 20:16:36 -07:00
db.TruncateMatchResults()
matchResult2, err := db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Nil(t, matchResult2)
}
func TestGetMatchResultForMatch(t *testing.T) {
db := setupTestDb(t)
2014-05-26 20:16:36 -07:00
matchResult := BuildTestMatchResult(254, 2)
db.CreateMatchResult(matchResult)
matchResult2 := BuildTestMatchResult(254, 5)
db.CreateMatchResult(matchResult2)
matchResult3 := BuildTestMatchResult(254, 4)
db.CreateMatchResult(matchResult3)
2014-05-26 20:16:36 -07:00
// Should return the match result with the highest play number (i.e. the most recent).
matchResult4, err := db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Equal(t, matchResult2, matchResult4)
2014-05-26 20:16:36 -07:00
}