mirror of
https://github.com/docker/compose.git
synced 2026-05-13 13:58:02 +00:00
publish: return ErrPublishAborted when user declines interactive prompts
Signed-off-by: Ishwar <ishwarcm@iitbhilai.ac.in>
This commit is contained in:
parent
73d8a6d57d
commit
9c5fd50989
2 changed files with 61 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue