diff options
author | Unknwon <u@gogs.io> | 2018-12-25 10:01:52 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2018-12-25 10:01:52 -0500 |
commit | 9b37b1569c2d466dc8293ed482c1549aa9a6d4a9 (patch) | |
tree | 4d0ca462b5be5e986c8051cc280fb9a8c08ee7d2 /models/repo_editor_test.go | |
parent | 5f1f1bb5ed3c9916f11016942b9f553ef4fb72a9 (diff) |
models/repo_editor: add isRepositoryGitPath to detect invalid file path (#5558)
Diffstat (limited to 'models/repo_editor_test.go')
-rw-r--r-- | models/repo_editor_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/models/repo_editor_test.go b/models/repo_editor_test.go new file mode 100644 index 00000000..396382e3 --- /dev/null +++ b/models/repo_editor_test.go @@ -0,0 +1,34 @@ +// Copyright 2018 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "os" + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func Test_isRepositoryGitPath(t *testing.T) { + Convey("Check if path is or resides inside '.git'", t, func() { + sep := string(os.PathSeparator) + testCases := []struct { + path string + expect bool + }{ + {"." + sep + ".git", true}, + {"." + sep + ".git" + sep + "", true}, + {"." + sep + ".git" + sep + "hooks" + sep + "pre-commit", true}, + {".git" + sep + "hooks", true}, + {"dir" + sep + ".git", true}, + + {".gitignore", false}, + {"dir" + sep + ".gitkeep", false}, + } + for _, tc := range testCases { + So(isRepositoryGitPath(tc.path), ShouldEqual, tc.expect) + } + }) +} |