|
| 1 | +package dockerfake |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "io" |
| 6 | + "strings" |
| 7 | + |
| 8 | + "github.com/docker/docker/api/types" |
| 9 | + dockertypes "github.com/docker/docker/api/types" |
| 10 | + containertypes "github.com/docker/docker/api/types/container" |
| 11 | + "github.com/docker/docker/api/types/events" |
| 12 | + "github.com/docker/docker/api/types/filters" |
| 13 | + "github.com/docker/docker/api/types/image" |
| 14 | + networktypes "github.com/docker/docker/api/types/network" |
| 15 | + "github.com/docker/docker/api/types/registry" |
| 16 | + "github.com/docker/docker/api/types/system" |
| 17 | + specs "github.com/opencontainers/image-spec/specs-go/v1" |
| 18 | + |
| 19 | + "github.com/coder/envbox/dockerutil" |
| 20 | +) |
| 21 | + |
| 22 | +var _ dockerutil.DockerClient = MockClient{} |
| 23 | + |
| 24 | +// MockClient provides overrides for functions that are called in envbox. |
| 25 | +type MockClient struct { |
| 26 | + ImagePullFn func(_ context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) |
| 27 | + ContainerCreateFn func(_ context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, _ *specs.Platform, containerName string) (containertypes.CreateResponse, error) |
| 28 | + ImagePruneFn func(_ context.Context, pruneFilter filters.Args) (dockertypes.ImagesPruneReport, error) |
| 29 | + ContainerStartFn func(_ context.Context, container string, options containertypes.StartOptions) error |
| 30 | + ContainerExecAttachFn func(_ context.Context, execID string, config dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error) |
| 31 | + ContainerExecCreateFn func(_ context.Context, container string, config dockertypes.ExecConfig) (dockertypes.IDResponse, error) |
| 32 | + ContainerExecStartFn func(_ context.Context, execID string, config dockertypes.ExecStartCheck) error |
| 33 | + ContainerExecInspectFn func(_ context.Context, execID string) (dockertypes.ContainerExecInspect, error) |
| 34 | + ContainerInspectFn func(_ context.Context, container string) (dockertypes.ContainerJSON, error) |
| 35 | + ContainerRemoveFn func(_ context.Context, container string, options containertypes.RemoveOptions) error |
| 36 | + PingFn func(_ context.Context) (dockertypes.Ping, error) |
| 37 | +} |
| 38 | + |
| 39 | +func (MockClient) ImageBuild(_ context.Context, _ io.Reader, _ dockertypes.ImageBuildOptions) (dockertypes.ImageBuildResponse, error) { |
| 40 | + panic("not implemented") |
| 41 | +} |
| 42 | + |
| 43 | +func (MockClient) BuildCachePrune(_ context.Context, _ dockertypes.BuildCachePruneOptions) (*dockertypes.BuildCachePruneReport, error) { |
| 44 | + panic("not implemented") |
| 45 | +} |
| 46 | + |
| 47 | +func (MockClient) BuildCancel(_ context.Context, _ string) error { |
| 48 | + panic("not implemented") |
| 49 | +} |
| 50 | + |
| 51 | +func (MockClient) ImageCreate(_ context.Context, _ string, _ image.CreateOptions) (io.ReadCloser, error) { |
| 52 | + panic("not implemented") |
| 53 | +} |
| 54 | + |
| 55 | +func (MockClient) ImageHistory(_ context.Context, _ string) ([]image.HistoryResponseItem, error) { |
| 56 | + panic("not implemented") |
| 57 | +} |
| 58 | + |
| 59 | +func (MockClient) ImageImport(_ context.Context, _ image.ImportSource, _ string, _ image.ImportOptions) (io.ReadCloser, error) { |
| 60 | + panic("not implemented") |
| 61 | +} |
| 62 | + |
| 63 | +func (MockClient) ImageInspectWithRaw(_ context.Context, _ string) (dockertypes.ImageInspect, []byte, error) { |
| 64 | + panic("not implemented") |
| 65 | +} |
| 66 | + |
| 67 | +func (MockClient) ImageList(_ context.Context, _ image.ListOptions) ([]image.Summary, error) { |
| 68 | + panic("not implemented") |
| 69 | +} |
| 70 | + |
| 71 | +func (MockClient) ImageLoad(_ context.Context, _ io.Reader, _ bool) (dockertypes.ImageLoadResponse, error) { |
| 72 | + panic("not implemented") |
| 73 | +} |
| 74 | + |
| 75 | +func (m MockClient) ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) { |
| 76 | + if m.ImagePullFn == nil { |
| 77 | + return io.NopCloser(strings.NewReader("")), nil |
| 78 | + } |
| 79 | + return m.ImagePullFn(ctx, ref, options) |
| 80 | +} |
| 81 | + |
| 82 | +func (MockClient) ImagePush(_ context.Context, _ string, _ image.PushOptions) (io.ReadCloser, error) { |
| 83 | + panic("not implemented") |
| 84 | +} |
| 85 | + |
| 86 | +func (MockClient) ImageRemove(_ context.Context, _ string, _ image.RemoveOptions) ([]image.DeleteResponse, error) { |
| 87 | + panic("not implemented") |
| 88 | +} |
| 89 | + |
| 90 | +func (MockClient) ImageSearch(_ context.Context, _ string, _ dockertypes.ImageSearchOptions) ([]registry.SearchResult, error) { |
| 91 | + panic("not implemented") |
| 92 | +} |
| 93 | + |
| 94 | +func (MockClient) ImageSave(_ context.Context, _ []string) (io.ReadCloser, error) { |
| 95 | + panic("not implemented") |
| 96 | +} |
| 97 | + |
| 98 | +func (MockClient) ImageTag(_ context.Context, _ string, _ string) error { |
| 99 | + panic("not implemented") |
| 100 | +} |
| 101 | + |
| 102 | +func (m MockClient) ImagesPrune(ctx context.Context, pruneFilter filters.Args) (dockertypes.ImagesPruneReport, error) { |
| 103 | + if m.ImagePruneFn == nil { |
| 104 | + return dockertypes.ImagesPruneReport{}, nil |
| 105 | + } |
| 106 | + return m.ImagePruneFn(ctx, pruneFilter) |
| 107 | +} |
| 108 | + |
| 109 | +func (MockClient) Events(_ context.Context, _ dockertypes.EventsOptions) (<-chan events.Message, <-chan error) { |
| 110 | + panic("not implemented") |
| 111 | +} |
| 112 | + |
| 113 | +func (MockClient) Info(_ context.Context) (system.Info, error) { |
| 114 | + panic("not implemented") |
| 115 | +} |
| 116 | + |
| 117 | +func (MockClient) RegistryLogin(_ context.Context, _ registry.AuthConfig) (registry.AuthenticateOKBody, error) { |
| 118 | + panic("not implemented") |
| 119 | +} |
| 120 | + |
| 121 | +func (MockClient) DiskUsage(_ context.Context, _ dockertypes.DiskUsageOptions) (dockertypes.DiskUsage, error) { |
| 122 | + panic("not implemented") |
| 123 | +} |
| 124 | + |
| 125 | +func (m MockClient) Ping(ctx context.Context) (dockertypes.Ping, error) { |
| 126 | + if m.PingFn == nil { |
| 127 | + return dockertypes.Ping{}, nil |
| 128 | + } |
| 129 | + return m.PingFn(ctx) |
| 130 | +} |
| 131 | + |
| 132 | +func (MockClient) ContainerAttach(_ context.Context, _ string, _ containertypes.AttachOptions) (dockertypes.HijackedResponse, error) { |
| 133 | + panic("not implemented") |
| 134 | +} |
| 135 | + |
| 136 | +func (MockClient) ContainerCommit(_ context.Context, _ string, _ containertypes.CommitOptions) (dockertypes.IDResponse, error) { |
| 137 | + panic("not implemented") |
| 138 | +} |
| 139 | + |
| 140 | +func (m MockClient) ContainerCreate(ctx context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, pspecs *specs.Platform, containerName string) (containertypes.CreateResponse, error) { |
| 141 | + if m.ContainerCreateFn == nil { |
| 142 | + return containertypes.CreateResponse{}, nil |
| 143 | + } |
| 144 | + return m.ContainerCreateFn(ctx, config, hostConfig, networkingConfig, pspecs, containerName) |
| 145 | +} |
| 146 | + |
| 147 | +func (MockClient) ContainerDiff(_ context.Context, _ string) ([]containertypes.FilesystemChange, error) { |
| 148 | + panic("not implemented") |
| 149 | +} |
| 150 | + |
| 151 | +func (m MockClient) ContainerExecAttach(ctx context.Context, execID string, config dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error) { |
| 152 | + if m.ContainerExecAttachFn == nil { |
| 153 | + return dockertypes.HijackedResponse{}, nil |
| 154 | + } |
| 155 | + return m.ContainerExecAttachFn(ctx, execID, config) |
| 156 | +} |
| 157 | + |
| 158 | +func (m MockClient) ContainerExecCreate(ctx context.Context, name string, config dockertypes.ExecConfig) (dockertypes.IDResponse, error) { |
| 159 | + if m.ContainerExecCreateFn == nil { |
| 160 | + return dockertypes.IDResponse{}, nil |
| 161 | + } |
| 162 | + return m.ContainerExecCreateFn(ctx, name, config) |
| 163 | +} |
| 164 | + |
| 165 | +func (m MockClient) ContainerExecInspect(ctx context.Context, id string) (dockertypes.ContainerExecInspect, error) { |
| 166 | + if m.ContainerExecInspectFn == nil { |
| 167 | + return dockertypes.ContainerExecInspect{}, nil |
| 168 | + } |
| 169 | + |
| 170 | + return m.ContainerExecInspectFn(ctx, id) |
| 171 | +} |
| 172 | + |
| 173 | +func (MockClient) ContainerExecResize(_ context.Context, _ string, _ containertypes.ResizeOptions) error { |
| 174 | + panic("not implemented") |
| 175 | +} |
| 176 | + |
| 177 | +func (m MockClient) ContainerExecStart(ctx context.Context, execID string, config dockertypes.ExecStartCheck) error { |
| 178 | + if m.ContainerExecStartFn == nil { |
| 179 | + return nil |
| 180 | + } |
| 181 | + return m.ContainerExecStartFn(ctx, execID, config) |
| 182 | +} |
| 183 | + |
| 184 | +func (MockClient) ContainerExport(_ context.Context, _ string) (io.ReadCloser, error) { |
| 185 | + panic("not implemented") |
| 186 | +} |
| 187 | + |
| 188 | +func (m MockClient) ContainerInspect(ctx context.Context, name string) (dockertypes.ContainerJSON, error) { |
| 189 | + if m.ContainerInspectFn == nil { |
| 190 | + return dockertypes.ContainerJSON{}, nil |
| 191 | + } |
| 192 | + return m.ContainerInspectFn(ctx, name) |
| 193 | +} |
| 194 | + |
| 195 | +func (MockClient) ContainerInspectWithRaw(_ context.Context, _ string, _ bool) (dockertypes.ContainerJSON, []byte, error) { |
| 196 | + panic("not implemented") |
| 197 | +} |
| 198 | + |
| 199 | +func (MockClient) ContainerKill(_ context.Context, _ string, _ string) error { |
| 200 | + panic("not implemented") |
| 201 | +} |
| 202 | + |
| 203 | +func (MockClient) ContainerList(_ context.Context, _ containertypes.ListOptions) ([]types.Container, error) { |
| 204 | + panic("not implemented") |
| 205 | +} |
| 206 | + |
| 207 | +func (MockClient) ContainerLogs(_ context.Context, _ string, _ containertypes.LogsOptions) (io.ReadCloser, error) { |
| 208 | + panic("not implemented") |
| 209 | +} |
| 210 | + |
| 211 | +func (MockClient) ContainerPause(_ context.Context, _ string) error { |
| 212 | + panic("not implemented") |
| 213 | +} |
| 214 | + |
| 215 | +func (m MockClient) ContainerRemove(ctx context.Context, name string, options containertypes.RemoveOptions) error { |
| 216 | + if m.ContainerRemoveFn == nil { |
| 217 | + return nil |
| 218 | + } |
| 219 | + return m.ContainerRemoveFn(ctx, name, options) |
| 220 | +} |
| 221 | + |
| 222 | +func (MockClient) ContainerRename(_ context.Context, _ string, _ string) error { |
| 223 | + panic("not implemented") |
| 224 | +} |
| 225 | + |
| 226 | +func (MockClient) ContainerResize(_ context.Context, _ string, _ containertypes.ResizeOptions) error { |
| 227 | + panic("not implemented") |
| 228 | +} |
| 229 | + |
| 230 | +func (MockClient) ContainerRestart(_ context.Context, _ string, _ containertypes.StopOptions) error { |
| 231 | + panic("not implemented") |
| 232 | +} |
| 233 | + |
| 234 | +func (MockClient) ContainerStatPath(_ context.Context, _ string, _ string) (dockertypes.ContainerPathStat, error) { |
| 235 | + panic("not implemented") |
| 236 | +} |
| 237 | + |
| 238 | +func (MockClient) ContainerStats(_ context.Context, _ string, _ bool) (dockertypes.ContainerStats, error) { |
| 239 | + panic("not implemented") |
| 240 | +} |
| 241 | + |
| 242 | +func (m MockClient) ContainerStart(ctx context.Context, name string, options containertypes.StartOptions) error { |
| 243 | + if m.ContainerStartFn == nil { |
| 244 | + return nil |
| 245 | + } |
| 246 | + return m.ContainerStartFn(ctx, name, options) |
| 247 | +} |
| 248 | + |
| 249 | +func (MockClient) ContainerStop(_ context.Context, _ string, _ containertypes.StopOptions) error { |
| 250 | + panic("not implemented") |
| 251 | +} |
| 252 | + |
| 253 | +func (MockClient) ContainerTop(_ context.Context, _ string, _ []string) (containertypes.ContainerTopOKBody, error) { |
| 254 | + panic("not implemented") |
| 255 | +} |
| 256 | + |
| 257 | +func (MockClient) ContainerUnpause(_ context.Context, _ string) error { |
| 258 | + panic("not implemented") |
| 259 | +} |
| 260 | + |
| 261 | +func (MockClient) ContainerUpdate(_ context.Context, _ string, _ containertypes.UpdateConfig) (containertypes.ContainerUpdateOKBody, error) { |
| 262 | + panic("not implemented") |
| 263 | +} |
| 264 | + |
| 265 | +func (MockClient) ContainerWait(_ context.Context, _ string, _ containertypes.WaitCondition) (<-chan containertypes.WaitResponse, <-chan error) { |
| 266 | + panic("not implemented") |
| 267 | +} |
| 268 | + |
| 269 | +func (MockClient) CopyFromContainer(_ context.Context, _ string, _ string) (io.ReadCloser, dockertypes.ContainerPathStat, error) { |
| 270 | + panic("not implemented") |
| 271 | +} |
| 272 | + |
| 273 | +func (MockClient) CopyToContainer(_ context.Context, _ string, _ string, _ io.Reader, _ dockertypes.CopyToContainerOptions) error { |
| 274 | + panic("not implemented") |
| 275 | +} |
| 276 | + |
| 277 | +func (MockClient) ContainersPrune(_ context.Context, _ filters.Args) (dockertypes.ContainersPruneReport, error) { |
| 278 | + panic("not implemented") |
| 279 | +} |
| 280 | + |
| 281 | +func (MockClient) ContainerStatsOneShot(_ context.Context, _ string) (dockertypes.ContainerStats, error) { |
| 282 | + panic("not implemented") |
| 283 | +} |
0 commit comments