-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from hellt/selfclosing-tags-enhancement
enhanced forceSelfClosingTags
- Loading branch information
Showing
3 changed files
with
70 additions
and
17 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
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
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,57 @@ | ||
package netconf_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/scrapli/scrapligo/driver/netconf" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestForceSelfClosingTags(t *testing.T) { | ||
tests := map[string]struct { | ||
got []byte | ||
want []byte | ||
}{ | ||
"empty_tag_no_attrs": { | ||
got: []byte( | ||
`<?xml version="1.0" encoding="UTF-8"?><rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get-config><source><running></running></source></get-config></rpc>]]>]]>`, //nolint: lll | ||
), | ||
want: []byte( | ||
`<?xml version="1.0" encoding="UTF-8"?><rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get-config><source><running/></source></get-config></rpc>]]>]]>`, //nolint: lll | ||
), | ||
}, | ||
"empty_tag_with_attrs": { | ||
got: []byte( | ||
`<?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"><routing-policy xmlns="http://openconfig.net/yang/routing-policy"></routing-policy></filter></get></rpc>]]>]]>`, //nolint: lll | ||
), | ||
want: []byte( | ||
`<?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"><routing-policy xmlns="http://openconfig.net/yang/routing-policy"/></filter></get></rpc>]]>]]>`, //nolint: lll | ||
), | ||
}, | ||
"empty_tag_with_attrs_and_spaces": { | ||
got: []byte( | ||
`<routing-policy xmlns="http://openconfig.net/yang/routing-policy"> </routing-policy>`, | ||
), | ||
want: []byte(`<routing-policy xmlns="http://openconfig.net/yang/routing-policy"/>`), | ||
}, | ||
"empty_tag_no_attrs_and_spaces": { | ||
got: []byte(`<running> </running>`), | ||
want: []byte(`<running/>`), | ||
}, | ||
} | ||
|
||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := netconf.ForceSelfClosingTags(tt.got) | ||
if !cmp.Equal(got, tt.want) { | ||
t.Fatalf( | ||
"%s: actual and expected values do not match\nactual: %s\nexpected:%s", | ||
name, | ||
got, | ||
tt.want, | ||
) | ||
} | ||
}) | ||
} | ||
} |