os: don't log the entire environment in tests

TestEnvironConsistency logs the values of all the environment variables,
which can be quite large on some environments. This change limits the
output to just the variables that caused the test to fail.

Change-Id: Ie796b57ac2cc845093c73298058b720df344fa28
Reviewed-on: https://go-review.googlesource.com/c/go/+/650581
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
qmuntal 2025-02-20 18:31:42 +01:00 committed by Quim Muntal
parent e1f02e9ae5
commit 64d82cd72c

View file

@ -189,17 +189,13 @@ func TestEnvironConsistency(t *testing.T) {
k := kv[:i]
v := kv[i+1:]
v2, ok := LookupEnv(k)
if ok && v == v2 {
t.Logf("LookupEnv(%q) = %q, %t", k, v2, ok)
} else {
if !ok || v != v2 {
t.Errorf("Environ contains %q, but LookupEnv(%q) = %q, %t", kv, k, v2, ok)
}
// Since k=v is already present in the environment,
// setting it should be a no-op.
if err := Setenv(k, v); err == nil {
t.Logf("Setenv(%q, %q)", k, v)
} else {
if err := Setenv(k, v); err != nil {
t.Errorf("Environ contains %q, but SetEnv(%q, %q) = %q", kv, k, v, err)
}
}