repo_editor_test.go 839 B

12345678910111213141516171819202122232425262728293031323334
  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. "os"
  7. "testing"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func Test_isRepositoryGitPath(t *testing.T) {
  11. Convey("Check if path is or resides inside '.git'", t, func() {
  12. sep := string(os.PathSeparator)
  13. testCases := []struct {
  14. path string
  15. expect bool
  16. }{
  17. {"." + sep + ".git", true},
  18. {"." + sep + ".git" + sep + "", true},
  19. {"." + sep + ".git" + sep + "hooks" + sep + "pre-commit", true},
  20. {".git" + sep + "hooks", true},
  21. {"dir" + sep + ".git", true},
  22. {".gitignore", false},
  23. {"dir" + sep + ".gitkeep", false},
  24. }
  25. for _, tc := range testCases {
  26. So(isRepositoryGitPath(tc.path), ShouldEqual, tc.expect)
  27. }
  28. })
  29. }