cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.28k stars 515 forks source link

--bugfix="assert.NotNil not work" #1179

Closed ElvisWai closed 1 month ago

ElvisWai commented 2 months ago

1178

修复 assert的 NotNil 不生效。(参数判断有误)

CLAassistant commented 2 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

:white_check_mark: ElvisWai
:x: liziwei


liziwei seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

ElvisWai commented 2 months ago

Describe the bug

使用 assert 的 NotNil 断言时不生效

Replay 测试代码:

import  "github.com/cloudwego/hertz/pkg/common/test/assert"
func TestAssertNotNil(t *testing.T) {
    var test interface{}
    assert.NotNil(t, test)
    fmt.Println("test 值不为空")
}

image

Hertz version:

version: 0.9.2

bugfix

func NotNil(t testing.TB, data interface{}) {
    t.Helper()
    if data != nil {
        return
    }

    if reflect.ValueOf(data).IsNil() {
        t.Fatalf("assertion failed, unexpected: %v, expected: not nil", data)
    }
}
welkeyever commented 2 months ago

有一些 ut 没过,可以瞅瞅

ElvisWai commented 1 month ago

@welkeyever 🐶 这是原本的 ut 写错了 Nil 和 NotNil 原本期望是达到什么效果?

welkeyever commented 1 month ago

@welkeyever 🐶 这是原本的 ut 写错了 Nil 和 NotNil 原本期望是达到什么效果?

嗯,看起来是的,可以一并修复下对应的 ut

ElvisWai commented 1 month ago

@welkeyever 有问题的ut改完了,但提交的账号不一致。。。这能解决吗

welkeyever commented 1 month ago

可能需要统一下,可以本地 squash 成一个 commit

ElvisWai commented 1 month ago

我重新提交PR