-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for junos specific tags and test
- Loading branch information
Showing
5 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package netconf_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/scrapli/scrapligo/util" | ||
) | ||
|
||
func testGetOperational(testName string, testCase *operationalTest) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
t.Logf("%s: starting", testName) | ||
|
||
d, fileTransportObj := prepareDriver(t, testName, testCase.payload.PayloadFile) | ||
|
||
r, err := d.Get(testCase.filter) | ||
if err != nil { | ||
t.Fatalf( | ||
"%s: encountered error running netconf Driver Validate, error: %s", | ||
testName, | ||
err, | ||
) | ||
} | ||
|
||
if r.Failed != nil && !testCase.shouldFail { | ||
t.Fatalf("%s: response object indicates failure", | ||
testName) | ||
} | ||
|
||
actualOut := r.Result | ||
actualIn := bytes.Join(fileTransportObj.Writes, []byte("\n")) | ||
|
||
if *update { | ||
writeGolden(t, testName, actualIn, actualOut) | ||
} | ||
|
||
expectedIn := readFile(t, fmt.Sprintf("golden/%s-in.txt", testName)) | ||
expectedOut := readFile(t, fmt.Sprintf("golden/%s-out.txt", testName)) | ||
|
||
if !cmp.Equal(actualIn, expectedIn) { | ||
t.Errorf( | ||
"%s: actual and expected inputs do not match\nactual: %s\nexpected:%s", | ||
testName, | ||
actualIn, | ||
expectedIn, | ||
) | ||
} | ||
|
||
if !cmp.Equal(actualOut, string(expectedOut)) { | ||
t.Fatalf( | ||
"%s: actual and expected outputs do not match\nactual: %s\nexpected:%s", | ||
testName, | ||
actualOut, | ||
expectedOut, | ||
) | ||
} | ||
} | ||
} | ||
|
||
type operationalTest struct { | ||
payload *util.PayloadTestCase | ||
filter string | ||
shouldFail bool | ||
} | ||
|
||
func TestGetOperational(t *testing.T) { | ||
cases := map[string]*operationalTest{ | ||
"junos-getoperational-components-fail": { | ||
payload: &util.PayloadTestCase{ | ||
Description: "operational show components", | ||
PayloadFile: "junos-getoperational-components-fail.txt", | ||
}, | ||
filter: `<components xmlns="http://openconfig.net/yang/platform"> | ||
<component> | ||
<state> | ||
<type xmlns:idx="http://openconfig.net/yang/platform-types">idx:CHASSIS</type> | ||
</state> | ||
</component> | ||
</components>`, | ||
shouldFail: true, | ||
}, | ||
} | ||
|
||
for testName, testCase := range cases { | ||
f := testGetOperational(testName, testCase) | ||
t.Run(testName, f) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
driver/netconf/test-fixtures/golden/junos-getoperational-components-fail-in.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> | ||
<capabilities> | ||
<capability>urn:ietf:params:netconf:base:1.0</capability> | ||
</capabilities> | ||
</hello>]]>]]> | ||
|
||
|
||
<?xml version="1.0" encoding="UTF-8"?><rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get><filter type="subtree"><components xmlns="http://openconfig.net/yang/platform"><component><state><type xmlns:idx="http://openconfig.net/yang/platform-types">idx:CHASSIS</type></state></component></components></filter></get></rpc>]]>]]> | ||
|
20 changes: 20 additions & 0 deletions
20
driver/netconf/test-fixtures/golden/junos-getoperational-components-fail-out.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<nc:rpc-reply xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/23.2R2.21-EVO/junos" message-id="101"> | ||
<nc:rpc-error> | ||
<nc:error-type>protocol</nc:error-type> | ||
<nc:error-tag>operation-failed</nc:error-tag> | ||
<nc:error-severity>error</nc:error-severity> | ||
<nc:error-message>syntax error</nc:error-message> | ||
<nc:error-info> | ||
<nc:bad-element>components</nc:bad-element> | ||
</nc:error-info> | ||
</nc:rpc-error> | ||
<nc:rpc-error> | ||
<nc:error-type>protocol</nc:error-type> | ||
<nc:error-tag>operation-failed</nc:error-tag> | ||
<nc:error-severity>error</nc:error-severity> | ||
<nc:error-message>syntax error, expecting </filter></nc:error-message> | ||
<nc:error-info> | ||
<nc:bad-element>components</nc:bad-element> | ||
</nc:error-info> | ||
</nc:rpc-error> | ||
</nc:rpc-reply> |
50 changes: 50 additions & 0 deletions
50
driver/netconf/test-fixtures/junos-getoperational-components-fail.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<nc:hello xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> | ||
<nc:capabilities> | ||
<nc:capability>urn:ietf:params:netconf:base:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:netconf:capability:candidate:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:netconf:capability:confirmed-commit:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:netconf:capability:validate:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:netconf:base:1.0?module=ietf-netconf&revision=2011-06-01</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:netconf:capability:candidate:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:netconf:capability:validate:1.0</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:netconf:capability:url:1.0?scheme=http,ftp,file</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&revision=2013-07-15</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:yang:ietf-yang-metadata?module=ietf-yang-metadata&revision=2016-08-05</nc:capability> | ||
<nc:capability>urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring</nc:capability> | ||
<nc:capability>http://xml.juniper.net/netconf/junos/1.0</nc:capability> | ||
<nc:capability>http://xml.juniper.net/dmi/system/1.0</nc:capability> | ||
<nc:capability>http://yang.juniper.net/junos/jcmd?module=junos-configuration-metadata&revision=2021-09-01</nc:capability> | ||
</nc:capabilities> | ||
<nc:session-id>5026</nc:session-id> | ||
</nc:hello> | ||
]]>]]> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> | ||
<capabilities> | ||
<capability>urn:ietf:params:netconf:base:1.0</capability> | ||
</capabilities> | ||
</hello>]]>]]> | ||
<?xml version="1.0" encoding="UTF-8"?><rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get><filter type="subtree"><components xmlns="http://openconfig.net/yang/platform"><component><state><type xmlns:idx="http://openconfig.net/yang/platform-types">idx:CHASSIS</type></state></component></components></filter></get></rpc>]]>]]> | ||
<nc:rpc-reply xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/23.2R2.21-EVO/junos" message-id="101"> | ||
<nc:rpc-error> | ||
<nc:error-type>protocol</nc:error-type> | ||
<nc:error-tag>operation-failed</nc:error-tag> | ||
<nc:error-severity>error</nc:error-severity> | ||
<nc:error-message>syntax error</nc:error-message> | ||
<nc:error-info> | ||
<nc:bad-element>components</nc:bad-element> | ||
</nc:error-info> | ||
</nc:rpc-error> | ||
<nc:rpc-error> | ||
<nc:error-type>protocol</nc:error-type> | ||
<nc:error-tag>operation-failed</nc:error-tag> | ||
<nc:error-severity>error</nc:error-severity> | ||
<nc:error-message>syntax error, expecting </filter></nc:error-message> | ||
<nc:error-info> | ||
<nc:bad-element>components</nc:bad-element> | ||
</nc:error-info> | ||
</nc:rpc-error> | ||
</nc:rpc-reply> | ||
]]>]]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters