ITADN

Consider not parsing flags in `init()`

#22Closedichekrygin 创建于 2025-05-08
I
ichekrygincommented
Please consider finding an alternative to the current usage at: https://github.com/kubernetes-sigs/etcd-manager/blob/ff658808c84129191e05e6a203667c7854a104a3/pkg/etcd/etcdprocess.go#L52 Parsing command-line flags in a package `init()` function can have unintended side effects. In particular, this pattern interferes with the normal behavior of `go test`. We're observing that importing this package as a dependency suppresses `go test -v` output. This happens because the early `flag.Parse()` call consumes all flags—including `-test.v`—before the Go test runner processes them. This makes debugging and running tests with expected verbosity difficult. Consider deferring flag parsing to the `main()` or `TestMain()` function or using a guard to prevent unintended parsing in library contexts.
关闭于 2025-06-25 3 条评论