diff --git a/cmd/cli/app/ruletype/common.go b/cmd/cli/app/ruletype/common.go index b51425c92c..aad5b45907 100644 --- a/cmd/cli/app/ruletype/common.go +++ b/cmd/cli/app/ruletype/common.go @@ -92,6 +92,10 @@ func shouldSkipFile(f string) bool { ext := filepath.Ext(f) switch ext { case ".yaml", ".yml", ".json": + if cli.IsTestFile(f) { + // Skip test files. + return true + } return false default: fmt.Fprintf(os.Stderr, "Skipping file %s: not a yaml or json file\n", f) diff --git a/cmd/dev/app/rule_type/lint.go b/cmd/dev/app/rule_type/lint.go index 947eccaead..ebd1271f35 100644 --- a/cmd/dev/app/rule_type/lint.go +++ b/cmd/dev/app/rule_type/lint.go @@ -17,6 +17,7 @@ import ( "gopkg.in/yaml.v3" "github.com/mindersec/minder/internal/engine/eval/rego" + "github.com/mindersec/minder/internal/util/cli" minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1" ) @@ -58,7 +59,7 @@ func lintCmdRun(cmd *cobra.Command, _ []string) error { return nil } - if filepath.Ext(path) != ".yaml" && filepath.Ext(path) != ".yml" { + if !cli.IsYAMLFileAndNotATest(path) { return nil } diff --git a/internal/util/cli/cli.go b/internal/util/cli/cli.go index a766cfd4c1..3620be050e 100644 --- a/internal/util/cli/cli.go +++ b/internal/util/cli/cli.go @@ -230,3 +230,14 @@ func GetRelevantCLIConfigPath(v *viper.Viper) string { GetDefaultCLIConfigPath(), )) } + +// IsYAMLFileAndNotATest checks if a file is a YAML file and not a test file +func IsYAMLFileAndNotATest(path string) bool { + return (filepath.Ext(path) == ".yaml" || filepath.Ext(path) == ".yml") && + !IsTestFile(path) +} + +// IsTestFile checks if a file is a test file. Test files are YAML files ending with .test.yaml or .test.yml +func IsTestFile(path string) bool { + return strings.HasSuffix(path, ".test.yaml") || strings.HasSuffix(path, ".test.yml") +}