Skip to content

Commit

Permalink
Hardcode expectedCommand variable
Browse files Browse the repository at this point in the history
Better testing of buildFenceAgentParams result
  • Loading branch information
razo7 committed Feb 28, 2023
1 parent 9cee882 commit 22ab7e9
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions controllers/fenceagentsremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ var _ = Describe("FAR Controller", func() {
underTestFAR = newFenceAgentsRemediation(validNodeName, " ", testShareParam, testNodeParam)
fenceAgentsPod := buildFarPod()

Context("Functionaility", func() {
When("testing buildFenceAgentParams", func() {
It("should fail when FAR's name isn't a node name", func() {
underTestFAR.ObjectMeta.Name = dummyNodeName
_, err := buildFenceAgentParams(underTestFAR)
Expect(err).To(HaveOccurred())
})
It("should succeed when FAR pod has been created", func() {
underTestFAR.ObjectMeta.Name = validNodeName
_, err := buildFenceAgentParams(underTestFAR)
Expect(err).NotTo(HaveOccurred())
Context("Functionality", func() {
Context("buildFenceAgentParams", func() {
When("FAR's name isn't a node name", func() {
It("should fail", func() {
underTestFAR.ObjectMeta.Name = dummyNodeName
_, err := buildFenceAgentParams(underTestFAR)
Expect(err).To(HaveOccurred())
})
It("should succeed", func() {
underTestFAR.ObjectMeta.Name = validNodeName
_, err := buildFenceAgentParams(underTestFAR)
Expect(err).NotTo(HaveOccurred())
})
})
})
When("creating a resource", func() {
Expand Down Expand Up @@ -140,15 +142,13 @@ func buildFarPod() *corev1.Pod {
func cliCommandsEquality(far *v1alpha1.FenceAgentsRemediation) (bool, error) {
//fence_ipmilan --ip=192.168.111.1 --ipport=6233 --username=admin --password=password --action=status --lanplus
if mocksExecuter.command == nil {
return false, errors.New("executedCommand is null")
}
expectedCommand, err := buildFenceAgentParams(far)
if err != nil {
return false, err
return false, errors.New("The command from mocksExecuter is null")
}
expectedCommand = append([]string{far.Spec.Agent}, expectedCommand...)

fmt.Printf("%s is the command from production environment, and %s is the expected command from test environment.\n", mocksExecuter.command, expectedCommand)
// hardcode expected command
expectedCommand := []string{" ", "--lanplus", "--password=password", "--username=admin", "--action=reboot", "--ip=192.168.111.1", "--ipport=6233"}

fmt.Printf("%s is the command from production environment, and %s is the hardcoded expected command from test environment.\n", mocksExecuter.command, expectedCommand)
sort.Strings(mocksExecuter.command)
sort.Strings(expectedCommand)
return reflect.DeepEqual(mocksExecuter.command, expectedCommand), nil
Expand Down

0 comments on commit 22ab7e9

Please sign in to comment.