match_test.go 851 B

1234567891011121314151617181920212223242526272829
  1. package util
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestMatchFiles(t *testing.T) {
  8. dir, err := filepath.Abs("./")
  9. assert.Nil(t, err)
  10. files, err := MatchFiles("./*.sql")
  11. assert.Nil(t, err)
  12. assert.Equal(t, []string{filepath.Join(dir, "studeat.sql"), filepath.Join(dir, "student.sql"), filepath.Join(dir, "xx.sql")}, files)
  13. files, err = MatchFiles("./??.sql")
  14. assert.Nil(t, err)
  15. assert.Equal(t, []string{filepath.Join(dir, "xx.sql")}, files)
  16. files, err = MatchFiles("./*.sq*")
  17. assert.Nil(t, err)
  18. assert.Equal(t, []string{filepath.Join(dir, "studeat.sql"), filepath.Join(dir, "student.sql"), filepath.Join(dir, "xx.sql"), filepath.Join(dir, "xx.sql1")}, files)
  19. files, err = MatchFiles("./student.sql")
  20. assert.Nil(t, err)
  21. assert.Equal(t, []string{filepath.Join(dir, "student.sql")}, files)
  22. }