Add MustTempDir (#1069)
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/stringx"
|
||||
conf "github.com/tal-tech/go-zero/tools/goctl/config"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
var cfg = &conf.Config{
|
||||
@@ -57,7 +58,7 @@ func TestRpcGenerate(t *testing.T) {
|
||||
|
||||
// case go mod
|
||||
t.Run("GOMOD", func(t *testing.T) {
|
||||
workDir := t.TempDir()
|
||||
workDir := util.MustTempDir()
|
||||
name := filepath.Base(workDir)
|
||||
_, err = execx.Run("go mod init "+name, workDir)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,7 +25,7 @@ service {{.serviceName}} {
|
||||
}
|
||||
`
|
||||
|
||||
// ProtoTmpl returns an sample of a proto file
|
||||
// ProtoTmpl returns a sample of a proto file
|
||||
func ProtoTmpl(out string) error {
|
||||
protoFilename := filepath.Base(out)
|
||||
serviceName := stringx.From(strings.TrimSuffix(protoFilename, filepath.Ext(protoFilename)))
|
||||
|
||||
@@ -5,16 +5,18 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
func TestProtoTmpl(t *testing.T) {
|
||||
_ = Clean()
|
||||
// exists dir
|
||||
err := ProtoTmpl(t.TempDir())
|
||||
err := ProtoTmpl(util.MustTempDir())
|
||||
assert.Nil(t, err)
|
||||
|
||||
// not exist dir
|
||||
dir := filepath.Join(t.TempDir(), "test")
|
||||
dir := filepath.Join(util.MustTempDir(), "test")
|
||||
err = ProtoTmpl(dir)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user