repo_editor_test.go 937 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package models
  7. import (
  8. "os"
  9. "testing"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func Test_isRepositoryGitPath(t *testing.T) {
  13. Convey("Check if path is or resides inside '.git'", t, func() {
  14. sep := string(os.PathSeparator)
  15. testCases := []struct {
  16. path string
  17. expect bool
  18. }{
  19. {"." + sep + ".git", true},
  20. {"." + sep + ".git" + sep + "", true},
  21. {"." + sep + ".git" + sep + "hooks" + sep + "pre-commit", true},
  22. {".git" + sep + "hooks", true},
  23. {"dir" + sep + ".git", true},
  24. {".gitignore", false},
  25. {"dir" + sep + ".gitkeep", false},
  26. }
  27. for _, tc := range testCases {
  28. So(isRepositoryGitPath(tc.path), ShouldEqual, tc.expect)
  29. }
  30. })
  31. }