1
0
mirror of https://shylinux.com/x/icebergs synced 2025-05-01 03:09:21 +08:00

add web.code.test

This commit is contained in:
shaoying 2020-12-09 21:30:02 +08:00
parent 330579531a
commit 8f8eed2015
3 changed files with 54 additions and 6 deletions

View File

@ -30,7 +30,7 @@ func _cli_progress(m *ice.Message, cb interface{}) {
} }
}) })
} }
func Follow(m *ice.Message, action string) bool { func Follow(m *ice.Message, action string, cb func()) bool {
m.Option(ice.MSG_PROCESS, "_follow") m.Option(ice.MSG_PROCESS, "_follow")
if m.Option(mdb.CACHE_ACTION, action); m.Option(mdb.CACHE_HASH) != "" { if m.Option(mdb.CACHE_ACTION, action); m.Option(mdb.CACHE_HASH) != "" {
m.Cmdy(OUTPUT, m.Option(mdb.CACHE_HASH)) m.Cmdy(OUTPUT, m.Option(mdb.CACHE_HASH))
@ -48,6 +48,7 @@ func Follow(m *ice.Message, action string) bool {
m.Option(mdb.CACHE_HASH, m.Result()) m.Option(mdb.CACHE_HASH, m.Result())
m.Option(mdb.CACHE_BEGIN, 1) m.Option(mdb.CACHE_BEGIN, 1)
m.Set(ice.MSG_RESULT) m.Set(ice.MSG_RESULT)
m.Go(cb)
return false return false
} }

View File

@ -4,13 +4,16 @@ import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"github.com/shylinux/toolkits/util/bench" "github.com/shylinux/toolkits/util/bench"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"path"
"strings" "strings"
"sync/atomic" "sync/atomic"
) )
@ -65,6 +68,53 @@ func init() {
BENCH: {Name: BENCH, Help: "性能压测", Value: kit.Data(kit.MDB_SHORT, kit.MDB_ZONE)}, BENCH: {Name: BENCH, Help: "性能压测", Value: kit.Data(kit.MDB_SHORT, kit.MDB_ZONE)},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
"test": {Name: "test path func auto run func", Help: "测试用例", Action: map[string]*ice.Action{
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
cli.Follow(m, "run", func() {
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
m.Cmdy(cli.SYSTEM, "go", "test", "./", "-v", "-run="+arg[1])
})
}},
"func": {Name: "func", Help: "函数", Hand: func(m *ice.Message, arg ...string) {
msg := m.Spawn()
if strings.HasSuffix(arg[0], "/") {
msg.Option(cli.CMD_DIR, arg[0])
msg.Split(msg.Cmdx(cli.SYSTEM, "grep", "-r", "func Test.*(", "./"), "file:line", ":", "\n")
msg.Table(func(index int, value map[string]string, head []string) {
if strings.HasPrefix(strings.TrimSpace(value["line"]), "//") {
return
}
ls := kit.Split(value["line"], " (", " (", " (")
m.Push("file", value["file"])
m.Push("func", strings.TrimPrefix(ls[1], "Test"))
})
} else {
for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, "grep", "^func Test.*(", arg[0]), "\n", "\n", "\n") {
ls := kit.Split(line, " (", " (", " (")
m.Push("func", strings.TrimPrefix(ls[1], "Test"))
}
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 || arg[0] == "" {
m.Cmdy(nfs.DIR, "./")
return
}
if len(arg) == 1 {
if strings.HasSuffix(arg[0], "/") {
m.Cmdy(nfs.DIR, arg[0])
} else {
for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, "grep", "^func Test.*(", arg[0]), "\n", "\n", "\n") {
ls := kit.Split(line, " (", " (", " (")
m.Push("func", strings.TrimPrefix(ls[1], "Test"))
}
}
return
}
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
m.Cmdy(cli.SYSTEM, "go", "test", "./", "-v", "-run="+arg[1])
}},
BENCH: {Name: "bench zone id auto insert", Help: "性能压测", Action: map[string]*ice.Action{ BENCH: {Name: "bench zone id auto insert", Help: "性能压测", Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, BENCH, "", mdb.HASH, arg) m.Cmdy(mdb.INSERT, BENCH, "", mdb.HASH, arg)

View File

@ -70,11 +70,7 @@ func init() {
}) })
}}, }},
gdb.BUILD: {Name: "build link", Help: "构建", Hand: func(m *ice.Message, arg ...string) { gdb.BUILD: {Name: "build link", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
if cli.Follow(m, gdb.BUILD) { cli.Follow(m, gdb.BUILD, func() {
return
}
m.Go(func() {
defer m.Cmdy(cli.OUTPUT, mdb.MODIFY, kit.MDB_STATUS, cli.Status.Stop) defer m.Cmdy(cli.OUTPUT, mdb.MODIFY, kit.MDB_STATUS, cli.Status.Stop)
defer m.Option(kit.MDB_HASH, m.Option("cache.hash")) defer m.Option(kit.MDB_HASH, m.Option("cache.hash"))
@ -94,6 +90,7 @@ func init() {
} }
m.Cmdy(cli.SYSTEM, "make", "PREFIX="+pp, "install") m.Cmdy(cli.SYSTEM, "make", "PREFIX="+pp, "install")
}) })
}}, }},
gdb.SPAWN: {Name: "spawn link", Help: "新建", Hand: func(m *ice.Message, arg ...string) { gdb.SPAWN: {Name: "spawn link", Help: "新建", Hand: func(m *ice.Message, arg ...string) {