From 211ec62a70a62fa73c3561ba48b7d50c004de3aa Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 28 Feb 2025 15:23:50 +0100 Subject: [PATCH] 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. --- acceptance/acceptance_test.go | 3 +++ acceptance/config_test.go | 8 ++++++++ acceptance/selftest/basic/script | 4 ++++ acceptance/selftest/basic/test.toml | 3 +++ 4 files changed, 18 insertions(+) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 066a84299..afdc42abc 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -390,6 +390,9 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont if _, ok := Ignored[relPath]; ok { continue } + if config.CompiledIgnoreObject.MatchesPath(relPath) { + continue + } unexpected = append(unexpected, relPath) if strings.HasPrefix(relPath, "out") { // We have a new file starting with "out" diff --git a/acceptance/config_test.go b/acceptance/config_test.go index 4edfee69d..cc5257c65 100644 --- a/acceptance/config_test.go +++ b/acceptance/config_test.go @@ -11,6 +11,7 @@ import ( "github.com/BurntSushi/toml" "github.com/databricks/cli/libs/testdiff" "github.com/databricks/cli/libs/testserver" + ignore "github.com/sabhiram/go-gitignore" "github.com/stretchr/testify/require" ) @@ -51,6 +52,11 @@ type TestConfig struct { // List of request headers to include when recording requests. IncludeRequestHeaders []string + + // List of gitignore patterns to ignore when checking output files + Ignore []string + + CompiledIgnoreObject *ignore.GitIgnore } 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, ", ") } diff --git a/acceptance/selftest/basic/script b/acceptance/selftest/basic/script index bccf30e71..a3ec98402 100644 --- a/acceptance/selftest/basic/script +++ b/acceptance/selftest/basic/script @@ -27,3 +27,7 @@ echo 123456 printf "\n=== Testing --version" trace $CLI --version + +touch ignored_file.txt +mkdir ignored_dir +touch ignored_dir/hello.txt diff --git a/acceptance/selftest/basic/test.toml b/acceptance/selftest/basic/test.toml index 762e28ceb..3ca3d9255 100644 --- a/acceptance/selftest/basic/test.toml +++ b/acceptance/selftest/basic/test.toml @@ -1,5 +1,8 @@ # Badness = "Brief description of what's wrong with the test output, if anything" +Ignore = ['ignore*'] + + #[GOOS] # Disable on Windows #windows = false