Skip to content

Commit 61e9102

Browse files
committed
publish: return ErrPublishAborted when user declines interactive prompts
Signed-off-by: Ishwar <ishwarcm@iitbhilai.ac.in>
1 parent 3d2d03c commit 61e9102

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

pkg/compose/publish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s *composeService) publish(ctx context.Context, project *types.Project, re
5959
return err
6060
}
6161
if !accept {
62-
return nil
62+
return api.ErrCanceled
6363
}
6464
err = s.Push(ctx, project, api.PushOptions{IgnoreFailures: true, ImageMandatory: true})
6565
if err != nil {

pkg/compose/publish_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package compose
1818

1919
import (
20+
"errors"
2021
"slices"
2122
"testing"
2223

@@ -100,3 +101,62 @@ services:
100101
return !slices.Contains([]string{".Data", ".Digest", ".Size"}, path.String())
101102
}, cmp.Ignore()))
102103
}
104+
105+
func Test_preChecks_decline_returns_ErrPublishAborted(t *testing.T) {
106+
project := &types.Project{
107+
Services: types.Services{
108+
"web": {
109+
Name: "web",
110+
Image: "nginx",
111+
Volumes: []types.ServiceVolumeConfig{
112+
{
113+
Type: types.VolumeTypeBind,
114+
Source: "/host/path",
115+
Target: "/container/path",
116+
},
117+
},
118+
},
119+
},
120+
}
121+
122+
declined := func(message string, defaultValue bool) (bool, error) {
123+
return false, nil
124+
}
125+
svc := &composeService{
126+
prompt: declined,
127+
}
128+
129+
accept, err := svc.preChecks(t.Context(), project, api.PublishOptions{})
130+
assert.NilError(t, err)
131+
assert.Equal(t, accept, false)
132+
}
133+
134+
func Test_publish_decline_returns_ErrCanceled(t *testing.T) {
135+
project := &types.Project{
136+
Services: types.Services{
137+
"web": {
138+
Name: "web",
139+
Image: "nginx",
140+
Volumes: []types.ServiceVolumeConfig{
141+
{
142+
Type: types.VolumeTypeBind,
143+
Source: "/host/path",
144+
Target: "/container/path",
145+
},
146+
},
147+
},
148+
},
149+
}
150+
151+
declined := func(message string, defaultValue bool) (bool, error) {
152+
return false, nil
153+
}
154+
svc := &composeService{
155+
prompt: declined,
156+
events: &ignore{},
157+
}
158+
159+
err := svc.publish(t.Context(), project, "docker.io/myorg/myapp:latest", api.PublishOptions{})
160+
assert.Assert(t, errors.Is(err, api.ErrCanceled),
161+
"expected api.ErrCanceled when user declines, got: %v", err)
162+
}

0 commit comments

Comments
 (0)