From 93cbe735d32e1a45633d818a4568f61c91f0c14c Mon Sep 17 00:00:00 2001 From: felix h Date: Thu, 27 Aug 2026 12:16:49 +0200 Subject: [PATCH] fix(compose): report EventProcessor success correctly Signed-off-by: felix h --- pkg/compose/progress.go | 2 +- pkg/compose/progress_test.go | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 pkg/compose/progress_test.go diff --git a/pkg/compose/progress.go b/pkg/compose/progress.go index 7defdf2e55d..cff5613b711 100644 --- a/pkg/compose/progress.go +++ b/pkg/compose/progress.go @@ -28,7 +28,7 @@ type progressFunc func(context.Context) error func Run(ctx context.Context, pf progressFunc, operation string, bus api.EventProcessor) error { bus.Start(ctx, operation) err := pf(ctx) - bus.Done(operation, err != nil) + bus.Done(operation, err == nil) return err } diff --git a/pkg/compose/progress_test.go b/pkg/compose/progress_test.go new file mode 100644 index 00000000000..0706377a391 --- /dev/null +++ b/pkg/compose/progress_test.go @@ -0,0 +1,66 @@ +/* + Copyright 2020 Docker Compose CLI authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package compose + +import ( + "context" + "errors" + "testing" + + "gotest.tools/v3/assert" + + "github.com/docker/compose/v5/pkg/api" +) + +type runEventProcessor struct { + operation string + success bool +} + +func (r *runEventProcessor) Start(context.Context, string) {} + +func (r *runEventProcessor) On(...api.Resource) {} + +func (r *runEventProcessor) Done(operation string, success bool) { + r.operation = operation + r.success = success +} + +func TestRunReportsSuccess(t *testing.T) { + processor := &runEventProcessor{} + + err := Run(t.Context(), func(context.Context) error { + return nil + }, "test", processor) + + assert.NilError(t, err) + assert.Equal(t, processor.operation, "test") + assert.Check(t, processor.success) +} + +func TestRunReportsFailure(t *testing.T) { + expected := errors.New("test failure") + processor := &runEventProcessor{} + + err := Run(t.Context(), func(context.Context) error { + return expected + }, "test", processor) + + assert.ErrorIs(t, err, expected) + assert.Equal(t, processor.operation, "test") + assert.Check(t, !processor.success) +}