Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DeleteMachine call outside Eventually block in integration tests #232

Closed
wants to merge 9 commits into from
12 changes: 7 additions & 5 deletions provider/server/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ var _ = Describe("Exec", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_annotations_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ var _ = Describe("UpdateMachineAnnotations", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be simplified:

Suggested change
}).Should(Succeed())
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
return err
}).Should(Succeed())

This eliminates the need for the additional Gomega argument as well. Please update other occurrences accordingly.

Copy link
Contributor

@lukas016 lukas016 Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are benefits? it looks more as cosmetic change. both solution are valid for gomega and this solution is more similar another eventually blocks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality remains the same, but this approach offers advantages in terms of:

Readability: It explicitly conveys that the DeleteMachine call is expected to eventually succeed, eliminating the need for an additional Expect statement.

Clarity: Using Eventually(func() error { ... }).Should(Succeed()) directly signifies the expectation that an operation will ultimately succeed, avoiding the need for explicit error handling within the function.

However, this approach is optional and may vary based on preference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will implement it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
36 changes: 16 additions & 20 deletions provider/server/machine_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ var _ = Describe("CreateMachine", func() {
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down Expand Up @@ -159,12 +158,11 @@ var _ = Describe("CreateMachine", func() {
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down Expand Up @@ -276,12 +274,11 @@ var _ = Describe("CreateMachine", func() {
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down Expand Up @@ -407,12 +404,11 @@ var _ = Describe("CreateMachine", func() {
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ var _ = Describe("ListMachine", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_networkinterface_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ var _ = Describe("AttachNetworkInterface", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_networkinterface_detach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ var _ = Describe("DetachNetworkInterface", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_powerstate_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ var _ = Describe("UpdateMachinePower", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_volume_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ var _ = Describe("AttachVolume", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
9 changes: 4 additions & 5 deletions provider/server/machine_volume_detach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ var _ = Describe("DetachVolume", func() {
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
Eventually(func() error {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
return err
}).Should(Succeed())
Eventually(func() bool {
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
Expand Down
Loading