acc: add Ignore setting to config (#2405)

Ignore output files using gitignore syntax.

## Changes
New Ignore setting in test.toml that will ignore specified files (syntax
is gitignore).

## Why

I'm using it in #2396 to ignore virtual env. It includes a lot of files.
The regular 'rm -fr .venv' approach only works if script get to that
point, but due to errors it might abort early. In that cases test runner
prints all unexpected files, polluting output. Ignoring those files at
test runner level ensure you never see them.

## Tests
Updated selftest/basic.
This commit is contained in:
Denis Bilenko 2025-02-28 15:23:50 +01:00 committed by GitHub
parent 3aef065c5c
commit 211ec62a70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 0 deletions

View File

@ -390,6 +390,9 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
if _, ok := Ignored[relPath]; ok { if _, ok := Ignored[relPath]; ok {
continue continue
} }
if config.CompiledIgnoreObject.MatchesPath(relPath) {
continue
}
unexpected = append(unexpected, relPath) unexpected = append(unexpected, relPath)
if strings.HasPrefix(relPath, "out") { if strings.HasPrefix(relPath, "out") {
// We have a new file starting with "out" // We have a new file starting with "out"

View File

@ -11,6 +11,7 @@ import (
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/databricks/cli/libs/testdiff" "github.com/databricks/cli/libs/testdiff"
"github.com/databricks/cli/libs/testserver" "github.com/databricks/cli/libs/testserver"
ignore "github.com/sabhiram/go-gitignore"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -51,6 +52,11 @@ type TestConfig struct {
// List of request headers to include when recording requests. // List of request headers to include when recording requests.
IncludeRequestHeaders []string IncludeRequestHeaders []string
// List of gitignore patterns to ignore when checking output files
Ignore []string
CompiledIgnoreObject *ignore.GitIgnore
} }
type ServerStub struct { type ServerStub struct {
@ -111,6 +117,8 @@ func LoadConfig(t *testing.T, dir string) (TestConfig, string) {
} }
} }
result.CompiledIgnoreObject = ignore.CompileIgnoreLines(result.Ignore...)
return result, strings.Join(configs, ", ") return result, strings.Join(configs, ", ")
} }

View File

@ -27,3 +27,7 @@ echo 123456
printf "\n=== Testing --version" printf "\n=== Testing --version"
trace $CLI --version trace $CLI --version
touch ignored_file.txt
mkdir ignored_dir
touch ignored_dir/hello.txt

View File

@ -1,5 +1,8 @@
# Badness = "Brief description of what's wrong with the test output, if anything" # Badness = "Brief description of what's wrong with the test output, if anything"
Ignore = ['ignore*']
#[GOOS] #[GOOS]
# Disable on Windows # Disable on Windows
#windows = false #windows = false