feat: add idempotent calendar bootstrap
Bootstrap independently reviewed catalogs through audited import, approval, and initial activation transitions, then resume insight scheduling safely.
This commit is contained in:
72
cmd/calendar/main_test.go
Normal file
72
cmd/calendar/main_test.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseOptionsSupportsHelp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if _, err := parseOptions([]string{"--help"}); !errors.Is(err, flag.ErrHelp) {
|
||||
t.Fatalf("error=%v, want flag.ErrHelp", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOptionsRequiresBootstrapInputs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
}{
|
||||
{name: "file", args: []string{"-action", "bootstrap", "-current-jalali-year", "1405", "-reviewer", "reviewer", "-actor", "operator"}},
|
||||
{name: "current year", args: []string{"-action", "bootstrap", "-file", "/calendar/reviewed.json", "-reviewer", "reviewer", "-actor", "operator"}},
|
||||
{name: "reviewer", args: []string{"-action", "bootstrap", "-file", "/calendar/reviewed.json", "-current-jalali-year", "1405", "-actor", "operator"}},
|
||||
{name: "operator", args: []string{"-action", "bootstrap", "-file", "/calendar/reviewed.json", "-current-jalali-year", "1405", "-reviewer", "reviewer"}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if _, err := parseOptions(test.args); err == nil {
|
||||
t.Fatal("expected missing bootstrap input error")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
options, err := parseOptions([]string{"-action", "bootstrap", "-file", "/calendar/reviewed.json", "-current-jalali-year", "1405", "-reviewer", "reviewer", "-actor", "operator"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if options.action != "bootstrap" || options.currentJalaliYear != 1405 || options.reviewer != "reviewer" || options.actor != "operator" {
|
||||
t.Fatalf("options=%+v", options)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadImportRejectsUnknownFieldsAndTrailingDocuments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
directory := t.TempDir()
|
||||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
}{
|
||||
{name: "unknown field", json: `{"version":"test","unexpected":true}`},
|
||||
{name: "trailing document", json: `{"version":"test"} {}`},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
path := filepath.Join(directory, test.name+".json")
|
||||
if err := os.WriteFile(path, []byte(test.json), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := readImport(path); err == nil {
|
||||
t.Fatal("expected strict JSON error")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user