generate_test.go 677 B

1234567891011121314151617181920212223242526272829303132333435
  1. package generate
  2. import (
  3. "io/ioutil"
  4. "path/filepath"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/zeromicro/go-zero/tools/goctl/config"
  8. "github.com/zeromicro/go-zero/tools/goctl/util/pathx"
  9. )
  10. var testTypes = `
  11. type User struct{}
  12. type Class struct{}
  13. `
  14. func TestDo(t *testing.T) {
  15. cfg, err := config.NewConfig(config.DefaultFormat)
  16. assert.Nil(t, err)
  17. tempDir := pathx.MustTempDir()
  18. typesfile := filepath.Join(tempDir, "types.go")
  19. err = ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
  20. assert.Nil(t, err)
  21. err = Do(&Context{
  22. Types: []string{"User", "Class"},
  23. Cache: false,
  24. Output: tempDir,
  25. Cfg: cfg,
  26. })
  27. assert.Nil(t, err)
  28. }