Skip to content

Commit

Permalink
fix(cmd): Edge Cases in Test Subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
jshlbrd committed Oct 2, 2024
1 parent 33f46d4 commit dd96fa3
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cmd/substation/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit dd96fa3

Please sign in to comment.