repo_editor_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 database
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestIsRepositoryGitPath(t *testing.T) {
  10. tests := []struct {
  11. path string
  12. wantVal bool
  13. }{
  14. {path: ".git", wantVal: true},
  15. {path: "./.git", wantVal: true},
  16. {path: ".git/hooks/pre-commit", wantVal: true},
  17. {path: ".git/hooks", wantVal: true},
  18. {path: "dir/.git", wantVal: true},
  19. // Case-insensitive file system
  20. {path: ".Git", wantVal: true},
  21. {path: "./.Git", wantVal: true},
  22. {path: ".Git/hooks/pre-commit", wantVal: true},
  23. {path: ".Git/hooks", wantVal: true},
  24. {path: "dir/.Git", wantVal: true},
  25. {path: ".gitignore", wantVal: false},
  26. {path: "dir/.gitkeep", wantVal: false},
  27. // Windows-specific
  28. {path: `.git\`, wantVal: true},
  29. {path: `.git\hooks\pre-commit`, wantVal: true},
  30. {path: `.git\hooks`, wantVal: true},
  31. {path: `dir\.git`, wantVal: true},
  32. {path: `.\.git.`, wantVal: true},
  33. {path: `.\.git.\`, wantVal: true},
  34. {path: `.git.\hooks\pre-commit`, wantVal: true},
  35. {path: `.git.\hooks`, wantVal: true},
  36. {path: `dir\.git.`, wantVal: true},
  37. {path: "./.git.", wantVal: true},
  38. {path: "./.git./", wantVal: true},
  39. {path: ".git./hooks/pre-commit", wantVal: true},
  40. {path: ".git./hooks", wantVal: true},
  41. {path: "dir/.git.", wantVal: true},
  42. {path: `dir\.gitkeep`, wantVal: false},
  43. }
  44. for _, test := range tests {
  45. t.Run(test.path, func(t *testing.T) {
  46. assert.Equal(t, test.wantVal, isRepositoryGitPath(test.path))
  47. })
  48. }
  49. }