Skip to content

Commit

Permalink
test: add failed when contains test for send w/ callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
carlmontanari committed Oct 17, 2024
1 parent 6650a5b commit 3ef514d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
32 changes: 29 additions & 3 deletions driver/generic/sendwithcallbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type sendWithCallbacksTestCase struct {
payloadFile string
initialInput string
callbacks []*generic.Callback
failed bool
}

func testSendWithCallbacks(
Expand All @@ -37,10 +38,9 @@ func testSendWithCallbacks(
)
}

if r.Failed != nil {
if r.Failed != nil && !testCase.failed {
t.Fatalf(
"%s: response object indicates failure,"+
" this shouldn't happenf or send with callbacks",
"%s: response object indicates failure, this shouldn't happen",
testName,
)
}
Expand Down Expand Up @@ -91,6 +91,32 @@ func TestSendWithCallbacks(t *testing.T) {
},
},
},
"send-with-callbacks-failed-when-contains": {
description: "simple send with callbacks test w/ failed when contains output",
payloadFile: "send-with-callbacks-failed-when-contains.txt",
initialInput: "",
callbacks: []*generic.Callback{
{
Callback: func(d *generic.Driver, _ string) error {
_, err := d.Channel.SendInput("configure terminal")

return err
},
Contains: "C3560CX#",
Name: "callback-one",
ResetOutput: true,
},
{
Callback: func(d *generic.Driver, _ string) error {
return d.Channel.WriteAndReturn([]byte("show version"), false)
},
ContainsRe: regexp.MustCompile(`(?im)^c3560cx\(config\)#`),
Name: "callback-two",
Complete: true,
},
},
failed: true,
},
}

for testName, testCase := range cases {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
configure terminal


show version

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
C3560CX#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
C3560CX(config)#show version
^
% Invalid input detected at '^' marker.

C3560CX(config)#
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ C3560CX#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
C3560CX(config)#show version
^
% Invalid input detected at '^' marker.
NOTHING TO SEE HERE -- dont want the test to have a failed result, so just making this show no failed when contains thing :)

C3560CX(config)#

0 comments on commit 3ef514d

Please sign in to comment.