a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLoadRepoGitignore_SkipsBlanksCommentsAndNonUTF8(t *testing.T) {
|
|
dir := t.TempDir()
|
|
// A valid file interleaved with a blank line, a comment, and a
|
|
// non-UTF-8 (e.g. DLP-encrypted) line that must be skipped, not fed to
|
|
// the matcher and not aborting the read.
|
|
content := "# comment\n\nnode_modules/\n" + string([]byte{0xff, 0xfe, 0xfd}) + "\n*.log\n"
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, ".gitignore"), []byte(content), 0o644))
|
|
|
|
got := loadRepoGitignore(dir)
|
|
require.Equal(t, []string{"node_modules/", "*.log"}, got)
|
|
}
|
|
|
|
func TestLoadRepoGitignore_LongLineDoesNotAbort(t *testing.T) {
|
|
dir := t.TempDir()
|
|
// A pathologically long line (larger than the default 64 KiB scanner
|
|
// buffer) must not discard the patterns that follow it.
|
|
long := make([]byte, 200*1024)
|
|
for i := range long {
|
|
long[i] = 'a'
|
|
}
|
|
content := "*.tmp\n" + string(long) + "\nbuild/\n"
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, ".gitignore"), []byte(content), 0o644))
|
|
|
|
got := loadRepoGitignore(dir)
|
|
require.Contains(t, got, "*.tmp")
|
|
require.Contains(t, got, "build/")
|
|
}
|
|
|
|
func TestLoadRepoGitignore_MissingFileIsNil(t *testing.T) {
|
|
require.Nil(t, loadRepoGitignore(t.TempDir()))
|
|
require.Nil(t, loadRepoGitignore(""))
|
|
}
|