Skip to content

Commit

Permalink
feat: add test case for hook.go
Browse files Browse the repository at this point in the history
  • Loading branch information
dapeng committed Dec 22, 2024
1 parent f71915e commit a117167
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions hook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package gone

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBeforeStartProvider_Provide(t *testing.T) {
// 准备测试数据
preparer := &Preparer{}
provider := &BeforeStartProvider{
preparer: preparer,
}

// 执行测试
hook, err := provider.Provide()

// 验证结果
assert.NoError(t, err)
assert.NotNil(t, hook)
var beforeStart = BeforeStart(preparer.beforeStart)

assert.Equal(t, reflect.ValueOf(hook).Pointer(), reflect.ValueOf(beforeStart).Pointer())
}

func TestAfterStartProvider_Provide(t *testing.T) {
// 准备测试数据
preparer := &Preparer{}
provider := &AfterStartProvider{
preparer: preparer,
}

// 执行测试
hook, err := provider.Provide()

// 验证结果
assert.NoError(t, err)
assert.NotNil(t, hook)
var fn = AfterStart(preparer.afterStart)
assert.Equal(t, reflect.ValueOf(hook).Pointer(), reflect.ValueOf(fn).Pointer())
}

func TestBeforeStopProvider_Provide(t *testing.T) {
// 准备测试数据
preparer := &Preparer{}
provider := &BeforeStopProvider{
preparer: preparer,
}

// 执行测试
hook, err := provider.Provide()

// 验证结果
assert.NoError(t, err)
assert.NotNil(t, hook)
var fn = BeforeStop(preparer.beforeStop)
assert.Equal(t, reflect.ValueOf(hook).Pointer(), reflect.ValueOf(fn).Pointer())
}

func TestAfterStopProvider_Provide(t *testing.T) {
// 准备测试数据
preparer := &Preparer{}
provider := &AfterStopProvider{
preparer: preparer,
}

// 执行测试
hook, err := provider.Provide()

// 验证结果
assert.NoError(t, err)
assert.NotNil(t, hook)
var fn = AfterStop(preparer.afterStop)
assert.Equal(t, reflect.ValueOf(hook).Pointer(), reflect.ValueOf(fn).Pointer())
}

0 comments on commit a117167

Please sign in to comment.