generate_test.go 610 B

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