From dd96fa36745e98bd9a3153608cc26403f898f5a0 Mon Sep 17 00:00:00 2001 From: jshlbrd Date: Wed, 2 Oct 2024 16:59:02 -0700 Subject: [PATCH] fix(cmd): Edge Cases in Test Subcommand --- cmd/substation/test.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd/substation/test.go b/cmd/substation/test.go index e38e94ef..1eaff62c 100644 --- a/cmd/substation/test.go +++ b/cmd/substation/test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "io" "os" "path/filepath" "time" @@ -36,6 +37,10 @@ func init() { func fiConfig(f string) (customConfig, error) { fi, err := os.Open(f) if err != nil { + if err == io.EOF { + return customConfig{}, nil + } + return customConfig{}, err } @@ -259,9 +264,12 @@ production resources, such as any enrichment or send transforms. return err } + // If the Jsonnet cannot compile, then the file is invalid. mem, err := buildFile(arg, m) if err != nil { - return err + fmt.Printf("?\t%s\t[config error]\n", arg) + + return nil } cfg, err = memConfig(mem) @@ -294,18 +302,18 @@ production resources, such as any enrichment or send transforms. return err } - // Skip directories, except the one provided as an argument, if - // the 'recursive' flag is not set. - if d.IsDir() && path != arg && !cmd.Flag("recursive").Changed { - return filepath.SkipDir - } - if filepath.Ext(path) == ".json" || filepath.Ext(path) == ".jsonnet" || filepath.Ext(path) == ".libsonnet" { entries = append(entries, path) } + // Skip directories, except the one provided as an argument, if + // the 'recursive' flag is not set. + if d.IsDir() && path != arg && !cmd.Flag("recursive").Changed { + return filepath.SkipDir + } + return nil }); err != nil { return err @@ -327,9 +335,12 @@ production resources, such as any enrichment or send transforms. return err } + // If the Jsonnet cannot compile, then the file is invalid. mem, err := buildFile(entry, m) if err != nil { - return err + fmt.Printf("?\t%s\t[config error]\n", entry) + + continue } cfg, err = memConfig(mem)