Check license header for .go files.

TEST=unittest
TEST=manually checked repo upload fails if license header is missing in
a go file, and success otherwise.
BUG=chromium:979452

Change-Id: Ic1f81fce7bbba88f799677d72e2ce2f241134f1d
Reviewed-on: https://chromium-review.googlesource.com/1679931
Tested-by: Keigo Oka <oka@chromium.org>
Commit-Ready: Keigo Oka <oka@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 4baf40e..7bcadb2 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -60,7 +60,7 @@
     r"(^|.*[\\\/])[^.]+$",
     # Other
     r".*\.java$", r".*\.mk$", r".*\.am$",
-    r".*\.policy$", r".*\.conf$",
+    r".*\.policy$", r".*\.conf$", r".*\.go$",
 ]
 
 
@@ -455,6 +455,11 @@
 
 def _check_no_long_lines(_project, commit, options=()):
   """Checks there are no lines longer than MAX_LEN in any of the text files."""
+  LONG_LINE_OK_PATHS = [
+      # Go has no line length limit.
+      # https://golang.org/doc/effective_go.html#formatting
+      r".*\.go$",
+  ]
 
   MAX_LEN = 80
   SKIP_REGEXP = re.compile('|'.join([
@@ -464,7 +469,7 @@
   included, excluded = _parse_common_inclusion_options(options)
   files = _filter_files(_get_affected_files(commit),
                         included + COMMON_INCLUDED_PATHS,
-                        excluded + COMMON_EXCLUDED_PATHS)
+                        excluded + COMMON_EXCLUDED_PATHS + LONG_LINE_OK_PATHS)
 
   errors = []
   for afile in files:
@@ -500,8 +505,9 @@
   TAB_OK_PATHS = [
       r".*\.ebuild$",
       r".*\.eclass$",
+      r".*\.go$",
       r".*/[M|m]akefile$",
-      r".*\.mk$"
+      r".*\.mk$",
   ]
 
   included, excluded = _parse_common_inclusion_options(options)
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index 99b695c..feb53c4 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -767,6 +767,12 @@
       self.content_mock.return_value = header
       self.assertEqual(None, pre_upload._check_cros_license('proj', 'sha1'))
 
+  def testNoExcludedGolang(self):
+    """Don't exclude .go files for license checks."""
+    self.file_mock.return_value = ['foo/main.go']
+    self.content_mock.return_value = ('package main\nfunc main() {}')
+    self.assertNotEqual(None, pre_upload._check_cros_license('proj', 'sha1'))
+
   def testIgnoreExcludedPaths(self):
     """Ignores excluded paths for license checks."""
     self.file_mock.return_value = ['foo/OWNERS']