repo_editor_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package db
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func Test_isRepositoryGitPath(t *testing.T) {
  11. tests := []struct {
  12. path string
  13. wantVal bool
  14. }{
  15. {path: filepath.Join(".", ".git"), wantVal: true},
  16. {path: filepath.Join(".", ".git", ""), wantVal: true},
  17. {path: filepath.Join(".", ".git", "hooks", "pre-commit"), wantVal: true},
  18. {path: filepath.Join(".git", "hooks"), wantVal: true},
  19. {path: filepath.Join("dir", ".git"), wantVal: true},
  20. {path: filepath.Join(".", ".git."), wantVal: true},
  21. {path: filepath.Join(".", ".git.", ""), wantVal: true},
  22. {path: filepath.Join(".", ".git.", "hooks", "pre-commit"), wantVal: true},
  23. {path: filepath.Join(".git.", "hooks"), wantVal: true},
  24. {path: filepath.Join("dir", ".git."), wantVal: true},
  25. {path: filepath.Join(".gitignore"), wantVal: false},
  26. {path: filepath.Join("dir", ".gitkeep"), wantVal: false},
  27. }
  28. for _, test := range tests {
  29. t.Run("", func(t *testing.T) {
  30. assert.Equal(t, test.wantVal, isRepositoryGitPath(test.path))
  31. })
  32. }
  33. }