-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Draft * Add mocks generated by mockery * Add tests for common docker util * Remove comments to pass the lint errors * Add back test for ContainerWait * Cast return values * Add tests for error scenarios * Separate out docker interface and add file to codecov ignore * Use error object for testing * Pass dummy flag and mount directory * Add test for error * Add pypi client invalid host failure test * Check error contains substring * Add more tests for error returns * Fix test runs * Address @neel-astro's comments
- Loading branch information
1 parent
d5ba8ec
commit 581cf8b
Showing
11 changed files
with
481 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
--- | ||
ignore: | ||
- "sql/docker_interface.go" | ||
coverage: | ||
range: 85..100 | ||
round: down | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package sql | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/api/types/network" | ||
"github.com/docker/docker/client" | ||
specs "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
type DockerBinder struct { | ||
cli *client.Client | ||
} | ||
|
||
type DockerBind interface { | ||
ImageBuild(ctx context.Context, buildContext io.Reader, options *types.ImageBuildOptions) (types.ImageBuildResponse, error) | ||
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.ContainerCreateCreatedBody, error) | ||
ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error | ||
ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error) | ||
ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) | ||
} | ||
|
||
func (d DockerBinder) ImageBuild(ctx context.Context, buildContext io.Reader, options *types.ImageBuildOptions) (types.ImageBuildResponse, error) { | ||
return d.cli.ImageBuild(ctx, buildContext, *options) | ||
} | ||
|
||
func (d DockerBinder) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.ContainerCreateCreatedBody, error) { | ||
return d.cli.ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, containerName) | ||
} | ||
|
||
func (d DockerBinder) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error { | ||
return d.cli.ContainerStart(ctx, containerID, options) | ||
} | ||
|
||
func (d DockerBinder) ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (body <-chan container.ContainerWaitOKBody, err <-chan error) { | ||
return d.cli.ContainerWait(ctx, containerID, condition) | ||
} | ||
|
||
func (d DockerBinder) ContainerLogs(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error) { | ||
return d.cli.ContainerLogs(ctx, containerID, options) | ||
} | ||
|
||
func NewDockerClient() (DockerBind, error) { | ||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DockerBinder{cli: cli}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestArgNotSetError(t *testing.T) { | ||
errorMessage := ArgNotSetError("sample_argument") | ||
expectedErrorMesssage := "argument not set:sample_argument" | ||
assert.EqualError(t, errorMessage, expectedErrorMesssage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.