2018-12-25 10:01:52 -05:00
|
|
|
// 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.
|
|
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
package db
|
2018-12-25 10:01:52 -05:00
|
|
|
|
|
|
|
|
import (
|
2020-04-19 04:24:08 +08:00
|
|
|
"path/filepath"
|
2018-12-25 10:01:52 -05:00
|
|
|
"testing"
|
|
|
|
|
|
2020-04-19 04:24:08 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-12-25 10:01:52 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_isRepositoryGitPath(t *testing.T) {
|
2020-04-19 04:24:08 +08:00
|
|
|
tests := []struct {
|
2022-05-30 19:14:41 +08:00
|
|
|
path string
|
|
|
|
|
wantVal bool
|
2020-04-19 04:24:08 +08:00
|
|
|
}{
|
2022-05-30 19:14:41 +08:00
|
|
|
{path: filepath.Join(".", ".git"), wantVal: true},
|
|
|
|
|
{path: filepath.Join(".", ".git", ""), wantVal: true},
|
|
|
|
|
{path: filepath.Join(".", ".git", "hooks", "pre-commit"), wantVal: true},
|
|
|
|
|
{path: filepath.Join(".git", "hooks"), wantVal: true},
|
|
|
|
|
{path: filepath.Join("dir", ".git"), wantVal: true},
|
2018-12-25 10:01:52 -05:00
|
|
|
|
2022-05-30 19:14:41 +08:00
|
|
|
{path: filepath.Join(".", ".git."), wantVal: true},
|
|
|
|
|
{path: filepath.Join(".", ".git.", ""), wantVal: true},
|
|
|
|
|
{path: filepath.Join(".", ".git.", "hooks", "pre-commit"), wantVal: true},
|
|
|
|
|
{path: filepath.Join(".git.", "hooks"), wantVal: true},
|
|
|
|
|
{path: filepath.Join("dir", ".git."), wantVal: true},
|
|
|
|
|
|
|
|
|
|
{path: filepath.Join(".gitignore"), wantVal: false},
|
|
|
|
|
{path: filepath.Join("dir", ".gitkeep"), wantVal: false},
|
2020-04-19 04:24:08 +08:00
|
|
|
}
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
t.Run("", func(t *testing.T) {
|
2022-05-30 19:14:41 +08:00
|
|
|
assert.Equal(t, test.wantVal, isRepositoryGitPath(test.path))
|
2020-04-19 04:24:08 +08:00
|
|
|
})
|
|
|
|
|
}
|
2018-12-25 10:01:52 -05:00
|
|
|
}
|