mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-10 22:48:14 -05:00
Co-authored-by: mask-pp <mask-pp@users.noreply.github.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
43 lines
739 B
Go
43 lines
739 B
Go
package cmd_test
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"scroll-tech/common/cmd"
|
|
)
|
|
|
|
func TestCmd(t *testing.T) {
|
|
app := cmd.NewCmd("date", "+%Y-%m-%d")
|
|
|
|
tm := time.Now()
|
|
curTime := fmt.Sprintf("%d-%02d-%02d", tm.Year(), tm.Month(), tm.Day())
|
|
|
|
okCh := make(chan struct{}, 1)
|
|
app.RegistFunc(curTime, func(buf string) {
|
|
if strings.Contains(buf, curTime) {
|
|
select {
|
|
case okCh <- struct{}{}:
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
})
|
|
defer app.UnRegistFunc(curTime)
|
|
|
|
// Run cmd.
|
|
app.RunCmd(true)
|
|
|
|
// Wait result.
|
|
select {
|
|
case <-okCh:
|
|
return
|
|
case <-time.After(time.Second):
|
|
assert.Fail(t, fmt.Sprintf("didn't get the desired result before timeout, keyword: %s", curTime))
|
|
}
|
|
}
|