From e78704fec61e338212d8de4814d42b86f0dab615 Mon Sep 17 00:00:00 2001 From: thediveo Date: Mon, 24 Jun 2024 21:02:13 +0200 Subject: [PATCH] refact: use individual autocleaning label values Signed-off-by: thediveo --- container_exec_test.go | 2 +- container_ip_test.go | 2 +- container_pid_test.go | 2 +- container_published_port_test.go | 2 +- container_run_test.go | 2 +- container_test.go | 2 +- container_wait_test.go | 8 +-- example_container_exec_test.go | 2 +- example_container_published_port_test.go | 2 +- example_session_network_test.go | 2 +- example_session_run_test.go | 2 +- image_build_test.go | 2 +- image_has_test.go | 64 +++++++++++++----------- network_create_test.go | 4 +- 14 files changed, 52 insertions(+), 46 deletions(-) diff --git a/container_exec_test.go b/container_exec_test.go index 223324b..094861a 100644 --- a/container_exec_test.go +++ b/container_exec_test.go @@ -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) }) diff --git a/container_ip_test.go b/container_ip_test.go index a2d217f..7c4b46b 100644 --- a/container_ip_test.go +++ b/container_ip_test.go @@ -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) }) diff --git a/container_pid_test.go b/container_pid_test.go index 8826c56..b7a3b0c 100644 --- a/container_pid_test.go +++ b/container_pid_test.go @@ -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") diff --git a/container_published_port_test.go b/container_published_port_test.go index 601c451..ca5df64 100644 --- a/container_published_port_test.go +++ b/container_published_port_test.go @@ -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") diff --git a/container_run_test.go b/container_run_test.go index f3039d1..c35585d 100644 --- a/container_run_test.go +++ b/container_run_test.go @@ -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) }) diff --git a/container_test.go b/container_test.go index 40a542f..f5907cd 100644 --- a/container_test.go +++ b/container_test.go @@ -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) }) diff --git a/container_wait_test.go b/container_wait_test.go index 52c2f0d..a112bfc 100644 --- a/container_wait_test.go +++ b/container_wait_test.go @@ -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") @@ -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`)))) }) }) diff --git a/example_container_exec_test.go b/example_container_exec_test.go index 79d58c7..9931c05 100644 --- a/example_container_exec_test.go +++ b/example_container_exec_test.go @@ -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) } diff --git a/example_container_published_port_test.go b/example_container_published_port_test.go index 105c28c..963ff2d 100644 --- a/example_container_published_port_test.go +++ b/example_container_published_port_test.go @@ -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) } diff --git a/example_session_network_test.go b/example_session_network_test.go index 1661102..c341c49 100644 --- a/example_session_network_test.go +++ b/example_session_network_test.go @@ -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) } diff --git a/example_session_run_test.go b/example_session_run_test.go index 475dbec..c801e5f 100644 --- a/example_session_run_test.go +++ b/example_session_run_test.go @@ -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) } diff --git a/image_build_test.go b/image_build_test.go index e535db0..973d6eb 100644 --- a/image_build_test.go +++ b/image_build_test.go @@ -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. diff --git a/image_has_test.go b/image_has_test.go index 81da460..a8ac0e6 100644 --- a/image_has_test.go +++ b/image_has_test.go @@ -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()) }) }) diff --git a/network_create_test.go b/network_create_test.go index 192351e..ae71fa0 100644 --- a/network_create_test.go +++ b/network_create_test.go @@ -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) }) @@ -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) })