maintner/godata: skip TestGerritHashtags when TEST_GERRIT_AUTH unset
TestGerritHashtags is documented to be off by default unless
environment variable TEST_GERRIT_AUTH is set to "user:token",
or we're running in the prod project.
However, the previous code never skipped TestGerritHashtags,
even when TEST_GERRIT_AUTH wasn't set, because strings.SplitN
returns a slice with length 1 when the input string is empty.
This change fixes that.
Updates golang/go#28318
Change-Id: Ib2f113dbc3ccfd933f9944fe8efa105ff3ba5057
Reviewed-on: https://go-review.googlesource.com/c/153442
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/maintner/godata/godata_test.go b/maintner/godata/godata_test.go
index edd18b0..59c11e2 100644
--- a/maintner/godata/godata_test.go
+++ b/maintner/godata/godata_test.go
@@ -7,6 +7,7 @@
import (
"bytes"
"context"
+ "errors"
"fmt"
"os"
"sort"
@@ -289,7 +290,11 @@
}
}
if slurp == "" {
- slurp = os.Getenv("TEST_GERRIT_AUTH")
+ var ok bool
+ slurp, ok = os.LookupEnv("TEST_GERRIT_AUTH")
+ if !ok {
+ return "", "", errors.New("environment variable TEST_GERRIT_AUTH is not set")
+ }
}
f := strings.SplitN(strings.TrimSpace(slurp), ":", 2)
if len(f) == 1 {