pi-agent: Implement contextual Target actions
This commit is contained in:
@@ -16,6 +16,7 @@ type fakeTarget struct {
|
||||
available bool
|
||||
state target.State
|
||||
setErr error
|
||||
setState target.State
|
||||
confirmation string
|
||||
calls []bool
|
||||
}
|
||||
@@ -34,7 +35,9 @@ func (f *fakeTarget) Confirmation(bool) string { return f.confirmation }
|
||||
func (f *fakeTarget) SetDesired(_ context.Context, enabled bool, _ *profile.Profile) target.OperationResult {
|
||||
f.calls = append(f.calls, enabled)
|
||||
if f.setErr == nil {
|
||||
if enabled {
|
||||
if f.setState != "" {
|
||||
f.state = f.setState
|
||||
} else if enabled {
|
||||
f.state = target.Enabled
|
||||
} else {
|
||||
f.state = target.Disabled
|
||||
@@ -84,11 +87,11 @@ func TestApplicationRequiresTargetConfirmationBeforeMutation(t *testing.T) {
|
||||
}
|
||||
createAndActivate(t, application)
|
||||
|
||||
warning := application.Dispatch(app.Intent{Kind: app.SetTargetDesired, TargetID: "docker-daemon", Enabled: true})
|
||||
warning := application.Dispatch(app.Intent{Kind: app.EnableTarget, TargetID: "docker-daemon"})
|
||||
if warning.ConfirmationRequest == nil || warning.Err != nil || len(adapter.calls) != 0 || warning.Snapshot.Targets[0].State != target.Disabled {
|
||||
t.Fatalf("unconfirmed result = %#v, calls=%v", warning, adapter.calls)
|
||||
}
|
||||
confirmed := application.Dispatch(app.Intent{Kind: app.SetTargetDesired, TargetID: "docker-daemon", Enabled: true, Confirm: true})
|
||||
confirmed := application.Dispatch(app.Intent{Kind: app.EnableTarget, TargetID: "docker-daemon", Confirm: true})
|
||||
if confirmed.Err != nil || len(adapter.calls) != 1 || confirmed.Snapshot.Targets[0].State != target.Enabled {
|
||||
t.Fatalf("confirmed result = %#v, calls=%v", confirmed, adapter.calls)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user