Centralize output schema and module key validation catalogs
This commit is contained in:
@@ -31,15 +31,31 @@ var definitions = map[string]Definition{
|
||||
},
|
||||
}
|
||||
|
||||
var supportedKeys = []string{
|
||||
SchemaBareSegments,
|
||||
SchemaAuditaV1,
|
||||
}
|
||||
|
||||
func SupportedKeys() []string {
|
||||
out := make([]string, len(supportedKeys))
|
||||
copy(out, supportedKeys)
|
||||
return out
|
||||
}
|
||||
|
||||
func IsSupported(key string) bool {
|
||||
_, ok := definitions[strings.TrimSpace(key)]
|
||||
return ok
|
||||
}
|
||||
|
||||
func Resolve(key string) (Definition, error) {
|
||||
normalized := strings.TrimSpace(key)
|
||||
if normalized == "" {
|
||||
return Definition{}, fmt.Errorf("output schema must not be empty")
|
||||
}
|
||||
def, ok := definitions[normalized]
|
||||
if !ok {
|
||||
if !IsSupported(normalized) {
|
||||
return Definition{}, fmt.Errorf("unsupported output schema %q", normalized)
|
||||
}
|
||||
def := definitions[normalized]
|
||||
return def, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package outputschema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -56,3 +57,19 @@ func TestResolveUnknown(t *testing.T) {
|
||||
t.Fatalf("expected unsupported output schema error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportedKeysAndIsSupported(t *testing.T) {
|
||||
want := []string{SchemaBareSegments, SchemaAuditaV1}
|
||||
if got := SupportedKeys(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("unexpected supported schema keys: got=%v want=%v", got, want)
|
||||
}
|
||||
|
||||
for _, key := range want {
|
||||
if !IsSupported(key) {
|
||||
t.Fatalf("expected schema key %q to be supported", key)
|
||||
}
|
||||
}
|
||||
if IsSupported("seriatim-intermediate") {
|
||||
t.Fatalf("did not expect unsupported schema to be reported as supported")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user