Include available choices in unknown scope diagnostics
This commit is contained in:
@@ -255,3 +255,32 @@ func TestRequiredConfigSelectorOnlyAppliesToSelectedScopes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknownConfigScopeReportsChoicesWithoutRuntimeWork(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
names []string
|
||||
scope []string
|
||||
choices string
|
||||
}{
|
||||
{[]string{"promptkit"}, nil, "available: promptkit"},
|
||||
{[]string{"zeta", "alpha", "promptkit", "app"}, []string{"--scope", "unknown"}, "available: app, promptkit, alpha, zeta"},
|
||||
} {
|
||||
runtimeCalls := 0
|
||||
suite := ConfigSuite[struct{}]{NewContext: func() struct{} { runtimeCalls++; return struct{}{} }}
|
||||
for _, name := range tc.names {
|
||||
suite.Scopes = append(suite.Scopes, ConfigScope[struct{}]{Name: name, Operations: []ConfigOperation{ConfigValidate}, Acquire: func(context.Context, ConfigRequest, struct{}) (Acquired[ConfigView], error) {
|
||||
runtimeCalls++
|
||||
return Acquired[ConfigView]{}, nil
|
||||
}})
|
||||
}
|
||||
app, _ := New(Identity{Name: "example"})
|
||||
if err := RegisterConfig(app, suite); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var out, diagnostics bytes.Buffer
|
||||
result := app.Execute(context.Background(), append([]string{"config", "validate"}, tc.scope...), Streams{Out: &out, Err: &diagnostics})
|
||||
if result.Kind != OutcomeUsage || runtimeCalls != 0 || out.Len() != 0 || !strings.Contains(diagnostics.String(), tc.choices) {
|
||||
t.Fatalf("result=%#v calls=%d out=%q diagnostics=%q", result, runtimeCalls, out.String(), diagnostics.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user