Skip to content

Commit

Permalink
refact: use individual autocleaning label values
Browse files Browse the repository at this point in the history
Signed-off-by: thediveo <[email protected]>
  • Loading branch information
thediveo committed Jun 24, 2024
1 parent d03d65e commit e78704f
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 46 deletions.
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
2 changes: 1 addition & 1 deletion container_pid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ var _ = Describe("getting container PIDs", Ordered, func() {
Context("handling a failed container", func() {

It("doesn't wait endless for PID of failed container", func(ctx context.Context) {
sess := Successful(NewSession(ctx, session.WithAutoCleaning("test.morbid=pid")))
sess := Successful(NewSession(ctx, session.WithAutoCleaning("test.morbid=container.pid")))
DeferCleanup(func(ctx context.Context) { sess.Close(ctx) })

By("creating a crashed container")
Expand Down
2 changes: 1 addition & 1 deletion container_published_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = Describe("published container ports", Ordered, func() {

It("publishes container ports and talks to them", func(ctx context.Context) {
sess := Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=container.port")))
DeferCleanup(func(ctx context.Context) { sess.Close(ctx) })

By("spinning up an http serving busybox with published ports")
Expand Down
2 changes: 1 addition & 1 deletion container_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var _ = Describe("run container", Ordered, func() {

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

BeforeAll(func(ctx context.Context) {
sess = Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=container")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
Expand Down
8 changes: 5 additions & 3 deletions container_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("waiting for a container to terminate", Ordered, func() {
})

It("doesn't wait endless for failed container", func(ctx context.Context) {
sess := Successful(NewSession(ctx, session.WithAutoCleaning("test.morbid=pid")))
sess := Successful(NewSession(ctx, session.WithAutoCleaning("test.morbid=container.wait")))
DeferCleanup(func(ctx context.Context) { sess.Close(ctx) })

By("creating a crashed container")
Expand All @@ -48,8 +48,10 @@ var _ = Describe("waiting for a container to terminate", Ordered, func() {
By("waiting for crashed container")
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
Expect(cntr.Wait(ctx)).To(MatchError(
MatchRegexp(`waiting for container ".+"/[[:xdigit:]]+ to finish failed, .+ No such container`)))
Expect(cntr.Wait(ctx)).To(Or(
Succeed(),
MatchError(
MatchRegexp(`waiting for container ".+"/[[:xdigit:]]+ to finish failed, .+ No such container`))))
})

})
2 changes: 1 addition & 1 deletion example_container_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ExampleContainer_Exec() {
defer cancel()

sess, err := morbyd.NewSession(ctx,
session.WithAutoCleaning("test.morbyd="))
session.WithAutoCleaning("test.morbyd=example.container.exec"))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example_container_published_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ExampleContainer_PublishedPort() {
defer cancel()

sess, err := morbyd.NewSession(ctx,
session.WithAutoCleaning("test.morbyd="))
session.WithAutoCleaning("test.morbyd=example.container.port"))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example_session_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ExampleSession_CreateNetwork() {
defer cancel()

sess, err := morbyd.NewSession(ctx,
session.WithAutoCleaning("test.morbyd="))
session.WithAutoCleaning("test.morbyd=example.session.network"))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example_session_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ExampleSession_Run() {
defer cancel()

sess, err := morbyd.NewSession(ctx,
session.WithAutoCleaning("test.morbyd="))
session.WithAutoCleaning("test.morbyd=example.session.run"))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion image_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var _ = Describe("build image", Ordered, func() {

BeforeAll(func(ctx context.Context) {
sess = Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=image.build")))
DeferCleanup(func(ctx context.Context) {
// not strictly necessary as we're doing it anyway after each
// individual test in order to check for leaked go routines.
Expand Down
64 changes: 34 additions & 30 deletions image_has_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,48 @@ import (

var _ = Describe("image presence", Ordered, func() {

BeforeEach(func(ctx context.Context) {
goodgos := Goroutines()
DeferCleanup(func() {
Eventually(Goroutines).Within(2 * time.Second).ProbeEvery(250 * time.Millisecond).
ShouldNot(HaveLeaked(goodgos))
Context("image presence checking", Ordered, func() {

BeforeEach(func(ctx context.Context) {
goodgos := Goroutines()
DeferCleanup(func() {
Eventually(Goroutines).Within(2 * time.Second).ProbeEvery(250 * time.Millisecond).
ShouldNot(HaveLeaked(goodgos))
})
})
})

It("reports whether an image is locally available", func(ctx context.Context) {
const imgref = "busybox:latestandgreatest"
It("reports whether an image is locally available", func(ctx context.Context) {
const imgref = "busybox:latestandgreatest"

ctrl := mock.NewController(GinkgoT())
sess := Successful(NewSession(ctx,
WithMockController(ctrl, "ImageList")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
ctrl := mock.NewController(GinkgoT())
sess := Successful(NewSession(ctx,
WithMockController(ctrl, "ImageList")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
rec := sess.Client().(*MockClient).EXPECT()
rec.ImageList(Any, Any).Return([]image.Summary{}, nil)
rec.ImageList(Any, Any).Return([]image.Summary{
{ /*doesn't matter what, just needs to exist*/ },
}, nil)

Expect(sess.HasImage(ctx, imgref)).To(BeFalse())
Expect(sess.HasImage(ctx, imgref)).To(BeTrue())
})
rec := sess.Client().(*MockClient).EXPECT()
rec.ImageList(Any, Any).Return([]image.Summary{}, nil)
rec.ImageList(Any, Any).Return([]image.Summary{
{ /*doesn't matter what, just needs to exist*/ },
}, nil)

Expect(sess.HasImage(ctx, imgref)).To(BeFalse())
Expect(sess.HasImage(ctx, imgref)).To(BeTrue())
})
It("reports image listing errors", func(ctx context.Context) {
ctrl := mock.NewController(GinkgoT())
sess := Successful(NewSession(ctx,
WithMockController(ctrl, "ImageList")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
rec := sess.Client().(*MockClient).EXPECT()
rec.ImageList(Any, Any).Return(nil, errors.New("error IJK305I"))

It("reports image listing errors", func(ctx context.Context) {
ctrl := mock.NewController(GinkgoT())
sess := Successful(NewSession(ctx,
WithMockController(ctrl, "ImageList")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
Expect(sess.HasImage(ctx, "busybox:absolutelygreatest")).Error().To(HaveOccurred())
})
rec := sess.Client().(*MockClient).EXPECT()
rec.ImageList(Any, Any).Return(nil, errors.New("error IJK305I"))

Expect(sess.HasImage(ctx, "busybox:absolutelygreatest")).Error().To(HaveOccurred())
})

})
4 changes: 2 additions & 2 deletions network_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("creating custom networks", Ordered, func() {

It("rejects invalid options", func(ctx context.Context) {
sess := Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=network.create.invopt")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
Expand All @@ -58,7 +58,7 @@ var _ = Describe("creating custom networks", Ordered, func() {
const name = "morbyd-custom-bridge-network"

sess := Successful(NewSession(ctx,
session.WithAutoCleaning("test.morbyd=")))
session.WithAutoCleaning("test.morbyd=network.create.customnet")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
})
Expand Down

0 comments on commit e78704f

Please sign in to comment.