From e1c4fb79bc90ffe6ae6612b3728b35301405861d Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sat, 8 Apr 2017 10:39:54 -0400 Subject: [PATCH] Add status tests --- common_test.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 common_test.go diff --git a/common_test.go b/common_test.go new file mode 100644 index 0000000..7c291d6 --- /dev/null +++ b/common_test.go @@ -0,0 +1,66 @@ +package ofxgo_test + +import ( + "github.com/aclindsa/ofxgo" + "testing" +) + +func TestStatusValid(t *testing.T) { + s := ofxgo.Status{ + 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) { + s := ofxgo.Status{ + 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 { + t.Fatalf("Status.CodeMeaning unexpectedly succeeded with invalid Code\n", err) + } +} + +func TestStatusCodeConditions(t *testing.T) { + s := ofxgo.Status{ + 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 { + t.Fatalf("Status.CodeConditions unexpectedly succeeded with invalid Code\n", err) + } +}