Verify typed alias composition in integrations
This commit is contained in:
@@ -225,6 +225,51 @@ func TestRequiredSelectorAppliesOnlyToItsSelectedScope(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigAliasesForwardSelectedTenantAndGlobalHelp(t *testing.T) {
|
||||
type input struct{ Tenant commandkit.Supplied[string] }
|
||||
flag := commandkit.ValueFlag(commandkit.FlagMeta{Name: "tenant"}, (*string)(nil),
|
||||
func(value string) (string, error) { return value, nil },
|
||||
func(target *input, value commandkit.Supplied[string]) { target.Tenant = value })
|
||||
var acquired []commandkit.Supplied[string]
|
||||
command := Command(Suite[input, struct{}]{
|
||||
Selectors: []Selector[input]{{Binding: flag, Scopes: []string{"promptkit"}}},
|
||||
Scopes: []Scope[input, struct{}]{
|
||||
{
|
||||
Name: "promptkit",
|
||||
Operations: []Operation{Validate},
|
||||
Acquire: func(_ context.Context, _ Request, value input, _ struct{}) (commandkit.Acquired[View], error) {
|
||||
acquired = append(acquired, value.Tenant)
|
||||
return commandkit.Acquired[View]{}, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
app, err := commandkit.New(commandkit.Identity{Name: "example"},
|
||||
command,
|
||||
commandkit.Alias("check-config", "config validate"),
|
||||
commandkit.FlagAliasFor("config validate", "--tenant-id", "--tenant"),
|
||||
commandkit.FlagAlias("--hlep", "--help"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var output bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"check-config", "--hlep"}, commandkit.Streams{Out: &output, Err: io.Discard})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || !strings.Contains(output.String(), "validate") || len(acquired) != 0 {
|
||||
t.Fatalf("global help alias outcome/output/acquisitions = (%#v, %q, %#v)", outcome, output.String(), acquired)
|
||||
}
|
||||
|
||||
outcome = app.Execute(context.Background(), []string{"check-config", "--scope", "promptkit", "--tenant-id=acme"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || len(acquired) != 1 || acquired[0] != (commandkit.Supplied[string]{Value: "acme", Set: true}) {
|
||||
t.Fatalf("aliased selector outcome/acquisitions = (%#v, %#v)", outcome, acquired)
|
||||
}
|
||||
outcome = app.Execute(context.Background(), []string{"config", "validate", "--scope", "promptkit", "--tenant=canonical"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || len(acquired) != 2 || acquired[1] != (commandkit.Supplied[string]{Value: "canonical", Set: true}) {
|
||||
t.Fatalf("canonical selector outcome/acquisitions = (%#v, %#v)", outcome, acquired)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShowAcquiresAllViewsBeforeRenderingAndFramesNativeYAML(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
var acquisitionOutputLengths []int
|
||||
|
||||
Reference in New Issue
Block a user