gopls/internal/hooks: improve license file test

Now that we're only including licenses for the things gopls actually
depends on, we don't need to access the network on the trybots, and we
can get rid of the go.sum check that adds a step to the release process.

Change-Id: I3d38334ea3a9c904dfa125157c7b0468a0699b54
Reviewed-on: https://go-review.googlesource.com/c/tools/+/286436
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/gopls/internal/hooks/gen-licenses.sh b/gopls/internal/hooks/gen-licenses.sh
index f0756ff..7d6bab7 100755
--- a/gopls/internal/hooks/gen-licenses.sh
+++ b/gopls/internal/hooks/gen-licenses.sh
@@ -6,13 +6,10 @@
 
 set -o pipefail
 
+output=$1
 tempfile=$(mktemp)
 cd $(dirname $0)
 
-modhash=$(sha256sum ../../go.sum | awk '{print $1}')
-# Make sure we have the code for all the modules we depend on.
-go mod download
-
 cat > $tempfile <<END
 // Copyright 2020 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -37,9 +34,5 @@
   echo >> $tempfile
 done
 
-cat >> $tempfile << END
-\`
-
-const licensesGeneratedFrom = "$modhash"
-END
-mv $tempfile licenses.go
\ No newline at end of file
+echo "\`" >> $tempfile
+mv $tempfile $output
\ No newline at end of file
diff --git a/gopls/internal/hooks/licenses.go b/gopls/internal/hooks/licenses.go
index 028c90e..a159465 100644
--- a/gopls/internal/hooks/licenses.go
+++ b/gopls/internal/hooks/licenses.go
@@ -167,5 +167,3 @@
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 `
-
-const licensesGeneratedFrom = "029a0f934a7bad22a7d47185055bc554b1ea23ce427351caa87d9a088fcfba4e"
diff --git a/gopls/internal/hooks/licenses_test.go b/gopls/internal/hooks/licenses_test.go
index 28b1149..d2c4e34 100644
--- a/gopls/internal/hooks/licenses_test.go
+++ b/gopls/internal/hooks/licenses_test.go
@@ -5,19 +5,36 @@
 package hooks
 
 import (
-	"crypto/sha256"
-	"encoding/hex"
+	"bytes"
 	"io/ioutil"
+	"os/exec"
+	"runtime"
 	"testing"
 )
 
 func TestLicenses(t *testing.T) {
-	sumBytes, err := ioutil.ReadFile("../../go.sum")
+	if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
+		t.Skip("generating licenses only works on Unixes")
+	}
+	tmp, err := ioutil.TempFile("", "")
 	if err != nil {
 		t.Fatal(err)
 	}
-	sumSum := sha256.Sum256(sumBytes)
-	if licensesGeneratedFrom != hex.EncodeToString(sumSum[:]) {
+	tmp.Close()
+
+	if out, err := exec.Command("./gen-licenses.sh", tmp.Name()).CombinedOutput(); err != nil {
+		t.Fatalf("generating licenses failed: %q, %v", out, err)
+	}
+
+	got, err := ioutil.ReadFile(tmp.Name())
+	if err != nil {
+		t.Fatal(err)
+	}
+	want, err := ioutil.ReadFile("licenses.go")
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !bytes.Equal(got, want) {
 		t.Error("combined license text needs updating. Run: `go generate ./internal/hooks` from the gopls module.")
 	}
 }