correctly set the team number for tests

Without this, it's going to pick some random team number on some
computers and fail on others (depending on the network configuration).

Change-Id: I182ed50299170de737812eadee68ff418e6518e6
diff --git a/frc971/control_loops/claw/claw.gyp b/frc971/control_loops/claw/claw.gyp
index e8e3276..a3e556a 100644
--- a/frc971/control_loops/claw/claw.gyp
+++ b/frc971/control_loops/claw/claw.gyp
@@ -49,6 +49,7 @@
         '<(DEPTH)/frc971/control_loops/control_loops.gyp:state_feedback_loop',
         '<(AOS)/common/controls/controls.gyp:control_loop_test',
         '<(DEPTH)/frc971/control_loops/control_loops.gyp:position_sensor_sim',
+        '<(DEPTH)/frc971/control_loops/control_loops.gyp:team_number_test_environment',
       ],
     },
     {
diff --git a/frc971/control_loops/claw/claw_lib_test.cc b/frc971/control_loops/claw/claw_lib_test.cc
index 8d0ac78..ca610d9 100644
--- a/frc971/control_loops/claw/claw_lib_test.cc
+++ b/frc971/control_loops/claw/claw_lib_test.cc
@@ -9,6 +9,7 @@
 #include "frc971/control_loops/claw/claw.h"
 #include "frc971/control_loops/position_sensor_sim.h"
 #include "frc971/constants.h"
+#include "frc971/control_loops/team_number_test_environment.h"
 
 using ::aos::time::Time;
 
@@ -76,7 +77,9 @@
                     ".frc971.control_loops.claw_queue.output",
                     ".frc971.control_loops.claw_queue.status"),
         claw_(&claw_queue_),
-        claw_plant_() {}
+        claw_plant_() {
+    set_team_id(kTeamNumber);
+  }
 
   void VerifyNearGoal() {
     claw_queue_.goal.FetchLatest();
diff --git a/frc971/control_loops/control_loops.gyp b/frc971/control_loops/control_loops.gyp
index 6e882e1..2c0b4d5 100644
--- a/frc971/control_loops/control_loops.gyp
+++ b/frc971/control_loops/control_loops.gyp
@@ -1,6 +1,20 @@
 {
   'targets': [
     {
+      'target_name': 'team_number_test_environment',
+      'type': 'static_library',
+      'sources': [
+        'team_number_test_environment.cc'
+      ],
+      'dependencies': [
+        '<(AOS)/common/network/network.gyp:team_number',
+        '<(EXTERNALS):gtest',
+      ],
+      'export_dependent_settings': [
+        '<(EXTERNALS):gtest',
+      ],
+    },
+    {
       'target_name': 'state_feedback_loop_test',
       'type': 'executable',
       'sources': [
diff --git a/frc971/control_loops/fridge/fridge.gyp b/frc971/control_loops/fridge/fridge.gyp
index ade2d0a..1f3eebb 100644
--- a/frc971/control_loops/fridge/fridge.gyp
+++ b/frc971/control_loops/fridge/fridge.gyp
@@ -50,6 +50,7 @@
         '<(DEPTH)/frc971/control_loops/control_loops.gyp:state_feedback_loop',
         '<(AOS)/common/controls/controls.gyp:control_loop_test',
         '<(DEPTH)/frc971/control_loops/control_loops.gyp:position_sensor_sim',
+        '<(DEPTH)/frc971/control_loops/control_loops.gyp:team_number_test_environment',
       ],
     },
     {
diff --git a/frc971/control_loops/fridge/fridge_lib_test.cc b/frc971/control_loops/fridge/fridge_lib_test.cc
index 98deb8e..120bd2c 100644
--- a/frc971/control_loops/fridge/fridge_lib_test.cc
+++ b/frc971/control_loops/fridge/fridge_lib_test.cc
@@ -9,13 +9,13 @@
 #include "frc971/control_loops/fridge/fridge.q.h"
 #include "frc971/control_loops/fridge/fridge.h"
 #include "frc971/constants.h"
+#include "frc971/control_loops/team_number_test_environment.h"
 
 using ::aos::time::Time;
 
 namespace frc971 {
 namespace control_loops {
 namespace testing {
-
 // Class which simulates the fridge and sends out queue messages with the
 // position.
 class FridgeSimulation {
@@ -131,7 +131,9 @@
                       ".frc971.control_loops.fridge_queue.output",
                       ".frc971.control_loops.fridge_queue.status"),
         fridge_(&fridge_queue_),
-        fridge_plant_() {}
+        fridge_plant_() {
+    set_team_id(kTeamNumber);
+  }
 
   void VerifyNearGoal() {
     fridge_queue_.goal.FetchLatest();
diff --git a/frc971/control_loops/team_number_test_environment.cc b/frc971/control_loops/team_number_test_environment.cc
new file mode 100644
index 0000000..624a119
--- /dev/null
+++ b/frc971/control_loops/team_number_test_environment.cc
@@ -0,0 +1,15 @@
+#include "frc971/control_loops/team_number_test_environment.h"
+
+#include "aos/common/network/team_number.h"
+
+namespace frc971 {
+namespace control_loops {
+namespace testing {
+
+void TeamNumberEnvironment::SetUp() {
+  ::aos::network::OverrideTeamNumber(kTeamNumber);
+}
+
+}  // namespace testing
+}  // namespace control_loops
+}  // namespace frc971
diff --git a/frc971/control_loops/team_number_test_environment.h b/frc971/control_loops/team_number_test_environment.h
new file mode 100644
index 0000000..f0c1a16
--- /dev/null
+++ b/frc971/control_loops/team_number_test_environment.h
@@ -0,0 +1,30 @@
+#ifndef FRC971_CONTROL_LOOPS_TEAM_NUMBER_TEST_ENVIRONMENT_H_
+#define FRC971_CONTROL_LOOPS_TEAM_NUMBER_TEST_ENVIRONMENT_H_
+
+#include "gtest/gtest.h"
+
+namespace frc971 {
+namespace control_loops {
+namespace testing {
+
+// The team number we use for tests.
+static const int kTeamNumber = 1;
+
+// Overrides the team number to kTeamNumber before any test consructors run.
+// This is important for tests which retrieve constants values during
+// construction.
+class TeamNumberEnvironment : public ::testing::Environment {
+ public:
+  void SetUp() override;
+};
+
+// The static variable in a header is intentional. Kind of a hack, undefined
+// order, but that works OK here.
+static ::testing::Environment* const team_number_env =
+    ::testing::AddGlobalTestEnvironment(new TeamNumberEnvironment());
+
+}  // namespace testing
+}  // namespace control_loops
+}  // namespace frc971
+
+#endif  // FRC971_CONTROL_LOOPS_TEAM_NUMBER_TEST_ENVIRONMENT_H_