Skip to content

Commit 7d4cd60

Browse files
committed
feat: container pause/unpause
Signed-off-by: thediveo <thediveo@gmx.eu>
1 parent 47b1c82 commit 7d4cd60

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
![build and test](https://github.com/thediveo/morbyd/actions/workflows/buildandtest.yaml/badge.svg?branch=master)
88
![goroutines](https://img.shields.io/badge/go%20routines-not%20leaking-success)
99
[![Go Report Card](https://goreportcard.com/badge/github.com/thediveo/morbyd)](https://goreportcard.com/report/github.com/thediveo/morbyd)
10-
![Coverage](https://img.shields.io/badge/Coverage-98.7%25-brightgreen)
10+
![Coverage](https://img.shields.io/badge/Coverage-98.6%25-brightgreen)
1111

1212
`morbyd` is a thin layer on top of the standard Docker Go client to easily build
1313
and run throw-away test Docker images and containers. And to easily run commands

container.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ func (c *Container) PID(ctx context.Context) (int, error) {
135135
}
136136
}
137137

138+
// Pause the container.
139+
func (c *Container) Pause(ctx context.Context) error {
140+
return c.Session.moby.ContainerPause(ctx, c.ID)
141+
}
142+
143+
// Unpause the container.
144+
func (c *Container) Unpause(ctx context.Context) error {
145+
return c.Session.moby.ContainerUnpause(ctx, c.ID)
146+
}
147+
138148
// Stop the container by sending it a termination signal. Default is SIGTERM,
139149
// unless changed using [run.WithStopSignal].
140150
func (c *Container) Stop(ctx context.Context) {

container_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ var _ = Describe("containers", Ordered, func() {
5757
Expect(time.Since(start)).To(BeNumerically(">=", 4*time.Second))
5858
})
5959

60+
It("pauses and unpauses a container", func(ctx context.Context) {
61+
cntr := Successful(sess.Run(ctx, "busybox",
62+
run.WithCommand("/bin/sh", "-c", "while true; do sleep 1; done"),
63+
run.WithAutoRemove(),
64+
run.WithCombinedOutput(timestamper.New(GinkgoWriter)),
65+
))
66+
Expect(cntr.PID(ctx)).Error().NotTo(HaveOccurred())
67+
68+
Expect(cntr.Pause(ctx)).To(Succeed())
69+
Expect(cntr.Refresh(ctx)).To(Succeed())
70+
Expect(cntr.Details.State.Paused).To(BeTrue())
71+
72+
Expect(cntr.Unpause(ctx)).To(Succeed())
73+
Expect(cntr.Refresh(ctx)).To(Succeed())
74+
Expect(cntr.Details.State.Paused).To(BeFalse())
75+
})
76+
6077
It("stops a container cooperatively", func(ctx context.Context) {
6178
var buff safe.Buffer
6279

0 commit comments

Comments
 (0)