AlexStocks commented on code in PR #1062:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1062#discussion_r4505144072
##########
admin/controller/auth/auth_test.go:
##########
@@ -31,12 +31,8 @@ import (
)
func TestParseTokenRejectsUnexpectedSigningMethod(t *testing.T) {
- claims := CustomClaims{
- Username: "admin",
- StandardClaims: jwt.StandardClaims{
- ExpiresAt: time.Now().Add(time.Hour).Unix(),
- },
- }
+ claims := CustomClaims{Username: "admin"}
+ claims.ExpiresAt = time.Now().Add(time.Hour).Unix()
Review Comment:
💭 七处 fixture 是同一份样板(`{Username:"admin"} + ExpiresAt`),建议抽一个小 helper 收敛:
```go
func newTestClaims(ttl time.Duration) CustomClaims {
c := CustomClaims{Username: "admin"}
c.ExpiresAt = time.Now().Add(ttl).Unix()
return c
}
```
好处有两层:一是把「不要写回被弃用的 `jwt.StandardClaims`」这个约束集中到一处(下一批新人加用例时不会再撞
SA1019);二是这七个用例目前各自 `time.Now()` 取值,收敛后过期/有效的边界只有一个来源,读起来也更清楚。
##########
admin/controller/auth/auth_test.go:
##########
@@ -31,12 +31,8 @@ import (
)
func TestParseTokenRejectsUnexpectedSigningMethod(t *testing.T) {
- claims := CustomClaims{
- Username: "admin",
- StandardClaims: jwt.StandardClaims{
- ExpiresAt: time.Now().Add(time.Hour).Unix(),
- },
- }
+ claims := CustomClaims{Username: "admin"}
Review Comment:
💭 建议在这个文件顶部(imports 下方)补一行说明,解释为什么拆成「字面量 + 单独赋值」而不是原来的嵌套结构:
```go
// Assign the promoted ExpiresAt field directly: naming the deprecated
// jwt.StandardClaims type here trips staticcheck SA1019 (see #1062).
```
否则这是一个「看起来可以随手合并回 struct literal」的改动,下一个人做格式化/重构时很容易改回去,然后再被 lint 咬一次。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]