Skip to content

Commit

Permalink
Merge pull request #9 from thediveo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
thediveo authored Jun 24, 2024
2 parents d74c5a2 + 68f0ff0 commit a4e4a3b
Show file tree
Hide file tree
Showing 22 changed files with 322 additions and 166 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
![build and test](https://github.com/thediveo/morbyd/workflows/build%20and%20test/badge.svg?branch=master)
![goroutines](https://img.shields.io/badge/go%20routines-not%20leaking-success)
[![Go Report Card](https://goreportcard.com/badge/github.com/thediveo/morbyd)](https://goreportcard.com/report/github.com/thediveo/morbyd)
![Coverage](https://img.shields.io/badge/Coverage-99.6%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-99.2%25-brightgreen)

`morbyd` is a thin layer on top of the standard Docker Go client to easily build
and run throw-away test Docker images and containers. And to easily run commands
Expand Down
48 changes: 45 additions & 3 deletions client_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,24 @@ func newWrappedClient(ctrl *mock.Controller, wrapped moby.Client, withouts []str
return wrapped.ContainerList(ctx, options)
})
}
if !slices.Contains(withouts, "ContainerPause") {
rec.ContainerPause(Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, containerID string) error {
return wrapped.ContainerPause(ctx, containerID)
})
}
if !slices.Contains(withouts, "ContainerRemove") {
rec.ContainerRemove(Any, Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, containerID string, options container.RemoveOptions) error {
return wrapped.ContainerRemove(ctx, containerID, options)
})
}
if !slices.Contains(withouts, "ContainerRestart") {
rec.ContainerRestart(Any, Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, containerID string, options container.StopOptions) error {
return wrapped.ContainerRestart(ctx, containerID, options)
})
}
if !slices.Contains(withouts, "ContainerStart") {
rec.ContainerStart(Any, Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, containerID string, options container.StartOptions) error {
Expand All @@ -104,6 +116,12 @@ func newWrappedClient(ctrl *mock.Controller, wrapped moby.Client, withouts []str
return wrapped.ContainerStop(ctx, containerID, options)
})
}
if !slices.Contains(withouts, "ContainerUnpause") {
rec.ContainerUnpause(Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, containerID string) error {
return wrapped.ContainerUnpause(ctx, containerID)
})
}
if !slices.Contains(withouts, "ContainerWait") {
rec.ContainerWait(Any, Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error) {
Expand Down Expand Up @@ -144,19 +162,19 @@ func newWrappedClient(ctrl *mock.Controller, wrapped moby.Client, withouts []str
}
if !slices.Contains(withouts, "ImageList") {
rec.ImageList(Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, options types.ImageListOptions) ([]image.Summary, error) {
DoAndReturn(func(ctx context.Context, options image.ListOptions) ([]image.Summary, error) {
return wrapped.ImageList(ctx, options)
})
}
if !slices.Contains(withouts, "ImagePull") {
rec.ImagePull(Any, Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error) {
DoAndReturn(func(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error) {
return wrapped.ImagePull(ctx, refStr, options)
})
}
if !slices.Contains(withouts, "ImageRemove") {
rec.ImageRemove(Any, Any, Any).AnyTimes().
DoAndReturn(func(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]image.DeleteResponse, error) {
DoAndReturn(func(ctx context.Context, imageID string, options image.RemoveOptions) ([]image.DeleteResponse, error) {
return wrapped.ImageRemove(ctx, imageID, options)
})
}
Expand Down
12 changes: 6 additions & 6 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func (c *Container) PID(ctx context.Context) (int, error) {
if inspRes.State != nil && inspRes.State.Pid != 0 {
return inspRes.State.Pid, nil
}
// We're either too early or too late, but we have to figure out,
// because we don't want to hang around any further if there is no
// chance of getting a PID in the near future...
// We're either too early or too late, but we have to figure out which
// one we're, because we don't want to hang around any further if there
// is no chance of getting a PID in the near future...
if inspRes.State != nil &&
((inspRes.State.Dead || inspRes.State.OOMKilled) &&
!inspRes.State.Restarting) {
Expand All @@ -146,8 +146,8 @@ func (c *Container) Stop(ctx context.Context) {
// [Docker's Client.ContainerWait]: https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerWait
func (c *Container) Wait(ctx context.Context) error {
// Nota bene: errch is buffered with size 1. The wait result channel is
// unbuffered though. ContainerWait EITHER sends an error OR on a result,
// never both. And it never sends a nil error, in particular.
// unbuffered though. ContainerWait EITHER sends an error OR a result, never
// both. And in consequence it never sends a nil error.
waitch, errch := c.Session.moby.ContainerWait(ctx, c.ID, container.WaitConditionNotRunning)
select {
case err := <-errch:
Expand Down Expand Up @@ -187,7 +187,7 @@ func (c *Container) AbbreviatedID() string {
// address string including port number can be determined as follows:
//
// // for instance, returns "127.0.0.1:32890"
// svcAddrPort := cntr.PublishedPort("1234").Any().UnspecifiedAsLoopback().String
// svcAddrPort := cntr.PublishedPort("1234").Any().UnspecifiedAsLoopback().String()
func (c *Container) PublishedPort(portproto string) Addrs {
if !strings.Contains(portproto, "/") {
portproto += "/tcp"
Expand Down
2 changes: 1 addition & 1 deletion container_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("execute command inside container", Ordered, func() {

BeforeEach(func(ctx context.Context) {
sess = Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=container.exec")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
Expand Down
2 changes: 1 addition & 1 deletion container_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var _ = Describe("getting container IPs", Ordered, func() {

It("returns a container's IP that we can talk to", func(ctx context.Context) {
sess := Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=container.ip")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
Expand Down
Loading

0 comments on commit a4e4a3b

Please sign in to comment.