publish: return ErrPublishAborted when user declines interactive prompts

Signed-off-by: Ishwar <ishwarcm@iitbhilai.ac.in>
This commit is contained in:
Ishwar 2026-03-26 15:46:19 +05:30 committed by Guillaume Lours
parent 73d8a6d57d
commit 9c5fd50989
2 changed files with 61 additions and 1 deletions

View file

@ -59,7 +59,7 @@ func (s *composeService) publish(ctx context.Context, project *types.Project, re
return err
}
if !accept {
return nil
return api.ErrCanceled
}
err = s.Push(ctx, project, api.PushOptions{IgnoreFailures: true, ImageMandatory: true})
if err != nil {

View file

@ -17,6 +17,7 @@
package compose
import (
"errors"
"slices"
"testing"
@ -100,3 +101,62 @@ services:
return !slices.Contains([]string{".Data", ".Digest", ".Size"}, path.String())
}, cmp.Ignore()))
}
func Test_preChecks_decline_returns_ErrPublishAborted(t *testing.T) {
project := &types.Project{
Services: types.Services{
"web": {
Name: "web",
Image: "nginx",
Volumes: []types.ServiceVolumeConfig{
{
Type: types.VolumeTypeBind,
Source: "/host/path",
Target: "/container/path",
},
},
},
},
}
declined := func(message string, defaultValue bool) (bool, error) {
return false, nil
}
svc := &composeService{
prompt: declined,
}
accept, err := svc.preChecks(t.Context(), project, api.PublishOptions{})
assert.NilError(t, err)
assert.Equal(t, accept, false)
}
func Test_publish_decline_returns_ErrCanceled(t *testing.T) {
project := &types.Project{
Services: types.Services{
"web": {
Name: "web",
Image: "nginx",
Volumes: []types.ServiceVolumeConfig{
{
Type: types.VolumeTypeBind,
Source: "/host/path",
Target: "/container/path",
},
},
},
},
}
declined := func(message string, defaultValue bool) (bool, error) {
return false, nil
}
svc := &composeService{
prompt: declined,
events: &ignore{},
}
err := svc.publish(t.Context(), project, "docker.io/myorg/myapp:latest", api.PublishOptions{})
assert.Assert(t, errors.Is(err, api.ErrCanceled),
"expected api.ErrCanceled when user declines, got: %v", err)
}