Skip to content

Commit

Permalink
ginkgo: rely on DeferCleanup
Browse files Browse the repository at this point in the history
Instead of using `AfterEach` blocks.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Nov 29, 2024
1 parent c2b65ab commit a2f19b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 3 additions & 4 deletions pkg/config/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ var _ = Describe("The dynamic network attachment configuration", func() {
Expect(err).NotTo(HaveOccurred())

Expect(os.MkdirAll(configurationDir, allowAllPermissions)).To(Succeed())
})

AfterEach(func() {
Expect(os.RemoveAll(configurationDir)).To(Succeed())
DeferCleanup(func() {
Expect(os.RemoveAll(configurationDir)).To(Succeed())
})
})

When("a valid configuration file is provided", func() {
Expand Down
12 changes: 4 additions & 8 deletions pkg/controller/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ var _ = Describe("Dynamic Attachment controller", func() {
Expect(os.WriteFile(
path.Join(cniConfigDir, multusConfigPath),
[]byte(dummyMultusConfig()), configFilePermissions)).To(Succeed())
})

AfterEach(func() {
Expect(os.RemoveAll(cniConfigDir)).To(Succeed())
DeferCleanup(func() {
Expect(os.RemoveAll(cniConfigDir)).To(Succeed())
})
})

Context("with an existing running pod", func() {
Expand Down Expand Up @@ -121,14 +120,11 @@ var _ = Describe("Dynamic Attachment controller", func() {
netAttachDef(networkToAdd1, namespace, dummyNetSpec(networkToAdd1, cniVersion)))
Expect(err).NotTo(HaveOccurred())
stopChannel = make(chan struct{})
DeferCleanup(func() { close(stopChannel) })
const maxEvents = 5
eventRecorder = record.NewFakeRecorder(maxEvents)
})

AfterEach(func() {
close(stopChannel)
})

JustBeforeEach(func() {
k8sClient = fake.NewSimpleClientset(pod)
Expect(
Expand Down

0 comments on commit a2f19b7

Please sign in to comment.