Allow users to re-import the match list in the scouting app
We currently append the match list to the existing data in the table.
This patch makes it so the entries are replaced instead of duplicated.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I86fdc49f8f01861bd0b35da8042a28e03ee9c0f0
diff --git a/scouting/db/db_test.go b/scouting/db/db_test.go
index 09b6eb7..290f451 100644
--- a/scouting/db/db_test.go
+++ b/scouting/db/db_test.go
@@ -397,6 +397,49 @@
}
}
+func TestOverwriteNewMatchData(t *testing.T) {
+ fixture := createDatabase(t)
+ defer fixture.TearDown()
+
+ testDatabase := []Match{
+ Match{
+ MatchNumber: 1, Round: 1, CompLevel: "quals",
+ R1: 251, R2: 169, R3: 286, B1: 253, B2: 538, B3: 149,
+ },
+ Match{
+ MatchNumber: 2, Round: 1, CompLevel: "quals",
+ R1: 198, R2: 135, R3: 777, B1: 999, B2: 434, B3: 698,
+ },
+ Match{
+ MatchNumber: 1, Round: 1, CompLevel: "quals",
+ R1: 147, R2: 421, R3: 538, B1: 126, B2: 448, B3: 262,
+ },
+ }
+
+ for i := 0; i < len(testDatabase); i++ {
+ err := fixture.db.AddToMatch(testDatabase[i])
+ check(t, err, fmt.Sprint("Failed to add match", i))
+ }
+
+ correct := []Match{
+ Match{
+ MatchNumber: 2, Round: 1, CompLevel: "quals",
+ R1: 198, R2: 135, R3: 777, B1: 999, B2: 434, B3: 698,
+ },
+ Match{
+ MatchNumber: 1, Round: 1, CompLevel: "quals",
+ R1: 147, R2: 421, R3: 538, B1: 126, B2: 448, B3: 262,
+ },
+ }
+
+ got, err := fixture.db.ReturnMatches()
+ check(t, err, "Failed to get match list")
+
+ if !reflect.DeepEqual(correct, got) {
+ t.Fatalf("Got %#v,\nbut expected %#v.", got, correct)
+ }
+}
+
func TestReturnRankingsDB(t *testing.T) {
fixture := createDatabase(t)
defer fixture.TearDown()