template_test.go 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package generate
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/zeromicro/go-zero/tools/goctl/util/pathx"
  7. )
  8. func TestTemplate(t *testing.T) {
  9. tempDir := t.TempDir()
  10. pathx.RegisterGoctlHome(tempDir)
  11. t.Cleanup(func() {
  12. pathx.RegisterGoctlHome("")
  13. })
  14. t.Run("Category", func(t *testing.T) {
  15. assert.Equal(t, category, Category())
  16. })
  17. t.Run("Clean", func(t *testing.T) {
  18. err := Clean()
  19. assert.NoError(t, err)
  20. })
  21. t.Run("Templates", func(t *testing.T) {
  22. err := Templates()
  23. assert.NoError(t, err)
  24. assert.True(t, pathx.FileExists(filepath.Join(tempDir, category, modelTemplateFile)))
  25. })
  26. t.Run("RevertTemplate", func(t *testing.T) {
  27. assert.NoError(t, RevertTemplate(modelTemplateFile))
  28. assert.Error(t, RevertTemplate("foo"))
  29. })
  30. t.Run("Update", func(t *testing.T) {
  31. assert.NoError(t, Update())
  32. })
  33. }