-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dapeng
committed
Dec 22, 2024
1 parent
f71915e
commit a117167
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |