Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/cli/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import (
// NewValidateCmd creates the "burnless validate" command.
func NewValidateCmd() *cobra.Command {
return &cobra.Command{
Use: "validate <file>",
Use: "validate [file]",
Short: "Validate an sre.yaml file",
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
SilenceUsage: true,
RunE: runValidate,
}
}

func runValidate(cmd *cobra.Command, args []string) error {
path := args[0]
path := "sre.yaml"
if len(args) > 0 {
path = args[0]
}

cfg, err := config.Load(path)
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions internal/cli/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,32 @@ func TestRunValidate_MissingFile(t *testing.T) {
t.Fatal("expected error for missing file, got nil")
}
}

func TestRunValidate_DefaultFile(t *testing.T) {
// change to a temp dir with a valid sre.yaml
tmp := t.TempDir()
sre := `
service: payments-api
slos:
- name: availability
target: 99.9
window: 30d
`
if err := os.WriteFile(filepath.Join(tmp, "sre.yaml"), []byte(sre), 0o644); err != nil {
t.Fatalf("failed to write sre.yaml: %v", err)
}

// change working directory to temp dir
orig, _ := os.Getwd()
defer func() { _ = os.Chdir(orig) }()
if err := os.Chdir(tmp); err != nil {
t.Fatalf("failed to chdir: %v", err)
}

// run validate with NO arguments — should find sre.yaml automatically
cmd := NewValidateCmd()
cmd.SetArgs([]string{})
if err := cmd.Execute(); err != nil {
t.Fatalf("expected no error with default sre.yaml, got: %v", err)
}
}
Loading