2021-03-12 17:49:28 +08:00
|
|
|
package generate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-01-25 23:15:07 +08:00
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/config"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
2021-03-12 17:49:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var testTypes = `
|
|
|
|
type User struct{}
|
|
|
|
type Class struct{}
|
|
|
|
`
|
|
|
|
|
|
|
|
func TestDo(t *testing.T) {
|
|
|
|
cfg, err := config.NewConfig(config.DefaultFormat)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-01-03 21:32:40 +08:00
|
|
|
tempDir := pathx.MustTempDir()
|
2021-03-12 17:49:28 +08:00
|
|
|
typesfile := filepath.Join(tempDir, "types.go")
|
2021-04-15 19:49:17 +08:00
|
|
|
err = ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
|
2021-03-12 17:49:28 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = Do(&Context{
|
|
|
|
Types: []string{"User", "Class"},
|
|
|
|
Cache: false,
|
|
|
|
Output: tempDir,
|
|
|
|
Cfg: cfg,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|