From 9b4d2413f97f3bc3bcadff37d8756d3e643462d1 Mon Sep 17 00:00:00 2001 From: Ilmari Aho Date: Wed, 7 Dec 2022 13:55:48 +0200 Subject: [PATCH] Add .Failed check to examples --- examples/generic_driver/basics/main.go | 5 +++++ examples/generic_driver/custom_logging/main.go | 5 +++++ examples/generic_driver/default_logging/main.go | 5 +++++ examples/generic_driver/interactive_prompts/main.go | 5 +++++ examples/generic_driver/textfsm_integration/main.go | 5 +++++ examples/netconf_driver/basics/main.go | 5 +++++ examples/network_driver/basics/main.go | 10 ++++++++++ examples/network_driver/platforms/main.go | 10 ++++++++++ examples/network_driver/privilege_levels/main.go | 5 +++++ examples/network_driver/sending_configs/main.go | 5 +++++ 10 files changed, 60 insertions(+) diff --git a/examples/generic_driver/basics/main.go b/examples/generic_driver/basics/main.go index b860951..2d0ddcd 100644 --- a/examples/generic_driver/basics/main.go +++ b/examples/generic_driver/basics/main.go @@ -66,6 +66,7 @@ func main() { // note that there is a convenience wrapper around send interactive in the generic driver as // well, so you could simply do `d.SendInteractive` here rather than poking the channel directly + // remember to refer to `.Result` object in that case interactiveOutput, err := d.Channel.SendInteractive(events) if err != nil { fmt.Printf("failed to send interactive input to device; error: %+v\n", err) @@ -84,6 +85,10 @@ func main() { fmt.Printf("failed to send command; error: %+v\n", err) return } + if r.Failed != nil { + fmt.Printf("response objects indicates failure: %+v\n", r.Failed) + return + } fmt.Printf( "sent command '%s', output received (SendCommand):\n %s\n\n\n", diff --git a/examples/generic_driver/custom_logging/main.go b/examples/generic_driver/custom_logging/main.go index 3a4146d..88731d9 100644 --- a/examples/generic_driver/custom_logging/main.go +++ b/examples/generic_driver/custom_logging/main.go @@ -61,6 +61,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf("got some output: %s\n\n\n", r.Result) } diff --git a/examples/generic_driver/default_logging/main.go b/examples/generic_driver/default_logging/main.go index 3884b32..fc48d14 100644 --- a/examples/generic_driver/default_logging/main.go +++ b/examples/generic_driver/default_logging/main.go @@ -37,6 +37,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf("got some output: %s\n\n\n", r.Result) } diff --git a/examples/generic_driver/interactive_prompts/main.go b/examples/generic_driver/interactive_prompts/main.go index 82ec9b9..6b0fb1e 100644 --- a/examples/generic_driver/interactive_prompts/main.go +++ b/examples/generic_driver/interactive_prompts/main.go @@ -50,6 +50,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf("interact response:\n%s\n", r.Result) } diff --git a/examples/generic_driver/textfsm_integration/main.go b/examples/generic_driver/textfsm_integration/main.go index 2661ee8..05e1ee1 100644 --- a/examples/generic_driver/textfsm_integration/main.go +++ b/examples/generic_driver/textfsm_integration/main.go @@ -44,6 +44,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } parsedOut, err := r.TextFsmParse(*arg) if err != nil { diff --git a/examples/netconf_driver/basics/main.go b/examples/netconf_driver/basics/main.go index d258422..1839dab 100644 --- a/examples/netconf_driver/basics/main.go +++ b/examples/netconf_driver/basics/main.go @@ -36,6 +36,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf("Config result: %s", r.Result) } diff --git a/examples/network_driver/basics/main.go b/examples/network_driver/basics/main.go index 950385d..a62ffdf 100644 --- a/examples/network_driver/basics/main.go +++ b/examples/network_driver/basics/main.go @@ -103,6 +103,11 @@ func main() { return } + if interactiveOutput.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", interactiveOutput.Failed) + + return + } fmt.Printf("output received (SendInteractive):\n %s\n\n\n", interactiveOutput.Result) @@ -116,6 +121,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf( "sent command '%s', output received (SendCommand):\n %s\n\n\n", diff --git a/examples/network_driver/platforms/main.go b/examples/network_driver/platforms/main.go index 55638c5..f2c0272 100644 --- a/examples/network_driver/platforms/main.go +++ b/examples/network_driver/platforms/main.go @@ -83,6 +83,11 @@ func main() { if err != nil { fmt.Printf("failed to send interactive input to device; error: %+v\n", err) } + if interactiveOutput.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", interactiveOutput.Failed) + + return + } fmt.Printf("output received (SendInteractive):\n %s\n\n\n", interactiveOutput.Result) @@ -94,6 +99,11 @@ func main() { fmt.Printf("failed to send command; error: %+v\n", err) return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf( "sent command '%s', output received (SendCommand):\n %s\n\n\n", diff --git a/examples/network_driver/privilege_levels/main.go b/examples/network_driver/privilege_levels/main.go index 686f759..a774ee8 100644 --- a/examples/network_driver/privilege_levels/main.go +++ b/examples/network_driver/privilege_levels/main.go @@ -72,6 +72,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf("got running config: %s\n\n\n", r.Result) } diff --git a/examples/network_driver/sending_configs/main.go b/examples/network_driver/sending_configs/main.go index 2d36ad9..e1f246c 100644 --- a/examples/network_driver/sending_configs/main.go +++ b/examples/network_driver/sending_configs/main.go @@ -48,6 +48,11 @@ func main() { return } + if r.Failed != nil { + fmt.Printf("response object indicates failure: %+v\n", r.Failed) + + return + } fmt.Printf("sending configs took %f seconds", r.ElapsedTime) }