Skip to content

Commit

Permalink
Merge pull request kubevirt#3947 from AlonaKaplan/safe_expecter_followup
Browse files Browse the repository at this point in the history
Improve ExpectBatchWithValidatedSend error handling
  • Loading branch information
kubevirt-bot authored Aug 12, 2020
2 parents ae34cba + 3fa17a2 commit 2bb4b0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
3 changes: 3 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,9 @@ func ExpectBatchWithValidatedSend(expecter expect.Expecter, batch []expect.Batch
}
expectFlag = true
sendFlag = false
if _, ok := batch[i].(*expect.BExp); !ok {
return nil, fmt.Errorf("ExpectBatchWithValidatedSend support only expect of type BExp")
}
bExp, _ := batch[i].(*expect.BExp)
previousSend := regexp.QuoteMeta(previousSend)

Expand Down
25 changes: 10 additions & 15 deletions tests/vmi_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package tests_test
import (
"fmt"
"net"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -647,22 +646,18 @@ var _ = Describe("[rfe_id:694][crit:medium][vendor:[email protected]][level:comp
err = tests.CheckForTextExpecter(dhcpVMI, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: "\\#"},
&expect.BSnd{S: "sudo dhclient -1 -r -d eth0\n"},
&expect.BSnd{S: "dhclient -1 -r -d eth0\n"},
&expect.BExp{R: "\\#"},
&expect.BSnd{S: "sudo dhclient -1 -sf /usr/bin/env --request-options subnet-mask,broadcast-address,time-offset,routers,domain-search,domain-name,domain-name-servers,host-name,nis-domain,nis-servers,ntp-servers,interface-mtu,tftp-server-name,bootfile-name eth0 | tee /dhcp-env\n"},
&expect.BExp{R: "\\#"},
&expect.BSnd{S: "cat /dhcp-env\n"},
&expect.BExp{R: "new_tftp_server_name=tftp.kubevirt.io"},
&expect.BSnd{S: "\n"},
&expect.BExp{R: "\\#"},
&expect.BSnd{S: "cat /dhcp-env\n"},
&expect.BExp{R: "new_bootfile_name=config"},
&expect.BSnd{S: "\n"},
&expect.BExp{R: "\\#"},
&expect.BSnd{S: "cat /dhcp-env\n"},
&expect.BExp{R: regexp.QuoteMeta("new_ntp_servers=127.0.0.1 127.0.0.2") + "((?s).*)" + regexp.QuoteMeta("new_unknown_240=private.options.kubevirt.io")},
&expect.BSnd{S: "\n"},
&expect.BSnd{S: "dhclient -1 -sf /usr/bin/env --request-options subnet-mask,broadcast-address,time-offset,routers,domain-search,domain-name,domain-name-servers,host-name,nis-domain,nis-servers,ntp-servers,interface-mtu,tftp-server-name,bootfile-name eth0 | tee /dhcp-env\n"},
&expect.BExp{R: "\\#"},
&expect.BSnd{S: "grep -q 'new_tftp_server_name=tftp.kubevirt.io' /dhcp-env; echo $?\n"},
&expect.BExp{R: tests.RetValue("0", "\\# ")},
&expect.BSnd{S: "grep -q 'new_bootfile_name=config' /dhcp-env; echo $?\n"},
&expect.BExp{R: tests.RetValue("0", "\\# ")},
&expect.BSnd{S: "grep -q 'new_ntp_servers=127.0.0.1 127.0.0.2' /dhcp-env; echo $?\n"},
&expect.BExp{R: tests.RetValue("0", "\\# ")},
&expect.BSnd{S: "grep -q 'new_unknown_240=private.options.kubevirt.io' /dhcp-env; echo $?\n"},
&expect.BExp{R: tests.RetValue("0", "\\# ")},
}, 15)

Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 2bb4b0d

Please sign in to comment.