mirror of
https://github.com/coder/coder.git
synced 2026-06-04 13:38:21 +00:00
25d70ce7bc
Closes https://github.com/coder/coder/issues/19011 We now use [go-git](https://pkg.go.dev/github.com/go-git/go-git/v5@v5.16.2/plumbing/format/gitignore)'s `gitignore` plumbing implementation to parse the `.gitignore` files and match against the patterns generated. We use this to ignore any ignored files in the git repository. Unfortunately I've had to slightly re-implement some of the interface exposed by `go-git` because they use `billy.Filesystem` instead of `afero.Fs`.
39 lines
794 B
Go
39 lines
794 B
Go
package ignore_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/agent/agentcontainers/ignore"
|
|
)
|
|
|
|
func TestFilePathToParts(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
path string
|
|
expected []string
|
|
}{
|
|
{"", []string{}},
|
|
{"/", []string{}},
|
|
{"foo", []string{"foo"}},
|
|
{"/foo", []string{"foo"}},
|
|
{"./foo/bar", []string{"foo", "bar"}},
|
|
{"../foo/bar", []string{"..", "foo", "bar"}},
|
|
{"foo/bar/baz", []string{"foo", "bar", "baz"}},
|
|
{"/foo/bar/baz", []string{"foo", "bar", "baz"}},
|
|
{"foo/../bar", []string{"bar"}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(fmt.Sprintf("`%s`", tt.path), func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
parts := ignore.FilePathToParts(tt.path)
|
|
require.Equal(t, tt.expected, parts)
|
|
})
|
|
}
|
|
}
|