mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Refactor partner API clients into separate package.
This commit is contained in:
@@ -5,21 +5,14 @@ package model
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testDbPath = "test.db"
|
||||
|
||||
func TestOpenUnreachableDatabase(t *testing.T) {
|
||||
_, err := OpenDatabase("..", "nonexistentdir/test.db")
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func setupTestDb(t *testing.T) *Database {
|
||||
os.Remove(filepath.Join("..", testDbPath))
|
||||
db, err := OpenDatabase("..", testDbPath)
|
||||
assert.Nil(t, err)
|
||||
return db
|
||||
return SetupTestDb(t, "model", "..")
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright 2017 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Data for use in tests in this package and others.
|
||||
|
||||
package model
|
||||
|
||||
import "github.com/Team254/cheesy-arena/game"
|
||||
|
||||
func BuildTestMatchResult(matchId int, playNumber int) *MatchResult {
|
||||
matchResult := &MatchResult{MatchId: matchId, PlayNumber: playNumber, MatchType: "qualification"}
|
||||
matchResult.RedScore = game.TestScore1()
|
||||
matchResult.BlueScore = game.TestScore2()
|
||||
matchResult.RedCards = map[string]string{"1868": "yellow"}
|
||||
matchResult.BlueCards = map[string]string{}
|
||||
return matchResult
|
||||
}
|
||||
|
||||
func BuildTestAlliances(db *Database) {
|
||||
db.CreateAllianceTeam(&AllianceTeam{0, 2, 0, 1718})
|
||||
db.CreateAllianceTeam(&AllianceTeam{0, 1, 3, 74})
|
||||
db.CreateAllianceTeam(&AllianceTeam{0, 1, 1, 469})
|
||||
db.CreateAllianceTeam(&AllianceTeam{0, 1, 0, 254})
|
||||
db.CreateAllianceTeam(&AllianceTeam{0, 1, 2, 2848})
|
||||
db.CreateAllianceTeam(&AllianceTeam{0, 2, 1, 2451})
|
||||
}
|
||||
43
model/test_helpers.go
Normal file
43
model/test_helpers.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2017 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Helper methods for use in tests in this package and others.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena/game"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testDbPath = "%s_test.db"
|
||||
|
||||
func SetupTestDb(t *testing.T, uniqueName, baseDir string) *Database {
|
||||
dbPath := fmt.Sprintf(testDbPath, uniqueName)
|
||||
os.Remove(filepath.Join(baseDir, dbPath))
|
||||
database, err := OpenDatabase(baseDir, dbPath)
|
||||
assert.Nil(t, err)
|
||||
return database
|
||||
}
|
||||
|
||||
func BuildTestMatchResult(matchId int, playNumber int) *MatchResult {
|
||||
matchResult := &MatchResult{MatchId: matchId, PlayNumber: playNumber, MatchType: "qualification"}
|
||||
matchResult.RedScore = game.TestScore1()
|
||||
matchResult.BlueScore = game.TestScore2()
|
||||
matchResult.RedCards = map[string]string{"1868": "yellow"}
|
||||
matchResult.BlueCards = map[string]string{}
|
||||
return matchResult
|
||||
}
|
||||
|
||||
func BuildTestAlliances(database *Database) {
|
||||
database.CreateAllianceTeam(&AllianceTeam{0, 2, 0, 1718})
|
||||
database.CreateAllianceTeam(&AllianceTeam{0, 1, 3, 74})
|
||||
database.CreateAllianceTeam(&AllianceTeam{0, 1, 1, 469})
|
||||
database.CreateAllianceTeam(&AllianceTeam{0, 1, 0, 254})
|
||||
database.CreateAllianceTeam(&AllianceTeam{0, 1, 2, 2848})
|
||||
database.CreateAllianceTeam(&AllianceTeam{0, 2, 1, 2451})
|
||||
}
|
||||
Reference in New Issue
Block a user