-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathvalidate.go
More file actions
61 lines (51 loc) · 1.42 KB
/
validate.go
File metadata and controls
61 lines (51 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"os"
"github.com/ethpandaops/assertoor/pkg/assertoor"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var validateCmd = &cobra.Command{
Use: "validate",
Short: "Validate assertoor configuration",
Long: `Validates the assertoor configuration file for syntax and semantic correctness`,
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
// Set up minimal logging for error output
logrus.SetLevel(logrus.ErrorLevel)
if verbose {
logrus.SetLevel(logrus.DebugLevel)
}
// Check if config file is specified
if cfgFile == "" {
logrus.Error("no configuration file specified")
os.Exit(1)
}
// Load configuration
config, err := assertoor.NewConfig(cfgFile)
if err != nil {
logrus.WithError(err).Error("failed to load configuration")
os.Exit(1)
}
// Validate configuration
if err := config.Validate(); err != nil {
logrus.WithError(err).Error("configuration validation failed")
os.Exit(1)
}
// Validate external test files exist and can be parsed
for _, extTest := range config.ExternalTests {
if extTest.File != "" {
// Check if external test file exists
if _, err := os.Stat(extTest.File); os.IsNotExist(err) {
logrus.WithField("test", extTest.File).Error("external test file does not exist")
os.Exit(1)
}
}
}
// Success - exit cleanly with no output
os.Exit(0)
},
}
func init() {
rootCmd.AddCommand(validateCmd)
}