Skip to content

Commit

Permalink
tests, utils: Move CheckResultShellCommandOnVmi close to the caller
Browse files Browse the repository at this point in the history
The `utils.go` file is huge with a mix of unrelated helpers.

The function in question is used only by one test package,
therefore move it closer to where it is used.

Signed-off-by: Edward Haas <[email protected]>
  • Loading branch information
EdDev committed Dec 26, 2023
1 parent 71893af commit ff1ae23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 11 additions & 1 deletion tests/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ var _ = SIGDescribe("Storage", func() {

By("Writing to disk")
Expect(console.LoginToAlpine(vmi)).To(Succeed(), "Should login")
tests.CheckResultShellCommandOnVmi(vmi, "dd if=/dev/zero of=/dev/vdb",
checkResultShellCommandOnVmi(vmi, "dd if=/dev/zero of=/dev/vdb",
"dd: error writing '/dev/vdb': I/O error", 20)

cleanUp(vmi)
Expand Down Expand Up @@ -1369,3 +1369,13 @@ func newVMIWithEphemeralPVC(claimName string) *v1.VirtualMachineInstance {
})
return vmi
}

func checkResultShellCommandOnVmi(vmi *virtv1.VirtualMachineInstance, cmd, output string, timeout int) {
res, err := console.SafeExpectBatchWithResponse(vmi, []expect.Batcher{
&expect.BSnd{S: fmt.Sprintf("%s\n", cmd)},
&expect.BExp{R: console.PromptExpression},
}, timeout)
ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, res).ToNot(BeEmpty())
ExpectWithOffset(1, res[0].Output).To(ContainSubstring(output))
}
10 changes: 0 additions & 10 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2310,13 +2310,3 @@ func RenderTargetcliPod(name, disksPVC string) *k8sv1.Pod {
},
}
}

func CheckResultShellCommandOnVmi(vmi *v1.VirtualMachineInstance, cmd, output string, timeout int) {
res, err := console.SafeExpectBatchWithResponse(vmi, []expect.Batcher{
&expect.BSnd{S: fmt.Sprintf("%s\n", cmd)},
&expect.BExp{R: console.PromptExpression},
}, timeout)
ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, res).ToNot(BeEmpty())
ExpectWithOffset(1, res[0].Output).To(ContainSubstring(output))
}

0 comments on commit ff1ae23

Please sign in to comment.