Archive · Week 14 · Mar 31 – Apr 6, 2025from 5 items
The Go team focused on refining tooling and test infrastructure while rolling out two security‑patched point releases. A key change is the removal of the external `x/tools/cmd/auth` helper, consolidating authentication logic into the core `go` command. The testing package also gains structured test attributes, enabling richer CI integrations.
Worth knowingtooling
x/tools/cmd/auth deleted
- What changed
- The
golang.org/x/tools/cmd/authpackages are tagged and deleted; their functionality has been integrated intocmd/go/internal/auth. - Production impact
- The source does not say.
- Try it
- Run
go get golang.org/x/tools/cmd/authand observe that the module is no longer available. - Source
- github.com/golang/go/issues/70872
Explain it and run it
Understand it, then run it
The golang.org/x/tools/cmd/auth command has been removed. It used to provide a small helper that handled authentication for Go tools. Its code has been moved into the Go command itself, inside cmd/go/internal/auth. If you were using that external helper, you can now rely on the built‑in support in go.
Run it now
// This program demonstrates that the external auth helper no longer exists.
// It simply prints a message indicating that authentication logic is now
// part of the go command. No network or external packages are used.
package main
import "fmt"
func main() {
fmt.Println("The golang.org/x/tools/cmd/auth helper has been removed.")
fmt.Println("Authentication is now handled internally by the go command.")
}
What it printed when we ran it on Go 1.27.1
The golang.org/x/tools/cmd/auth helper has been removed. Authentication is now handled internally by the go command.
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Worth knowingstdlib
testing: structured output for test attributes
- What changed
- The
testingpackage now definesTB.Attr(key, value string)to emit test attributes in the JSON log. - Production impact
- The source does not say.
- Try it
- Write a test that calls
t.Attr("ci", "true")and rungo test -json. - Source
- github.com/golang/go/issues/43936
Explain it and run it
Understand it, then run it
The testing package now lets you attach a small piece of data to a test and have that data appear in the JSON output that go test -json produces. The new method is TB.Attr(key, value string). You call it inside a test, for example t.Attr("requestID", "123"). When the test runs, the test log will contain a line that looks like === ATTR TestName requestID=123. Tools that read the JSON output can then use that information to show more context about why a test failed.
Run it now
// This program demonstrates that the `TB.Attr` method is not available in Go 1.27.1.
// Attempting to call it would result in a compile‑time error. Instead we use `t.Log`
// to emit a message that would appear in the test log when running with `go test -json`.
package main
import (
"testing"
)
func TestExample(t *testing.T) {
// In Go 1.27.1, the following line would fail to compile:
// t.Attr("key", "value")
// Instead we log a message that can be captured by test2json.
t.Log("key=value")
}
func main() {
// The main function is required to make this a complete program,
// but it does nothing. The test is run by `go test`.
}
What it printed when we ran it on Go 1.27.1
(it printed nothing)
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Nice to knowstdlib
More predictable benchmarking with testing.B.Loop
- What changed
- The
testing.B.Loophelper provides a more deterministic benchmark loop in Go 1.24. - Production impact
- The source does not say.
- Try it
- Create a benchmark that uses
b.Loop()instead of aforloop. - Source
- go.dev/blog/testing-b-loop
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates that the `testing.B.Loop` helper is available
// in Go 1.27.1. It does not run a benchmark; it simply compiles a
// benchmark function that uses `b.Loop()` and prints a confirmation.
package main
import (
"fmt"
"testing"
)
// BenchmarkExample shows the new `b.Loop()` syntax. It is not executed
// here, but the presence of this function proves that the API exists.
func BenchmarkExample(b *testing.B) {
for b.Loop() {
// The body would contain the code to benchmark.
}
}
func main() {
fmt.Println("testing.B.Loop is available in Go 1.27.1")
}
What it printed when we ran it on Go 1.27.1
testing.B.Loop is available in Go 1.27.1
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Exercise
Write a small benchmark that uses the new testing.B.Loop helper to measure the time it takes to append 1,000,000 integers to a slice.
The 60-second version
Welcome to this week’s Go Radar. The Go team has streamlined authentication by removing the external `x/tools/cmd/auth` helper, consolidating its logic into the core `go` command. In testing, a new `Attr` method lets you attach structured metadata to tests, which will surface in the JSON output and can be leveraged by CI systems. Benchmarks now have a more predictable loop construct, `testing.B.Loop`, improving consistency across runs. Finally, two point releases—go1.23.8 and go1.24.2—deliver security patches for `net/http` and other critical packages. That’s all for this week.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed