|
17 | 17 | package compose |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "errors" |
20 | 21 | "slices" |
21 | 22 | "testing" |
22 | 23 |
|
@@ -100,3 +101,62 @@ services: |
100 | 101 | return !slices.Contains([]string{".Data", ".Digest", ".Size"}, path.String()) |
101 | 102 | }, cmp.Ignore())) |
102 | 103 | } |
| 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