2020-03-31 00:19:18 -04:00
|
|
|
package ofxgo
|
2017-04-08 10:39:54 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStatusValid(t *testing.T) {
|
2020-03-31 00:19:18 -04:00
|
|
|
s := Status{
|
2017-04-08 10:39:54 -04:00
|
|
|
Code: 0,
|
|
|
|
Severity: "INFO",
|
|
|
|
Message: "Success",
|
|
|
|
}
|
|
|
|
if ok, err := s.Valid(); !ok {
|
|
|
|
t.Fatalf("Status unexpectedly invalid: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Severity = "INVALID"
|
|
|
|
if ok, err := s.Valid(); ok || err == nil {
|
|
|
|
t.Fatalf("Status unexpectedly valid invalid Severity\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Severity = "WARN"
|
|
|
|
if ok, err := s.Valid(); ok || err == nil {
|
|
|
|
t.Fatalf("Status unexpectedly valid with wrong Severity for Code 0\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Code = 9
|
|
|
|
if ok, err := s.Valid(); ok || err == nil {
|
|
|
|
t.Fatalf("Status unexpectedly valid with invalid Code\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusCodeMeaning(t *testing.T) {
|
2020-03-31 00:19:18 -04:00
|
|
|
s := Status{
|
2017-04-08 10:39:54 -04:00
|
|
|
Code: 15500,
|
|
|
|
Severity: "ERROR",
|
|
|
|
}
|
|
|
|
meaning, err := s.CodeMeaning()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Status.CodeMeaning unexpectedly failed: %s\n", err)
|
|
|
|
}
|
|
|
|
if meaning != "Signon invalid" {
|
|
|
|
t.Fatalf("Unexpected meaning for Code 15500: \"%s\"\n", meaning)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Code = 999
|
|
|
|
if meaning, err := s.CodeMeaning(); len(meaning) != 0 || err == nil {
|
2017-04-10 06:05:03 -04:00
|
|
|
t.Fatalf("Status.CodeMeaning unexpectedly succeeded with invalid Code\n")
|
2017-04-08 10:39:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusCodeConditions(t *testing.T) {
|
2020-03-31 00:19:18 -04:00
|
|
|
s := Status{
|
2017-04-08 10:39:54 -04:00
|
|
|
Code: 2006,
|
|
|
|
Severity: "ERROR",
|
|
|
|
}
|
|
|
|
if conditions, err := s.CodeConditions(); len(conditions) == 0 || err != nil {
|
|
|
|
t.Fatalf("Status.CodeConditions unexpectedly failed: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Code = 999
|
|
|
|
if conditions, err := s.CodeConditions(); len(conditions) != 0 || err == nil {
|
2017-04-10 06:05:03 -04:00
|
|
|
t.Fatalf("Status.CodeConditions unexpectedly succeeded with invalid Code\n")
|
2017-04-08 10:39:54 -04:00
|
|
|
}
|
|
|
|
}
|