blob: 4dda1434ff744915b452f1c81ef4c1916e3577fb [file] [log] [blame]
Philipp Schradercdb5cfc2022-02-20 14:57:07 -08001package requests
2
3import (
4 "bytes"
5 "io"
6 "net/http"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08007 "reflect"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -08008 "testing"
9
Philipp Schrader8747f1b2022-02-23 23:56:22 -080010 "github.com/frc971/971-Robot-Code/scouting/db"
Philipp Schraderd3fac192022-03-02 20:35:46 -080011 "github.com/frc971/971-Robot-Code/scouting/scraping"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080012 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/debug"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080013 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/error_response"
Philipp Schraderd3fac192022-03-02 20:35:46 -080014 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/refresh_match_list"
15 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/refresh_match_list_response"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080016 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_matches"
17 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_matches_response"
Philipp Schraderacf96232022-03-01 22:03:30 -080018 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_data_scouting"
19 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_data_scouting_response"
Philipp Schraderd1c4bef2022-02-28 22:51:30 -080020 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_matches_for_team"
21 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_matches_for_team_response"
Alex Perry81f96ba2022-03-13 18:26:19 -070022 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_notes_for_team"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080023 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting"
Philipp Schrader30005e42022-03-06 13:53:58 -080024 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting_response"
Alex Perry81f96ba2022-03-13 18:26:19 -070025 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_notes"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080026 "github.com/frc971/971-Robot-Code/scouting/webserver/server"
27 flatbuffers "github.com/google/flatbuffers/go"
28)
29
30// Validates that an unhandled address results in a 404.
31func Test404(t *testing.T) {
Philipp Schrader8747f1b2022-02-23 23:56:22 -080032 db := MockDatabase{}
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080033 scoutingServer := server.NewScoutingServer()
Philipp Schraderd3fac192022-03-02 20:35:46 -080034 HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080035 scoutingServer.Start(8080)
36 defer scoutingServer.Stop()
37
38 resp, err := http.Get("http://localhost:8080/requests/foo")
39 if err != nil {
40 t.Fatalf("Failed to get data: %v", err)
41 }
42 if resp.StatusCode != http.StatusNotFound {
43 t.Fatalf("Expected error code 404, but got %d instead", resp.Status)
44 }
45}
46
47// Validates that we can submit new data scouting data.
48func TestSubmitDataScoutingError(t *testing.T) {
Philipp Schrader8747f1b2022-02-23 23:56:22 -080049 db := MockDatabase{}
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080050 scoutingServer := server.NewScoutingServer()
Philipp Schraderd3fac192022-03-02 20:35:46 -080051 HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080052 scoutingServer.Start(8080)
53 defer scoutingServer.Stop()
54
55 resp, err := http.Post("http://localhost:8080/requests/submit/data_scouting", "application/octet-stream", bytes.NewReader([]byte("")))
56 if err != nil {
57 t.Fatalf("Failed to send request: %v", err)
58 }
59 if resp.StatusCode != http.StatusBadRequest {
60 t.Fatal("Unexpected status code. Got", resp.Status)
61 }
62
63 responseBytes, err := io.ReadAll(resp.Body)
64 if err != nil {
65 t.Fatal("Failed to read response bytes:", err)
66 }
67 errorResponse := error_response.GetRootAsErrorResponse(responseBytes, 0)
68
69 errorMessage := string(errorResponse.ErrorMessage())
70 if errorMessage != "Failed to parse SubmitDataScouting: runtime error: index out of range [3] with length 0" {
71 t.Fatal("Got mismatched error message:", errorMessage)
72 }
73}
74
75// Validates that we can submit new data scouting data.
76func TestSubmitDataScouting(t *testing.T) {
Philipp Schrader8747f1b2022-02-23 23:56:22 -080077 db := MockDatabase{}
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080078 scoutingServer := server.NewScoutingServer()
Philipp Schraderd3fac192022-03-02 20:35:46 -080079 HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080080 scoutingServer.Start(8080)
81 defer scoutingServer.Stop()
82
83 builder := flatbuffers.NewBuilder(1024)
84 builder.Finish((&submit_data_scouting.SubmitDataScoutingT{
Philipp Schraderfa45d742022-03-18 19:29:05 -070085 Team: 971,
86 Match: 1,
Philipp Schrader30b4a682022-04-16 14:36:17 -070087 SetNumber: 8,
Philipp Schrader4535b7e2022-04-08 20:27:00 -070088 CompLevel: "quals",
Philipp Schraderfa45d742022-03-18 19:29:05 -070089 StartingQuadrant: 2,
90 AutoBall1: true,
91 AutoBall2: false,
92 AutoBall3: false,
93 AutoBall4: false,
94 AutoBall5: false,
95 MissedShotsAuto: 9971,
96 UpperGoalAuto: 9971,
97 LowerGoalAuto: 9971,
98 MissedShotsTele: 9971,
99 UpperGoalTele: 9971,
100 LowerGoalTele: 9971,
101 DefenseRating: 9971,
102 DefenseReceivedRating: 4,
103 ClimbLevel: submit_data_scouting.ClimbLevelLow,
104 Comment: "this is a comment",
Philipp Schradercdb5cfc2022-02-20 14:57:07 -0800105 }).Pack(builder))
106
Philipp Schrader30005e42022-03-06 13:53:58 -0800107 response, err := debug.SubmitDataScouting("http://localhost:8080", builder.FinishedBytes())
Philipp Schradercdb5cfc2022-02-20 14:57:07 -0800108 if err != nil {
Philipp Schrader30005e42022-03-06 13:53:58 -0800109 t.Fatal("Failed to submit data scouting: ", err)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -0800110 }
Philipp Schrader30005e42022-03-06 13:53:58 -0800111
112 // We get an empty response back. Validate that.
113 expected := submit_data_scouting_response.SubmitDataScoutingResponseT{}
114 if !reflect.DeepEqual(expected, *response) {
115 t.Fatal("Expected ", expected, ", but got:", *response)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -0800116 }
Philipp Schradercdb5cfc2022-02-20 14:57:07 -0800117}
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800118
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800119// Validates that we can request the full match list.
120func TestRequestAllMatches(t *testing.T) {
121 db := MockDatabase{
122 matches: []db.Match{
123 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700124 MatchNumber: 1, SetNumber: 1, CompLevel: "qual",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800125 R1: 5, R2: 42, R3: 600, B1: 971, B2: 400, B3: 200,
126 },
127 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700128 MatchNumber: 2, SetNumber: 1, CompLevel: "qual",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800129 R1: 6, R2: 43, R3: 601, B1: 972, B2: 401, B3: 201,
130 },
131 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700132 MatchNumber: 3, SetNumber: 1, CompLevel: "qual",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800133 R1: 7, R2: 44, R3: 602, B1: 973, B2: 402, B3: 202,
134 },
135 },
136 }
137 scoutingServer := server.NewScoutingServer()
Philipp Schraderd3fac192022-03-02 20:35:46 -0800138 HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer)
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800139 scoutingServer.Start(8080)
140 defer scoutingServer.Stop()
141
142 builder := flatbuffers.NewBuilder(1024)
143 builder.Finish((&request_all_matches.RequestAllMatchesT{}).Pack(builder))
144
145 response, err := debug.RequestAllMatches("http://localhost:8080", builder.FinishedBytes())
146 if err != nil {
147 t.Fatal("Failed to request all matches: ", err)
148 }
149
150 expected := request_all_matches_response.RequestAllMatchesResponseT{
151 MatchList: []*request_all_matches_response.MatchT{
Philipp Schrader30b4a682022-04-16 14:36:17 -0700152 // MatchNumber, SetNumber, CompLevel
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800153 // R1, R2, R3, B1, B2, B3
154 {
155 1, 1, "qual",
156 5, 42, 600, 971, 400, 200,
157 },
158 {
159 2, 1, "qual",
160 6, 43, 601, 972, 401, 201,
161 },
162 {
163 3, 1, "qual",
164 7, 44, 602, 973, 402, 202,
165 },
166 },
167 }
168 if len(expected.MatchList) != len(response.MatchList) {
169 t.Fatal("Expected ", expected, ", but got ", *response)
170 }
171 for i, match := range expected.MatchList {
172 if !reflect.DeepEqual(*match, *response.MatchList[i]) {
173 t.Fatal("Expected for match", i, ":", *match, ", but got:", *response.MatchList[i])
174 }
175 }
Philipp Schrader30005e42022-03-06 13:53:58 -0800176
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800177}
178
Philipp Schraderd1c4bef2022-02-28 22:51:30 -0800179// Validates that we can request the full match list.
180func TestRequestMatchesForTeam(t *testing.T) {
181 db := MockDatabase{
182 matches: []db.Match{
183 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700184 MatchNumber: 1, SetNumber: 1, CompLevel: "qual",
Philipp Schraderd1c4bef2022-02-28 22:51:30 -0800185 R1: 5, R2: 42, R3: 600, B1: 971, B2: 400, B3: 200,
186 },
187 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700188 MatchNumber: 2, SetNumber: 1, CompLevel: "qual",
Philipp Schraderd1c4bef2022-02-28 22:51:30 -0800189 R1: 6, R2: 43, R3: 601, B1: 972, B2: 401, B3: 201,
190 },
191 },
192 }
193 scoutingServer := server.NewScoutingServer()
Philipp Schraderd3fac192022-03-02 20:35:46 -0800194 HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer)
Philipp Schraderd1c4bef2022-02-28 22:51:30 -0800195 scoutingServer.Start(8080)
196 defer scoutingServer.Stop()
197
198 builder := flatbuffers.NewBuilder(1024)
199 builder.Finish((&request_matches_for_team.RequestMatchesForTeamT{
200 Team: 971,
201 }).Pack(builder))
202
203 response, err := debug.RequestMatchesForTeam("http://localhost:8080", builder.FinishedBytes())
204 if err != nil {
205 t.Fatal("Failed to request all matches: ", err)
206 }
207
208 expected := request_matches_for_team_response.RequestMatchesForTeamResponseT{
209 MatchList: []*request_matches_for_team_response.MatchT{
Philipp Schrader30b4a682022-04-16 14:36:17 -0700210 // MatchNumber, SetNumber, CompLevel
Philipp Schraderd1c4bef2022-02-28 22:51:30 -0800211 // R1, R2, R3, B1, B2, B3
212 {
213 1, 1, "qual",
214 5, 42, 600, 971, 400, 200,
215 },
216 },
217 }
218 if len(expected.MatchList) != len(response.MatchList) {
219 t.Fatal("Expected ", expected, ", but got ", *response)
220 }
221 for i, match := range expected.MatchList {
222 if !reflect.DeepEqual(*match, *response.MatchList[i]) {
223 t.Fatal("Expected for match", i, ":", *match, ", but got:", *response.MatchList[i])
224 }
225 }
226}
227
Philipp Schraderacf96232022-03-01 22:03:30 -0800228// Validates that we can request the stats.
229func TestRequestDataScouting(t *testing.T) {
230 db := MockDatabase{
231 stats: []db.Stats{
232 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700233 TeamNumber: 971, MatchNumber: 1, SetNumber: 2, CompLevel: "quals",
Philipp Schraderfee07e12022-03-17 22:19:47 -0700234 StartingQuadrant: 1,
235 AutoBallPickedUp: [5]bool{true, false, false, false, true},
236 ShotsMissed: 1, UpperGoalShots: 2, LowerGoalShots: 3,
Philipp Schraderacf96232022-03-01 22:03:30 -0800237 ShotsMissedAuto: 4, UpperGoalAuto: 5, LowerGoalAuto: 6,
Philipp Schraderfa45d742022-03-18 19:29:05 -0700238 PlayedDefense: 7, DefenseReceivedScore: 3, Climbing: 2,
239 Comment: "a lovely comment", CollectedBy: "john",
Philipp Schraderacf96232022-03-01 22:03:30 -0800240 },
241 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700242 TeamNumber: 972, MatchNumber: 1, SetNumber: 4, CompLevel: "extra",
Philipp Schraderfee07e12022-03-17 22:19:47 -0700243 StartingQuadrant: 2,
244 AutoBallPickedUp: [5]bool{false, false, true, false, false},
245 ShotsMissed: 2, UpperGoalShots: 3, LowerGoalShots: 4,
Philipp Schraderacf96232022-03-01 22:03:30 -0800246 ShotsMissedAuto: 5, UpperGoalAuto: 6, LowerGoalAuto: 7,
Philipp Schraderfa45d742022-03-18 19:29:05 -0700247 PlayedDefense: 8, DefenseReceivedScore: 1, Climbing: 4,
248 Comment: "another lovely comment", CollectedBy: "andrea",
Philipp Schraderacf96232022-03-01 22:03:30 -0800249 },
250 },
251 }
252 scoutingServer := server.NewScoutingServer()
Philipp Schraderd3fac192022-03-02 20:35:46 -0800253 HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer)
Philipp Schraderacf96232022-03-01 22:03:30 -0800254 scoutingServer.Start(8080)
255 defer scoutingServer.Stop()
256
257 builder := flatbuffers.NewBuilder(1024)
258 builder.Finish((&request_data_scouting.RequestDataScoutingT{}).Pack(builder))
259
260 response, err := debug.RequestDataScouting("http://localhost:8080", builder.FinishedBytes())
261 if err != nil {
262 t.Fatal("Failed to request all matches: ", err)
263 }
264
265 expected := request_data_scouting_response.RequestDataScoutingResponseT{
266 StatsList: []*request_data_scouting_response.StatsT{
Philipp Schraderacf96232022-03-01 22:03:30 -0800267 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700268 Team: 971, Match: 1, SetNumber: 2, CompLevel: "quals",
Philipp Schrader36df73a2022-03-17 23:27:24 -0700269 MissedShotsAuto: 4, UpperGoalAuto: 5, LowerGoalAuto: 6,
270 MissedShotsTele: 1, UpperGoalTele: 2, LowerGoalTele: 3,
Philipp Schraderfa45d742022-03-18 19:29:05 -0700271 DefenseRating: 7,
272 DefenseReceivedRating: 3,
273 CollectedBy: "john",
274 AutoBall1: true, AutoBall2: false, AutoBall3: false,
Philipp Schrader36df73a2022-03-17 23:27:24 -0700275 AutoBall4: false, AutoBall5: true,
276 StartingQuadrant: 1,
277 ClimbLevel: request_data_scouting_response.ClimbLevelFailedWithPlentyOfTime,
Philipp Schraderfa45d742022-03-18 19:29:05 -0700278 Comment: "a lovely comment",
Philipp Schraderacf96232022-03-01 22:03:30 -0800279 },
280 {
Philipp Schrader30b4a682022-04-16 14:36:17 -0700281 Team: 972, Match: 1, SetNumber: 4, CompLevel: "extra",
Philipp Schrader36df73a2022-03-17 23:27:24 -0700282 MissedShotsAuto: 5, UpperGoalAuto: 6, LowerGoalAuto: 7,
283 MissedShotsTele: 2, UpperGoalTele: 3, LowerGoalTele: 4,
Philipp Schraderfa45d742022-03-18 19:29:05 -0700284 DefenseRating: 8,
285 DefenseReceivedRating: 1,
286 CollectedBy: "andrea",
287 AutoBall1: false, AutoBall2: false, AutoBall3: true,
Philipp Schrader36df73a2022-03-17 23:27:24 -0700288 AutoBall4: false, AutoBall5: false,
289 StartingQuadrant: 2,
290 ClimbLevel: request_data_scouting_response.ClimbLevelMedium,
Philipp Schraderfa45d742022-03-18 19:29:05 -0700291 Comment: "another lovely comment",
Philipp Schraderacf96232022-03-01 22:03:30 -0800292 },
293 },
294 }
295 if len(expected.StatsList) != len(response.StatsList) {
296 t.Fatal("Expected ", expected, ", but got ", *response)
297 }
298 for i, match := range expected.StatsList {
299 if !reflect.DeepEqual(*match, *response.StatsList[i]) {
300 t.Fatal("Expected for stats", i, ":", *match, ", but got:", *response.StatsList[i])
301 }
302 }
303}
304
Alex Perry81f96ba2022-03-13 18:26:19 -0700305func TestSubmitNotes(t *testing.T) {
306 database := MockDatabase{}
307 scoutingServer := server.NewScoutingServer()
308 HandleRequests(&database, scrapeEmtpyMatchList, scoutingServer)
309 scoutingServer.Start(8080)
310 defer scoutingServer.Stop()
311
312 builder := flatbuffers.NewBuilder(1024)
313 builder.Finish((&submit_notes.SubmitNotesT{
314 Team: 971,
315 Notes: "Notes",
316 }).Pack(builder))
317
318 _, err := debug.SubmitNotes("http://localhost:8080", builder.FinishedBytes())
319 if err != nil {
320 t.Fatal("Failed to submit notes: ", err)
321 }
322
323 expected := []db.NotesData{
324 {TeamNumber: 971, Notes: []string{"Notes"}},
325 }
326
327 if !reflect.DeepEqual(database.notes, expected) {
328 t.Fatal("Submitted notes did not match", expected, database.notes)
329 }
330}
331
332func TestRequestNotes(t *testing.T) {
333 database := MockDatabase{
334 notes: []db.NotesData{{
335 TeamNumber: 971,
336 Notes: []string{"Notes"},
337 }},
338 }
339 scoutingServer := server.NewScoutingServer()
340 HandleRequests(&database, scrapeEmtpyMatchList, scoutingServer)
341 scoutingServer.Start(8080)
342 defer scoutingServer.Stop()
343
344 builder := flatbuffers.NewBuilder(1024)
345 builder.Finish((&request_notes_for_team.RequestNotesForTeamT{
346 Team: 971,
347 }).Pack(builder))
348 response, err := debug.RequestNotes("http://localhost:8080", builder.FinishedBytes())
349 if err != nil {
350 t.Fatal("Failed to submit notes: ", err)
351 }
352
353 if response.Notes[0].Data != "Notes" {
354 t.Fatal("requested notes did not match", response)
355 }
356}
357
Philipp Schraderd3fac192022-03-02 20:35:46 -0800358// Validates that we can download the schedule from The Blue Alliance.
359func TestRefreshMatchList(t *testing.T) {
360 scrapeMockSchedule := func(int32, string) ([]scraping.Match, error) {
361 return []scraping.Match{
362 {
363 CompLevel: "qual",
364 MatchNumber: 1,
Philipp Schrader45befdd2022-04-08 19:12:44 -0700365 SetNumber: 2,
Philipp Schraderd3fac192022-03-02 20:35:46 -0800366 Alliances: scraping.Alliances{
367 Red: scraping.Alliance{
368 TeamKeys: []string{
369 "100",
370 "200",
371 "300",
372 },
373 },
374 Blue: scraping.Alliance{
375 TeamKeys: []string{
376 "101",
377 "201",
378 "301",
379 },
380 },
381 },
382 WinningAlliance: "",
383 EventKey: "",
384 Time: 0,
385 PredictedTime: 0,
386 ActualTime: 0,
387 PostResultTime: 0,
388 ScoreBreakdowns: scraping.ScoreBreakdowns{},
389 },
390 }, nil
391 }
392
393 database := MockDatabase{}
394 scoutingServer := server.NewScoutingServer()
395 HandleRequests(&database, scrapeMockSchedule, scoutingServer)
396 scoutingServer.Start(8080)
397 defer scoutingServer.Stop()
398
399 builder := flatbuffers.NewBuilder(1024)
400 builder.Finish((&refresh_match_list.RefreshMatchListT{}).Pack(builder))
401
402 response, err := debug.RefreshMatchList("http://localhost:8080", builder.FinishedBytes())
403 if err != nil {
404 t.Fatal("Failed to request all matches: ", err)
405 }
406
407 // Validate the response.
408 expected := refresh_match_list_response.RefreshMatchListResponseT{}
409 if !reflect.DeepEqual(expected, *response) {
410 t.Fatal("Expected ", expected, ", but got ", *response)
411 }
412
413 // Make sure that the data made it into the database.
414 expectedMatches := []db.Match{
415 {
416 MatchNumber: 1,
Philipp Schrader30b4a682022-04-16 14:36:17 -0700417 SetNumber: 2,
Philipp Schraderd3fac192022-03-02 20:35:46 -0800418 CompLevel: "qual",
419 R1: 100,
420 R2: 200,
421 R3: 300,
422 B1: 101,
423 B2: 201,
424 B3: 301,
425 },
426 }
427 if !reflect.DeepEqual(expectedMatches, database.matches) {
428 t.Fatal("Expected ", expectedMatches, ", but got ", database.matches)
429 }
430}
431
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800432// A mocked database we can use for testing. Add functionality to this as
433// needed for your tests.
434
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800435type MockDatabase struct {
436 matches []db.Match
Philipp Schraderacf96232022-03-01 22:03:30 -0800437 stats []db.Stats
Alex Perry81f96ba2022-03-13 18:26:19 -0700438 notes []db.NotesData
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800439}
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800440
Philipp Schraderd3fac192022-03-02 20:35:46 -0800441func (database *MockDatabase) AddToMatch(match db.Match) error {
442 database.matches = append(database.matches, match)
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800443 return nil
444}
445
Philipp Schrader30005e42022-03-06 13:53:58 -0800446func (database *MockDatabase) AddToStats(stats db.Stats) error {
447 database.stats = append(database.stats, stats)
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800448 return nil
449}
450
451func (database *MockDatabase) ReturnMatches() ([]db.Match, error) {
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800452 return database.matches, nil
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800453}
454
455func (database *MockDatabase) ReturnStats() ([]db.Stats, error) {
Philipp Schraderacf96232022-03-01 22:03:30 -0800456 return database.stats, nil
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800457}
458
Philipp Schraderd1c4bef2022-02-28 22:51:30 -0800459func (database *MockDatabase) QueryMatches(requestedTeam int32) ([]db.Match, error) {
460 var matches []db.Match
461 for _, match := range database.matches {
462 for _, team := range []int32{match.R1, match.R2, match.R3, match.B1, match.B2, match.B3} {
463 if team == requestedTeam {
464 matches = append(matches, match)
465 break
466 }
467 }
468 }
469 return matches, nil
Philipp Schrader8747f1b2022-02-23 23:56:22 -0800470}
471
472func (database *MockDatabase) QueryStats(int) ([]db.Stats, error) {
473 return []db.Stats{}, nil
474}
Philipp Schraderd3fac192022-03-02 20:35:46 -0800475
Alex Perry81f96ba2022-03-13 18:26:19 -0700476func (database *MockDatabase) QueryNotes(requestedTeam int32) (db.NotesData, error) {
477 var results []string
478 for _, data := range database.notes {
479 if data.TeamNumber == requestedTeam {
480 results = append(results, data.Notes[0])
481 }
482 }
483 return db.NotesData{TeamNumber: requestedTeam, Notes: results}, nil
484}
485
486func (database *MockDatabase) AddNotes(data db.NotesData) error {
487 database.notes = append(database.notes, data)
488 return nil
489}
490
Philipp Schraderd3fac192022-03-02 20:35:46 -0800491// Returns an empty match list from the fake The Blue Alliance scraping.
492func scrapeEmtpyMatchList(int32, string) ([]scraping.Match, error) {
493 return nil, nil
494}