2021-11-22 19:53:42 +08:00
|
|
|
package invoker
|
2020-12-06 16:50:08 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestScript int
|
|
|
|
|
|
|
|
func (script TestScript) Run(ctx context.Context) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunDBScript(t *testing.T) {
|
|
|
|
asserts := assert.New(t)
|
2021-11-22 19:53:42 +08:00
|
|
|
Register("test", TestScript(0))
|
2020-12-06 16:50:08 +08:00
|
|
|
|
|
|
|
// 不存在
|
|
|
|
{
|
|
|
|
asserts.Error(RunDBScript("else", context.Background()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 存在
|
|
|
|
{
|
|
|
|
asserts.NoError(RunDBScript("test", context.Background()))
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 19:53:42 +08:00
|
|
|
|
|
|
|
func TestListPrefix(t *testing.T) {
|
|
|
|
asserts := assert.New(t)
|
|
|
|
Register("U1", TestScript(0))
|
|
|
|
Register("U2", TestScript(0))
|
|
|
|
Register("U3", TestScript(0))
|
|
|
|
Register("P1", TestScript(0))
|
|
|
|
|
|
|
|
res := ListPrefix("U")
|
|
|
|
asserts.Len(res, 3)
|
|
|
|
}
|