瀏覽代碼

Added Files

Yoginth 7 年之前
父節點
當前提交
8e006f88b8
共有 1 個文件被更改,包括 36 次插入0 次删除
  1. 36 0
      models/repo_editor_test.go

+ 36 - 0
models/repo_editor_test.go

@@ -0,0 +1,36 @@
+// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2018 Gitote. All rights reserved.
+//
+// This source code is licensed under the MIT license found in the
+// LICENSE file in the root directory of this source tree.
+
+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)
+		}
+	})
+}