Skip to content

Commit

Permalink
Set RPCReply.Ok based on presence of <ok/> tag in reply
Browse files Browse the repository at this point in the history
closes Juniper#34
  • Loading branch information
Wayne Tucker committed Feb 18, 2018
1 parent 97b43ac commit 8e66346
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion netconf/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type RPCReply struct {
XMLName xml.Name `xml:"rpc-reply"`
Errors []RPCError `xml:"rpc-error,omitempty"`
Data string `xml:",innerxml"`
Ok bool `xml:",omitempty"`
Ok bool `xml:"ok,omitempty"`
RawReply string `xml:"-"`
}

Expand All @@ -61,6 +61,11 @@ func newRPCReply(rawXML []byte, ErrOnWarning bool) (*RPCReply, error) {
return nil, err
}

// ugly workaround for golang's XML unmarshaling of empty tags
// if <ok/> is missing then omitempty behavior makes Ok true
// if <ok/> is present then omitempty behavior makes OK the value of that tag (nil) which then translates to false
reply.Ok = !reply.Ok

if reply.Errors != nil {
for _, rpcErr := range reply.Errors {
if rpcErr.Severity == "error" || ErrOnWarning {
Expand Down
7 changes: 5 additions & 2 deletions netconf/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var RPCReplytests = []struct {
</commit-results>
<ok/>
</rpc-reply>`,
false,
true,
},
{
`
Expand Down Expand Up @@ -160,7 +160,7 @@ configuration check-out failed: (missing mandatory statements)
</commit-results>
<ok/>
</rpc-reply>`,
false,
true,
},
}

Expand All @@ -173,5 +173,8 @@ func TestNewRPCReply(t *testing.T) {
if reply.RawReply != tc.rawXML {
t.Errorf("newRPCReply(%q) did not set RawReply to input, got %q", tc.rawXML, reply.RawReply)
}
if reply.Ok != tc.replyOk {
t.Errorf("newRPCReply(%q).Ok == %v, want %v", tc.rawXML, reply.Ok, tc.replyOk)
}
}
}

0 comments on commit 8e66346

Please sign in to comment.