Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 1 | package requests |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "io" |
| 6 | "net/http" |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 7 | "reflect" |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 8 | "testing" |
| 9 | |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 10 | "github.com/frc971/971-Robot-Code/scouting/db" |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 11 | "github.com/frc971/971-Robot-Code/scouting/scraping" |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 12 | "github.com/frc971/971-Robot-Code/scouting/webserver/requests/debug" |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 13 | "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/error_response" |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 14 | "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 Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 16 | "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 Schrader | acf9623 | 2022-03-01 22:03:30 -0800 | [diff] [blame] | 18 | "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 Schrader | d1c4bef | 2022-02-28 22:51:30 -0800 | [diff] [blame] | 20 | "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" |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 22 | "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting" |
Philipp Schrader | 30005e4 | 2022-03-06 13:53:58 -0800 | [diff] [blame^] | 23 | "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting_response" |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 24 | "github.com/frc971/971-Robot-Code/scouting/webserver/server" |
| 25 | flatbuffers "github.com/google/flatbuffers/go" |
| 26 | ) |
| 27 | |
| 28 | // Validates that an unhandled address results in a 404. |
| 29 | func Test404(t *testing.T) { |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 30 | db := MockDatabase{} |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 31 | scoutingServer := server.NewScoutingServer() |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 32 | HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer) |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 33 | scoutingServer.Start(8080) |
| 34 | defer scoutingServer.Stop() |
| 35 | |
| 36 | resp, err := http.Get("http://localhost:8080/requests/foo") |
| 37 | if err != nil { |
| 38 | t.Fatalf("Failed to get data: %v", err) |
| 39 | } |
| 40 | if resp.StatusCode != http.StatusNotFound { |
| 41 | t.Fatalf("Expected error code 404, but got %d instead", resp.Status) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Validates that we can submit new data scouting data. |
| 46 | func TestSubmitDataScoutingError(t *testing.T) { |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 47 | db := MockDatabase{} |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 48 | scoutingServer := server.NewScoutingServer() |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 49 | HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer) |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 50 | scoutingServer.Start(8080) |
| 51 | defer scoutingServer.Stop() |
| 52 | |
| 53 | resp, err := http.Post("http://localhost:8080/requests/submit/data_scouting", "application/octet-stream", bytes.NewReader([]byte(""))) |
| 54 | if err != nil { |
| 55 | t.Fatalf("Failed to send request: %v", err) |
| 56 | } |
| 57 | if resp.StatusCode != http.StatusBadRequest { |
| 58 | t.Fatal("Unexpected status code. Got", resp.Status) |
| 59 | } |
| 60 | |
| 61 | responseBytes, err := io.ReadAll(resp.Body) |
| 62 | if err != nil { |
| 63 | t.Fatal("Failed to read response bytes:", err) |
| 64 | } |
| 65 | errorResponse := error_response.GetRootAsErrorResponse(responseBytes, 0) |
| 66 | |
| 67 | errorMessage := string(errorResponse.ErrorMessage()) |
| 68 | if errorMessage != "Failed to parse SubmitDataScouting: runtime error: index out of range [3] with length 0" { |
| 69 | t.Fatal("Got mismatched error message:", errorMessage) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Validates that we can submit new data scouting data. |
| 74 | func TestSubmitDataScouting(t *testing.T) { |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 75 | db := MockDatabase{} |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 76 | scoutingServer := server.NewScoutingServer() |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 77 | HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer) |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 78 | scoutingServer.Start(8080) |
| 79 | defer scoutingServer.Stop() |
| 80 | |
| 81 | builder := flatbuffers.NewBuilder(1024) |
| 82 | builder.Finish((&submit_data_scouting.SubmitDataScoutingT{ |
Sabina Leaver | e66c2fc | 2022-02-24 16:56:15 -0800 | [diff] [blame] | 83 | Team: 971, |
| 84 | Match: 1, |
| 85 | MissedShotsAuto: 9971, |
| 86 | UpperGoalAuto: 9971, |
| 87 | LowerGoalAuto: 9971, |
| 88 | MissedShotsTele: 9971, |
| 89 | UpperGoalTele: 9971, |
| 90 | LowerGoalTele: 9971, |
| 91 | DefenseRating: 9971, |
| 92 | Climbing: 9971, |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 93 | }).Pack(builder)) |
| 94 | |
Philipp Schrader | 30005e4 | 2022-03-06 13:53:58 -0800 | [diff] [blame^] | 95 | response, err := debug.SubmitDataScouting("http://localhost:8080", builder.FinishedBytes()) |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 96 | if err != nil { |
Philipp Schrader | 30005e4 | 2022-03-06 13:53:58 -0800 | [diff] [blame^] | 97 | t.Fatal("Failed to submit data scouting: ", err) |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 98 | } |
Philipp Schrader | 30005e4 | 2022-03-06 13:53:58 -0800 | [diff] [blame^] | 99 | |
| 100 | // We get an empty response back. Validate that. |
| 101 | expected := submit_data_scouting_response.SubmitDataScoutingResponseT{} |
| 102 | if !reflect.DeepEqual(expected, *response) { |
| 103 | t.Fatal("Expected ", expected, ", but got:", *response) |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 104 | } |
Philipp Schrader | cdb5cfc | 2022-02-20 14:57:07 -0800 | [diff] [blame] | 105 | } |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 106 | |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 107 | // Validates that we can request the full match list. |
| 108 | func TestRequestAllMatches(t *testing.T) { |
| 109 | db := MockDatabase{ |
| 110 | matches: []db.Match{ |
| 111 | { |
| 112 | MatchNumber: 1, Round: 1, CompLevel: "qual", |
| 113 | R1: 5, R2: 42, R3: 600, B1: 971, B2: 400, B3: 200, |
| 114 | }, |
| 115 | { |
| 116 | MatchNumber: 2, Round: 1, CompLevel: "qual", |
| 117 | R1: 6, R2: 43, R3: 601, B1: 972, B2: 401, B3: 201, |
| 118 | }, |
| 119 | { |
| 120 | MatchNumber: 3, Round: 1, CompLevel: "qual", |
| 121 | R1: 7, R2: 44, R3: 602, B1: 973, B2: 402, B3: 202, |
| 122 | }, |
| 123 | }, |
| 124 | } |
| 125 | scoutingServer := server.NewScoutingServer() |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 126 | HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer) |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 127 | scoutingServer.Start(8080) |
| 128 | defer scoutingServer.Stop() |
| 129 | |
| 130 | builder := flatbuffers.NewBuilder(1024) |
| 131 | builder.Finish((&request_all_matches.RequestAllMatchesT{}).Pack(builder)) |
| 132 | |
| 133 | response, err := debug.RequestAllMatches("http://localhost:8080", builder.FinishedBytes()) |
| 134 | if err != nil { |
| 135 | t.Fatal("Failed to request all matches: ", err) |
| 136 | } |
| 137 | |
| 138 | expected := request_all_matches_response.RequestAllMatchesResponseT{ |
| 139 | MatchList: []*request_all_matches_response.MatchT{ |
| 140 | // MatchNumber, Round, CompLevel |
| 141 | // R1, R2, R3, B1, B2, B3 |
| 142 | { |
| 143 | 1, 1, "qual", |
| 144 | 5, 42, 600, 971, 400, 200, |
| 145 | }, |
| 146 | { |
| 147 | 2, 1, "qual", |
| 148 | 6, 43, 601, 972, 401, 201, |
| 149 | }, |
| 150 | { |
| 151 | 3, 1, "qual", |
| 152 | 7, 44, 602, 973, 402, 202, |
| 153 | }, |
| 154 | }, |
| 155 | } |
| 156 | if len(expected.MatchList) != len(response.MatchList) { |
| 157 | t.Fatal("Expected ", expected, ", but got ", *response) |
| 158 | } |
| 159 | for i, match := range expected.MatchList { |
| 160 | if !reflect.DeepEqual(*match, *response.MatchList[i]) { |
| 161 | t.Fatal("Expected for match", i, ":", *match, ", but got:", *response.MatchList[i]) |
| 162 | } |
| 163 | } |
Philipp Schrader | 30005e4 | 2022-03-06 13:53:58 -0800 | [diff] [blame^] | 164 | |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Philipp Schrader | d1c4bef | 2022-02-28 22:51:30 -0800 | [diff] [blame] | 167 | // Validates that we can request the full match list. |
| 168 | func TestRequestMatchesForTeam(t *testing.T) { |
| 169 | db := MockDatabase{ |
| 170 | matches: []db.Match{ |
| 171 | { |
| 172 | MatchNumber: 1, Round: 1, CompLevel: "qual", |
| 173 | R1: 5, R2: 42, R3: 600, B1: 971, B2: 400, B3: 200, |
| 174 | }, |
| 175 | { |
| 176 | MatchNumber: 2, Round: 1, CompLevel: "qual", |
| 177 | R1: 6, R2: 43, R3: 601, B1: 972, B2: 401, B3: 201, |
| 178 | }, |
| 179 | }, |
| 180 | } |
| 181 | scoutingServer := server.NewScoutingServer() |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 182 | HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer) |
Philipp Schrader | d1c4bef | 2022-02-28 22:51:30 -0800 | [diff] [blame] | 183 | scoutingServer.Start(8080) |
| 184 | defer scoutingServer.Stop() |
| 185 | |
| 186 | builder := flatbuffers.NewBuilder(1024) |
| 187 | builder.Finish((&request_matches_for_team.RequestMatchesForTeamT{ |
| 188 | Team: 971, |
| 189 | }).Pack(builder)) |
| 190 | |
| 191 | response, err := debug.RequestMatchesForTeam("http://localhost:8080", builder.FinishedBytes()) |
| 192 | if err != nil { |
| 193 | t.Fatal("Failed to request all matches: ", err) |
| 194 | } |
| 195 | |
| 196 | expected := request_matches_for_team_response.RequestMatchesForTeamResponseT{ |
| 197 | MatchList: []*request_matches_for_team_response.MatchT{ |
| 198 | // MatchNumber, Round, CompLevel |
| 199 | // R1, R2, R3, B1, B2, B3 |
| 200 | { |
| 201 | 1, 1, "qual", |
| 202 | 5, 42, 600, 971, 400, 200, |
| 203 | }, |
| 204 | }, |
| 205 | } |
| 206 | if len(expected.MatchList) != len(response.MatchList) { |
| 207 | t.Fatal("Expected ", expected, ", but got ", *response) |
| 208 | } |
| 209 | for i, match := range expected.MatchList { |
| 210 | if !reflect.DeepEqual(*match, *response.MatchList[i]) { |
| 211 | t.Fatal("Expected for match", i, ":", *match, ", but got:", *response.MatchList[i]) |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Philipp Schrader | acf9623 | 2022-03-01 22:03:30 -0800 | [diff] [blame] | 216 | // Validates that we can request the stats. |
| 217 | func TestRequestDataScouting(t *testing.T) { |
| 218 | db := MockDatabase{ |
| 219 | stats: []db.Stats{ |
| 220 | { |
| 221 | TeamNumber: 971, MatchNumber: 1, |
| 222 | ShotsMissed: 1, UpperGoalShots: 2, LowerGoalShots: 3, |
| 223 | ShotsMissedAuto: 4, UpperGoalAuto: 5, LowerGoalAuto: 6, |
| 224 | PlayedDefense: 7, Climbing: 8, |
| 225 | }, |
| 226 | { |
| 227 | TeamNumber: 972, MatchNumber: 1, |
| 228 | ShotsMissed: 2, UpperGoalShots: 3, LowerGoalShots: 4, |
| 229 | ShotsMissedAuto: 5, UpperGoalAuto: 6, LowerGoalAuto: 7, |
| 230 | PlayedDefense: 8, Climbing: 9, |
| 231 | }, |
| 232 | }, |
| 233 | } |
| 234 | scoutingServer := server.NewScoutingServer() |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 235 | HandleRequests(&db, scrapeEmtpyMatchList, scoutingServer) |
Philipp Schrader | acf9623 | 2022-03-01 22:03:30 -0800 | [diff] [blame] | 236 | scoutingServer.Start(8080) |
| 237 | defer scoutingServer.Stop() |
| 238 | |
| 239 | builder := flatbuffers.NewBuilder(1024) |
| 240 | builder.Finish((&request_data_scouting.RequestDataScoutingT{}).Pack(builder)) |
| 241 | |
| 242 | response, err := debug.RequestDataScouting("http://localhost:8080", builder.FinishedBytes()) |
| 243 | if err != nil { |
| 244 | t.Fatal("Failed to request all matches: ", err) |
| 245 | } |
| 246 | |
| 247 | expected := request_data_scouting_response.RequestDataScoutingResponseT{ |
| 248 | StatsList: []*request_data_scouting_response.StatsT{ |
| 249 | // Team, Match, |
| 250 | // MissedShotsAuto, UpperGoalAuto, LowerGoalAuto, |
| 251 | // MissedShotsTele, UpperGoalTele, LowerGoalTele, |
| 252 | // DefenseRating, Climbing, |
| 253 | { |
| 254 | 971, 1, |
| 255 | 4, 5, 6, |
| 256 | 1, 2, 3, |
| 257 | 7, 8, |
| 258 | }, |
| 259 | { |
| 260 | 972, 1, |
| 261 | 5, 6, 7, |
| 262 | 2, 3, 4, |
| 263 | 8, 9, |
| 264 | }, |
| 265 | }, |
| 266 | } |
| 267 | if len(expected.StatsList) != len(response.StatsList) { |
| 268 | t.Fatal("Expected ", expected, ", but got ", *response) |
| 269 | } |
| 270 | for i, match := range expected.StatsList { |
| 271 | if !reflect.DeepEqual(*match, *response.StatsList[i]) { |
| 272 | t.Fatal("Expected for stats", i, ":", *match, ", but got:", *response.StatsList[i]) |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 277 | // Validates that we can download the schedule from The Blue Alliance. |
| 278 | func TestRefreshMatchList(t *testing.T) { |
| 279 | scrapeMockSchedule := func(int32, string) ([]scraping.Match, error) { |
| 280 | return []scraping.Match{ |
| 281 | { |
| 282 | CompLevel: "qual", |
| 283 | MatchNumber: 1, |
| 284 | Alliances: scraping.Alliances{ |
| 285 | Red: scraping.Alliance{ |
| 286 | TeamKeys: []string{ |
| 287 | "100", |
| 288 | "200", |
| 289 | "300", |
| 290 | }, |
| 291 | }, |
| 292 | Blue: scraping.Alliance{ |
| 293 | TeamKeys: []string{ |
| 294 | "101", |
| 295 | "201", |
| 296 | "301", |
| 297 | }, |
| 298 | }, |
| 299 | }, |
| 300 | WinningAlliance: "", |
| 301 | EventKey: "", |
| 302 | Time: 0, |
| 303 | PredictedTime: 0, |
| 304 | ActualTime: 0, |
| 305 | PostResultTime: 0, |
| 306 | ScoreBreakdowns: scraping.ScoreBreakdowns{}, |
| 307 | }, |
| 308 | }, nil |
| 309 | } |
| 310 | |
| 311 | database := MockDatabase{} |
| 312 | scoutingServer := server.NewScoutingServer() |
| 313 | HandleRequests(&database, scrapeMockSchedule, scoutingServer) |
| 314 | scoutingServer.Start(8080) |
| 315 | defer scoutingServer.Stop() |
| 316 | |
| 317 | builder := flatbuffers.NewBuilder(1024) |
| 318 | builder.Finish((&refresh_match_list.RefreshMatchListT{}).Pack(builder)) |
| 319 | |
| 320 | response, err := debug.RefreshMatchList("http://localhost:8080", builder.FinishedBytes()) |
| 321 | if err != nil { |
| 322 | t.Fatal("Failed to request all matches: ", err) |
| 323 | } |
| 324 | |
| 325 | // Validate the response. |
| 326 | expected := refresh_match_list_response.RefreshMatchListResponseT{} |
| 327 | if !reflect.DeepEqual(expected, *response) { |
| 328 | t.Fatal("Expected ", expected, ", but got ", *response) |
| 329 | } |
| 330 | |
| 331 | // Make sure that the data made it into the database. |
| 332 | expectedMatches := []db.Match{ |
| 333 | { |
| 334 | MatchNumber: 1, |
| 335 | Round: 1, |
| 336 | CompLevel: "qual", |
| 337 | R1: 100, |
| 338 | R2: 200, |
| 339 | R3: 300, |
| 340 | B1: 101, |
| 341 | B2: 201, |
| 342 | B3: 301, |
| 343 | }, |
| 344 | } |
| 345 | if !reflect.DeepEqual(expectedMatches, database.matches) { |
| 346 | t.Fatal("Expected ", expectedMatches, ", but got ", database.matches) |
| 347 | } |
| 348 | } |
| 349 | |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 350 | // A mocked database we can use for testing. Add functionality to this as |
| 351 | // needed for your tests. |
| 352 | |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 353 | type MockDatabase struct { |
| 354 | matches []db.Match |
Philipp Schrader | acf9623 | 2022-03-01 22:03:30 -0800 | [diff] [blame] | 355 | stats []db.Stats |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 356 | } |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 357 | |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 358 | func (database *MockDatabase) AddToMatch(match db.Match) error { |
| 359 | database.matches = append(database.matches, match) |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 360 | return nil |
| 361 | } |
| 362 | |
Philipp Schrader | 30005e4 | 2022-03-06 13:53:58 -0800 | [diff] [blame^] | 363 | func (database *MockDatabase) AddToStats(stats db.Stats) error { |
| 364 | database.stats = append(database.stats, stats) |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 365 | return nil |
| 366 | } |
| 367 | |
| 368 | func (database *MockDatabase) ReturnMatches() ([]db.Match, error) { |
Philipp Schrader | cbf5c6a | 2022-02-27 23:25:19 -0800 | [diff] [blame] | 369 | return database.matches, nil |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | func (database *MockDatabase) ReturnStats() ([]db.Stats, error) { |
Philipp Schrader | acf9623 | 2022-03-01 22:03:30 -0800 | [diff] [blame] | 373 | return database.stats, nil |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Philipp Schrader | d1c4bef | 2022-02-28 22:51:30 -0800 | [diff] [blame] | 376 | func (database *MockDatabase) QueryMatches(requestedTeam int32) ([]db.Match, error) { |
| 377 | var matches []db.Match |
| 378 | for _, match := range database.matches { |
| 379 | for _, team := range []int32{match.R1, match.R2, match.R3, match.B1, match.B2, match.B3} { |
| 380 | if team == requestedTeam { |
| 381 | matches = append(matches, match) |
| 382 | break |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | return matches, nil |
Philipp Schrader | 8747f1b | 2022-02-23 23:56:22 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | func (database *MockDatabase) QueryStats(int) ([]db.Stats, error) { |
| 390 | return []db.Stats{}, nil |
| 391 | } |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 392 | |
| 393 | // Returns an empty match list from the fake The Blue Alliance scraping. |
| 394 | func scrapeEmtpyMatchList(int32, string) ([]scraping.Match, error) { |
| 395 | return nil, nil |
| 396 | } |