package main
import (
"encoding/xml"
"reflect"
"testing"
)
func TestUnmarshalChallengeRespones(t *testing.T) {
var testXml string = `
sslvpn_logon
4
RADIUS
441
Enter Your 6 Digit Passcode
`
var r Resp
xml.Unmarshal([]byte(testXml), &r)
expected := Resp{
Action: "sslvpn_logon",
LogonStatus: 4,
LogonId: 441,
Challenge: "Enter Your 6 Digit Passcode ",
}
assertEqual(t, expected, r)
}
func TestUnmarshalLoginError(t *testing.T) {
var testXml string = `
sslvpn_logon
2
RADIUS
501
`
var r Resp
xml.Unmarshal([]byte(testXml), &r)
expected := Resp{
Action: "sslvpn_logon",
LogonStatus: 2,
Error: "501",
}
assertEqual(t, expected, r)
}
func TestUnmarshalLoginSuccess(t *testing.T) {
var testXml string = `
sslvpn_logon
1
RADIUS
`
var r Resp
xml.Unmarshal([]byte(testXml), &r)
expected := Resp{
Action: "sslvpn_logon",
LogonStatus: 1,
}
assertEqual(t, expected, r)
}
func assertEqual(t *testing.T, expected interface{}, result interface{}) {
if !reflect.DeepEqual(expected, result) {
t.Errorf(
"Unmarshaled values did not match.\nExpected: %v\nResult: %v\n",
expected, result,
)
t.Fail()
}
}