forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam_test.go
86 lines (73 loc) · 1.92 KB
/
team_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetNonexistentTeam(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
team, err := db.GetTeamById(1114)
assert.Nil(t, err)
assert.Nil(t, team)
}
func TestTeamCrud(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
team := Team{Id: 254, Name: "NASA", Nickname: "The Cheesy Poofs", City: "San Jose", StateProv: "CA",
Country: "USA", RookieYear: 1999, RobotName: "Barrage"}
db.CreateTeam(&team)
team2, err := db.GetTeamById(254)
assert.Nil(t, err)
assert.Equal(t, team, *team2)
team.Name = "Updated name"
db.SaveTeam(&team)
team2, err = db.GetTeamById(254)
assert.Nil(t, err)
assert.Equal(t, team.Name, team2.Name)
db.DeleteTeam(&team)
team2, err = db.GetTeamById(254)
assert.Nil(t, err)
assert.Nil(t, team2)
}
func TestTruncateTeams(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
team := Team{Id: 254, Name: "NASA", Nickname: "The Cheesy Poofs", City: "San Jose", StateProv: "CA",
Country: "USA", RookieYear: 1999, RobotName: "Barrage"}
db.CreateTeam(&team)
db.TruncateTeams()
team2, err := db.GetTeamById(254)
assert.Nil(t, err)
assert.Nil(t, team2)
}
func TestGetAllTeams(t *testing.T) {
clearDb()
defer clearDb()
db, err := OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
teams, err := db.GetAllTeams()
assert.Nil(t, err)
assert.Empty(t, teams)
numTeams := 20
for i := 1; i <= numTeams; i++ {
db.CreateTeam(&Team{Id: i, RookieYear: 2014})
}
teams, err = db.GetAllTeams()
assert.Nil(t, err)
assert.Equal(t, numTeams, len(teams))
for i := 0; i < numTeams; i++ {
assert.Equal(t, i+1, teams[i].Id)
}
}