diff --git a/bank_test.go b/bank_test.go index 389bfc7..0f1b46b 100644 --- a/bank_test.go +++ b/bank_test.go @@ -1,7 +1,6 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "strings" "testing" "time" @@ -42,24 +41,24 @@ func TestMarshalBankStatementRequest(t *testing.T) { ` - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", - SpecVersion: ofxgo.OfxVersion203, + SpecVersion: OfxVersion203, } - var request ofxgo.Request + var request Request request.Signon.UserID = "myusername" request.Signon.UserPass = "Pa$$word" request.Signon.Org = "BNK" request.Signon.Fid = "1987" - statementRequest := ofxgo.StatementRequest{ + statementRequest := StatementRequest{ TrnUID: "123", - BankAcctFrom: ofxgo.BankAcct{ + BankAcctFrom: BankAcct{ BankID: "318398732", AcctID: "78346129", - AcctType: ofxgo.AcctTypeChecking, + AcctType: AcctTypeChecking, }, Include: true, } @@ -68,7 +67,7 @@ func TestMarshalBankStatementRequest(t *testing.T) { request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() EST := time.FixedZone("EST", -5*60*60) - request.Signon.DtClient = *ofxgo.NewDate(2006, 1, 15, 11, 23, 0, 0, EST) + request.Signon.DtClient = *NewDate(2006, 1, 15, 11, 23, 0, 0, EST) marshalCheckRequest(t, &request, expectedString) } @@ -116,24 +115,24 @@ NEWFILEUID:NONE ` - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", - SpecVersion: ofxgo.OfxVersion103, + SpecVersion: OfxVersion103, } - var request ofxgo.Request + var request Request request.Signon.UserID = "myusername" request.Signon.UserPass = "Pa$$word" request.Signon.Org = "BNK" request.Signon.Fid = "1987" - statementRequest := ofxgo.StatementRequest{ + statementRequest := StatementRequest{ TrnUID: "123", - BankAcctFrom: ofxgo.BankAcct{ + BankAcctFrom: BankAcct{ BankID: "318398732", AcctID: "78346129", - AcctType: ofxgo.AcctTypeChecking, + AcctType: AcctTypeChecking, }, Include: true, } @@ -142,7 +141,7 @@ NEWFILEUID:NONE request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() EST := time.FixedZone("EST", -5*60*60) - request.Signon.DtClient = *ofxgo.NewDate(2006, 1, 15, 11, 23, 0, 0, EST) + request.Signon.DtClient = *NewDate(2006, 1, 15, 11, 23, 0, 0, EST) marshalCheckRequest(t, &request, expectedString) } @@ -211,73 +210,73 @@ func TestUnmarshalBankStatementResponse(t *testing.T) { `) - var expected ofxgo.Response + var expected Response - expected.Version = ofxgo.OfxVersion203 + expected.Version = OfxVersion203 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" - expected.Signon.DtServer = *ofxgo.NewDateGMT(2006, 1, 15, 11, 23, 03, 0) + expected.Signon.DtServer = *NewDateGMT(2006, 1, 15, 11, 23, 03, 0) expected.Signon.Language = "ENG" - expected.Signon.DtProfUp = ofxgo.NewDateGMT(2005, 2, 21, 9, 13, 0, 0) - expected.Signon.DtAcctUp = ofxgo.NewDateGMT(2006, 1, 2, 16, 0, 0, 0) + expected.Signon.DtProfUp = NewDateGMT(2005, 2, 21, 9, 13, 0, 0) + expected.Signon.DtAcctUp = NewDateGMT(2006, 1, 2, 16, 0, 0, 0) expected.Signon.Org = "BNK" expected.Signon.Fid = "1987" - var trnamt1, trnamt2 ofxgo.Amount + var trnamt1, trnamt2 Amount trnamt1.SetFrac64(-20000, 100) trnamt2.SetFrac64(-30000, 100) - banktranlist := ofxgo.TransactionList{ - DtStart: *ofxgo.NewDateGMT(2006, 1, 1, 0, 0, 0, 0), - DtEnd: *ofxgo.NewDateGMT(2006, 1, 15, 0, 0, 0, 0), - Transactions: []ofxgo.Transaction{ + banktranlist := TransactionList{ + DtStart: *NewDateGMT(2006, 1, 1, 0, 0, 0, 0), + DtEnd: *NewDateGMT(2006, 1, 15, 0, 0, 0, 0), + Transactions: []Transaction{ { - TrnType: ofxgo.TrnTypeCheck, - DtPosted: *ofxgo.NewDateGMT(2006, 1, 4, 0, 0, 0, 0), + TrnType: TrnTypeCheck, + DtPosted: *NewDateGMT(2006, 1, 4, 0, 0, 0, 0), TrnAmt: trnamt1, FiTID: "00592", CheckNum: "2002", }, { - TrnType: ofxgo.TrnTypeATM, - DtPosted: *ofxgo.NewDateGMT(2006, 1, 12, 0, 0, 0, 0), - DtUser: ofxgo.NewDateGMT(2006, 1, 12, 0, 0, 0, 0), + TrnType: TrnTypeATM, + DtPosted: *NewDateGMT(2006, 1, 12, 0, 0, 0, 0), + DtUser: NewDateGMT(2006, 1, 12, 0, 0, 0, 0), TrnAmt: trnamt2, FiTID: "00679", }, }, } - var balamt, availbalamt ofxgo.Amount + var balamt, availbalamt Amount balamt.SetFrac64(20029, 100) availbalamt.SetFrac64(20029, 100) - usd, err := ofxgo.NewCurrSymbol("USD") + usd, err := NewCurrSymbol("USD") if err != nil { t.Fatalf("Unexpected error creating CurrSymbol for USD\n") } - statementResponse := ofxgo.StatementResponse{ + statementResponse := StatementResponse{ TrnUID: "1001", - Status: ofxgo.Status{ + Status: Status{ Code: 0, Severity: "INFO", }, CurDef: *usd, - BankAcctFrom: ofxgo.BankAcct{ + BankAcctFrom: BankAcct{ BankID: "318398732", AcctID: "78346129", - AcctType: ofxgo.AcctTypeChecking, + AcctType: AcctTypeChecking, }, BankTranList: &banktranlist, BalAmt: balamt, - DtAsOf: *ofxgo.NewDateGMT(2006, 1, 14, 16, 0, 0, 0), + DtAsOf: *NewDateGMT(2006, 1, 14, 16, 0, 0, 0), AvailBalAmt: &availbalamt, - AvailDtAsOf: ofxgo.NewDateGMT(2006, 1, 14, 16, 0, 0, 0), + AvailDtAsOf: NewDateGMT(2006, 1, 14, 16, 0, 0, 0), } expected.Bank = append(expected.Bank, &statementResponse) - response, err := ofxgo.ParseResponse(responseReader) + response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } diff --git a/common_test.go b/common_test.go index bc1270c..6f41064 100644 --- a/common_test.go +++ b/common_test.go @@ -1,12 +1,11 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "testing" ) func TestStatusValid(t *testing.T) { - s := ofxgo.Status{ + s := Status{ Code: 0, Severity: "INFO", Message: "Success", @@ -32,7 +31,7 @@ func TestStatusValid(t *testing.T) { } func TestStatusCodeMeaning(t *testing.T) { - s := ofxgo.Status{ + s := Status{ Code: 15500, Severity: "ERROR", } @@ -51,7 +50,7 @@ func TestStatusCodeMeaning(t *testing.T) { } func TestStatusCodeConditions(t *testing.T) { - s := ofxgo.Status{ + s := Status{ Code: 2006, Severity: "ERROR", } diff --git a/constants.go b/constants.go index 302e372..6233d5f 100644 --- a/constants.go +++ b/constants.go @@ -9,8 +9,9 @@ package ofxgo import ( "errors" "fmt" - "github.com/aclindsa/xml" "strings" + + "github.com/aclindsa/xml" ) type ofxVersion uint diff --git a/constants_test.go b/constants_test.go index 4393d4c..bde41c7 100644 --- a/constants_test.go +++ b/constants_test.go @@ -1,4 +1,4 @@ -package ofxgo_test +package ofxgo /* * Do not edit this file by hand. It is auto-generated by calling `go generate`. @@ -7,14 +7,14 @@ package ofxgo_test */ import ( - "github.com/aclindsa/ofxgo" - "github.com/aclindsa/xml" "strings" "testing" + + "github.com/aclindsa/xml" ) func TestOfxVersion(t *testing.T) { - e, err := ofxgo.NewOfxVersion("102") + e, err := NewOfxVersion("102") if err != nil { t.Fatalf("Unexpected error creating new OfxVersion from string \"102\"\n") } @@ -31,7 +31,7 @@ func TestOfxVersion(t *testing.T) { marshalHelper(t, "220", &e) - overwritten, err := ofxgo.NewOfxVersion("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewOfxVersion("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new OfxVersion from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -59,7 +59,7 @@ func TestOfxVersion(t *testing.T) { } func TestAcctType(t *testing.T) { - e, err := ofxgo.NewAcctType("CHECKING") + e, err := NewAcctType("CHECKING") if err != nil { t.Fatalf("Unexpected error creating new AcctType from string \"CHECKING\"\n") } @@ -76,7 +76,7 @@ func TestAcctType(t *testing.T) { marshalHelper(t, "CD", &e) - overwritten, err := ofxgo.NewAcctType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewAcctType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new AcctType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -104,7 +104,7 @@ func TestAcctType(t *testing.T) { } func TestTrnType(t *testing.T) { - e, err := ofxgo.NewTrnType("CREDIT") + e, err := NewTrnType("CREDIT") if err != nil { t.Fatalf("Unexpected error creating new TrnType from string \"CREDIT\"\n") } @@ -121,7 +121,7 @@ func TestTrnType(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewTrnType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewTrnType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new TrnType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -149,7 +149,7 @@ func TestTrnType(t *testing.T) { } func TestImageType(t *testing.T) { - e, err := ofxgo.NewImageType("STATEMENT") + e, err := NewImageType("STATEMENT") if err != nil { t.Fatalf("Unexpected error creating new ImageType from string \"STATEMENT\"\n") } @@ -166,7 +166,7 @@ func TestImageType(t *testing.T) { marshalHelper(t, "TAX", &e) - overwritten, err := ofxgo.NewImageType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewImageType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new ImageType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -194,7 +194,7 @@ func TestImageType(t *testing.T) { } func TestImageRefType(t *testing.T) { - e, err := ofxgo.NewImageRefType("OPAQUE") + e, err := NewImageRefType("OPAQUE") if err != nil { t.Fatalf("Unexpected error creating new ImageRefType from string \"OPAQUE\"\n") } @@ -211,7 +211,7 @@ func TestImageRefType(t *testing.T) { marshalHelper(t, "FORMURL", &e) - overwritten, err := ofxgo.NewImageRefType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewImageRefType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new ImageRefType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -239,7 +239,7 @@ func TestImageRefType(t *testing.T) { } func TestCheckSup(t *testing.T) { - e, err := ofxgo.NewCheckSup("FRONTONLY") + e, err := NewCheckSup("FRONTONLY") if err != nil { t.Fatalf("Unexpected error creating new CheckSup from string \"FRONTONLY\"\n") } @@ -256,7 +256,7 @@ func TestCheckSup(t *testing.T) { marshalHelper(t, "FRONTANDBACK", &e) - overwritten, err := ofxgo.NewCheckSup("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewCheckSup("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new CheckSup from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -284,7 +284,7 @@ func TestCheckSup(t *testing.T) { } func TestCorrectAction(t *testing.T) { - e, err := ofxgo.NewCorrectAction("DELETE") + e, err := NewCorrectAction("DELETE") if err != nil { t.Fatalf("Unexpected error creating new CorrectAction from string \"DELETE\"\n") } @@ -301,7 +301,7 @@ func TestCorrectAction(t *testing.T) { marshalHelper(t, "REPLACE", &e) - overwritten, err := ofxgo.NewCorrectAction("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewCorrectAction("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new CorrectAction from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -329,7 +329,7 @@ func TestCorrectAction(t *testing.T) { } func TestBalType(t *testing.T) { - e, err := ofxgo.NewBalType("DOLLAR") + e, err := NewBalType("DOLLAR") if err != nil { t.Fatalf("Unexpected error creating new BalType from string \"DOLLAR\"\n") } @@ -346,7 +346,7 @@ func TestBalType(t *testing.T) { marshalHelper(t, "NUMBER", &e) - overwritten, err := ofxgo.NewBalType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewBalType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new BalType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -374,7 +374,7 @@ func TestBalType(t *testing.T) { } func TestInv401kSource(t *testing.T) { - e, err := ofxgo.NewInv401kSource("PRETAX") + e, err := NewInv401kSource("PRETAX") if err != nil { t.Fatalf("Unexpected error creating new Inv401kSource from string \"PRETAX\"\n") } @@ -391,7 +391,7 @@ func TestInv401kSource(t *testing.T) { marshalHelper(t, "OTHERNONVEST", &e) - overwritten, err := ofxgo.NewInv401kSource("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewInv401kSource("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new Inv401kSource from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -419,7 +419,7 @@ func TestInv401kSource(t *testing.T) { } func TestSubAcctType(t *testing.T) { - e, err := ofxgo.NewSubAcctType("CASH") + e, err := NewSubAcctType("CASH") if err != nil { t.Fatalf("Unexpected error creating new SubAcctType from string \"CASH\"\n") } @@ -436,7 +436,7 @@ func TestSubAcctType(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewSubAcctType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewSubAcctType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new SubAcctType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -464,7 +464,7 @@ func TestSubAcctType(t *testing.T) { } func TestBuyType(t *testing.T) { - e, err := ofxgo.NewBuyType("BUY") + e, err := NewBuyType("BUY") if err != nil { t.Fatalf("Unexpected error creating new BuyType from string \"BUY\"\n") } @@ -481,7 +481,7 @@ func TestBuyType(t *testing.T) { marshalHelper(t, "BUYTOCOVER", &e) - overwritten, err := ofxgo.NewBuyType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewBuyType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new BuyType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -509,7 +509,7 @@ func TestBuyType(t *testing.T) { } func TestOptAction(t *testing.T) { - e, err := ofxgo.NewOptAction("EXERCISE") + e, err := NewOptAction("EXERCISE") if err != nil { t.Fatalf("Unexpected error creating new OptAction from string \"EXERCISE\"\n") } @@ -526,7 +526,7 @@ func TestOptAction(t *testing.T) { marshalHelper(t, "EXPIRE", &e) - overwritten, err := ofxgo.NewOptAction("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewOptAction("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new OptAction from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -554,7 +554,7 @@ func TestOptAction(t *testing.T) { } func TestTferAction(t *testing.T) { - e, err := ofxgo.NewTferAction("IN") + e, err := NewTferAction("IN") if err != nil { t.Fatalf("Unexpected error creating new TferAction from string \"IN\"\n") } @@ -571,7 +571,7 @@ func TestTferAction(t *testing.T) { marshalHelper(t, "OUT", &e) - overwritten, err := ofxgo.NewTferAction("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewTferAction("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new TferAction from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -599,7 +599,7 @@ func TestTferAction(t *testing.T) { } func TestPosType(t *testing.T) { - e, err := ofxgo.NewPosType("LONG") + e, err := NewPosType("LONG") if err != nil { t.Fatalf("Unexpected error creating new PosType from string \"LONG\"\n") } @@ -616,7 +616,7 @@ func TestPosType(t *testing.T) { marshalHelper(t, "SHORT", &e) - overwritten, err := ofxgo.NewPosType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewPosType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new PosType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -644,7 +644,7 @@ func TestPosType(t *testing.T) { } func TestSecured(t *testing.T) { - e, err := ofxgo.NewSecured("NAKED") + e, err := NewSecured("NAKED") if err != nil { t.Fatalf("Unexpected error creating new Secured from string \"NAKED\"\n") } @@ -661,7 +661,7 @@ func TestSecured(t *testing.T) { marshalHelper(t, "COVERED", &e) - overwritten, err := ofxgo.NewSecured("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewSecured("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new Secured from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -689,7 +689,7 @@ func TestSecured(t *testing.T) { } func TestDuration(t *testing.T) { - e, err := ofxgo.NewDuration("DAY") + e, err := NewDuration("DAY") if err != nil { t.Fatalf("Unexpected error creating new Duration from string \"DAY\"\n") } @@ -706,7 +706,7 @@ func TestDuration(t *testing.T) { marshalHelper(t, "IMMEDIATE", &e) - overwritten, err := ofxgo.NewDuration("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewDuration("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new Duration from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -734,7 +734,7 @@ func TestDuration(t *testing.T) { } func TestRestriction(t *testing.T) { - e, err := ofxgo.NewRestriction("ALLORNONE") + e, err := NewRestriction("ALLORNONE") if err != nil { t.Fatalf("Unexpected error creating new Restriction from string \"ALLORNONE\"\n") } @@ -751,7 +751,7 @@ func TestRestriction(t *testing.T) { marshalHelper(t, "NONE", &e) - overwritten, err := ofxgo.NewRestriction("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewRestriction("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new Restriction from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -779,7 +779,7 @@ func TestRestriction(t *testing.T) { } func TestUnitType(t *testing.T) { - e, err := ofxgo.NewUnitType("SHARES") + e, err := NewUnitType("SHARES") if err != nil { t.Fatalf("Unexpected error creating new UnitType from string \"SHARES\"\n") } @@ -796,7 +796,7 @@ func TestUnitType(t *testing.T) { marshalHelper(t, "CURRENCY", &e) - overwritten, err := ofxgo.NewUnitType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewUnitType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new UnitType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -824,7 +824,7 @@ func TestUnitType(t *testing.T) { } func TestOptBuyType(t *testing.T) { - e, err := ofxgo.NewOptBuyType("BUYTOOPEN") + e, err := NewOptBuyType("BUYTOOPEN") if err != nil { t.Fatalf("Unexpected error creating new OptBuyType from string \"BUYTOOPEN\"\n") } @@ -841,7 +841,7 @@ func TestOptBuyType(t *testing.T) { marshalHelper(t, "BUYTOCLOSE", &e) - overwritten, err := ofxgo.NewOptBuyType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewOptBuyType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new OptBuyType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -869,7 +869,7 @@ func TestOptBuyType(t *testing.T) { } func TestSellType(t *testing.T) { - e, err := ofxgo.NewSellType("SELL") + e, err := NewSellType("SELL") if err != nil { t.Fatalf("Unexpected error creating new SellType from string \"SELL\"\n") } @@ -886,7 +886,7 @@ func TestSellType(t *testing.T) { marshalHelper(t, "SELLSHORT", &e) - overwritten, err := ofxgo.NewSellType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewSellType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new SellType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -914,7 +914,7 @@ func TestSellType(t *testing.T) { } func TestLoanPmtFreq(t *testing.T) { - e, err := ofxgo.NewLoanPmtFreq("WEEKLY") + e, err := NewLoanPmtFreq("WEEKLY") if err != nil { t.Fatalf("Unexpected error creating new LoanPmtFreq from string \"WEEKLY\"\n") } @@ -931,7 +931,7 @@ func TestLoanPmtFreq(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewLoanPmtFreq("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewLoanPmtFreq("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new LoanPmtFreq from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -959,7 +959,7 @@ func TestLoanPmtFreq(t *testing.T) { } func TestIncomeType(t *testing.T) { - e, err := ofxgo.NewIncomeType("CGLONG") + e, err := NewIncomeType("CGLONG") if err != nil { t.Fatalf("Unexpected error creating new IncomeType from string \"CGLONG\"\n") } @@ -976,7 +976,7 @@ func TestIncomeType(t *testing.T) { marshalHelper(t, "MISC", &e) - overwritten, err := ofxgo.NewIncomeType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewIncomeType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new IncomeType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1004,7 +1004,7 @@ func TestIncomeType(t *testing.T) { } func TestSellReason(t *testing.T) { - e, err := ofxgo.NewSellReason("CALL") + e, err := NewSellReason("CALL") if err != nil { t.Fatalf("Unexpected error creating new SellReason from string \"CALL\"\n") } @@ -1021,7 +1021,7 @@ func TestSellReason(t *testing.T) { marshalHelper(t, "MATURITY", &e) - overwritten, err := ofxgo.NewSellReason("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewSellReason("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new SellReason from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1049,7 +1049,7 @@ func TestSellReason(t *testing.T) { } func TestOptSellType(t *testing.T) { - e, err := ofxgo.NewOptSellType("SELLTOCLOSE") + e, err := NewOptSellType("SELLTOCLOSE") if err != nil { t.Fatalf("Unexpected error creating new OptSellType from string \"SELLTOCLOSE\"\n") } @@ -1066,7 +1066,7 @@ func TestOptSellType(t *testing.T) { marshalHelper(t, "SELLTOOPEN", &e) - overwritten, err := ofxgo.NewOptSellType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewOptSellType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new OptSellType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1094,7 +1094,7 @@ func TestOptSellType(t *testing.T) { } func TestRelType(t *testing.T) { - e, err := ofxgo.NewRelType("SPREAD") + e, err := NewRelType("SPREAD") if err != nil { t.Fatalf("Unexpected error creating new RelType from string \"SPREAD\"\n") } @@ -1111,7 +1111,7 @@ func TestRelType(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewRelType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewRelType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new RelType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1139,7 +1139,7 @@ func TestRelType(t *testing.T) { } func TestCharType(t *testing.T) { - e, err := ofxgo.NewCharType("ALPHAONLY") + e, err := NewCharType("ALPHAONLY") if err != nil { t.Fatalf("Unexpected error creating new CharType from string \"ALPHAONLY\"\n") } @@ -1156,7 +1156,7 @@ func TestCharType(t *testing.T) { marshalHelper(t, "ALPHAANDNUMERIC", &e) - overwritten, err := ofxgo.NewCharType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewCharType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new CharType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1184,7 +1184,7 @@ func TestCharType(t *testing.T) { } func TestSyncMode(t *testing.T) { - e, err := ofxgo.NewSyncMode("FULL") + e, err := NewSyncMode("FULL") if err != nil { t.Fatalf("Unexpected error creating new SyncMode from string \"FULL\"\n") } @@ -1201,7 +1201,7 @@ func TestSyncMode(t *testing.T) { marshalHelper(t, "LITE", &e) - overwritten, err := ofxgo.NewSyncMode("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewSyncMode("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new SyncMode from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1229,7 +1229,7 @@ func TestSyncMode(t *testing.T) { } func TestOfxSec(t *testing.T) { - e, err := ofxgo.NewOfxSec("NONE") + e, err := NewOfxSec("NONE") if err != nil { t.Fatalf("Unexpected error creating new OfxSec from string \"NONE\"\n") } @@ -1246,7 +1246,7 @@ func TestOfxSec(t *testing.T) { marshalHelper(t, "TYPE 1", &e) - overwritten, err := ofxgo.NewOfxSec("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewOfxSec("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new OfxSec from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1274,7 +1274,7 @@ func TestOfxSec(t *testing.T) { } func TestDebtType(t *testing.T) { - e, err := ofxgo.NewDebtType("COUPON") + e, err := NewDebtType("COUPON") if err != nil { t.Fatalf("Unexpected error creating new DebtType from string \"COUPON\"\n") } @@ -1291,7 +1291,7 @@ func TestDebtType(t *testing.T) { marshalHelper(t, "ZERO", &e) - overwritten, err := ofxgo.NewDebtType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewDebtType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new DebtType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1319,7 +1319,7 @@ func TestDebtType(t *testing.T) { } func TestDebtClass(t *testing.T) { - e, err := ofxgo.NewDebtClass("TREASURY") + e, err := NewDebtClass("TREASURY") if err != nil { t.Fatalf("Unexpected error creating new DebtClass from string \"TREASURY\"\n") } @@ -1336,7 +1336,7 @@ func TestDebtClass(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewDebtClass("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewDebtClass("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new DebtClass from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1364,7 +1364,7 @@ func TestDebtClass(t *testing.T) { } func TestCouponFreq(t *testing.T) { - e, err := ofxgo.NewCouponFreq("MONTHLY") + e, err := NewCouponFreq("MONTHLY") if err != nil { t.Fatalf("Unexpected error creating new CouponFreq from string \"MONTHLY\"\n") } @@ -1381,7 +1381,7 @@ func TestCouponFreq(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewCouponFreq("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewCouponFreq("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new CouponFreq from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1409,7 +1409,7 @@ func TestCouponFreq(t *testing.T) { } func TestCallType(t *testing.T) { - e, err := ofxgo.NewCallType("CALL") + e, err := NewCallType("CALL") if err != nil { t.Fatalf("Unexpected error creating new CallType from string \"CALL\"\n") } @@ -1426,7 +1426,7 @@ func TestCallType(t *testing.T) { marshalHelper(t, "MATURITY", &e) - overwritten, err := ofxgo.NewCallType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewCallType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new CallType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1454,7 +1454,7 @@ func TestCallType(t *testing.T) { } func TestAssetClass(t *testing.T) { - e, err := ofxgo.NewAssetClass("DOMESTICBOND") + e, err := NewAssetClass("DOMESTICBOND") if err != nil { t.Fatalf("Unexpected error creating new AssetClass from string \"DOMESTICBOND\"\n") } @@ -1471,7 +1471,7 @@ func TestAssetClass(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewAssetClass("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewAssetClass("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new AssetClass from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1499,7 +1499,7 @@ func TestAssetClass(t *testing.T) { } func TestMfType(t *testing.T) { - e, err := ofxgo.NewMfType("OPENEND") + e, err := NewMfType("OPENEND") if err != nil { t.Fatalf("Unexpected error creating new MfType from string \"OPENEND\"\n") } @@ -1516,7 +1516,7 @@ func TestMfType(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewMfType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewMfType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new MfType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1544,7 +1544,7 @@ func TestMfType(t *testing.T) { } func TestOptType(t *testing.T) { - e, err := ofxgo.NewOptType("PUT") + e, err := NewOptType("PUT") if err != nil { t.Fatalf("Unexpected error creating new OptType from string \"PUT\"\n") } @@ -1561,7 +1561,7 @@ func TestOptType(t *testing.T) { marshalHelper(t, "CALL", &e) - overwritten, err := ofxgo.NewOptType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewOptType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new OptType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1589,7 +1589,7 @@ func TestOptType(t *testing.T) { } func TestStockType(t *testing.T) { - e, err := ofxgo.NewStockType("COMMON") + e, err := NewStockType("COMMON") if err != nil { t.Fatalf("Unexpected error creating new StockType from string \"COMMON\"\n") } @@ -1606,7 +1606,7 @@ func TestStockType(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewStockType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewStockType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new StockType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1634,7 +1634,7 @@ func TestStockType(t *testing.T) { } func TestHolderType(t *testing.T) { - e, err := ofxgo.NewHolderType("INDIVIDUAL") + e, err := NewHolderType("INDIVIDUAL") if err != nil { t.Fatalf("Unexpected error creating new HolderType from string \"INDIVIDUAL\"\n") } @@ -1651,7 +1651,7 @@ func TestHolderType(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewHolderType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewHolderType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new HolderType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1679,7 +1679,7 @@ func TestHolderType(t *testing.T) { } func TestAcctClassification(t *testing.T) { - e, err := ofxgo.NewAcctClassification("PERSONAL") + e, err := NewAcctClassification("PERSONAL") if err != nil { t.Fatalf("Unexpected error creating new AcctClassification from string \"PERSONAL\"\n") } @@ -1696,7 +1696,7 @@ func TestAcctClassification(t *testing.T) { marshalHelper(t, "OTHER", &e) - overwritten, err := ofxgo.NewAcctClassification("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewAcctClassification("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new AcctClassification from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1724,7 +1724,7 @@ func TestAcctClassification(t *testing.T) { } func TestSvcStatus(t *testing.T) { - e, err := ofxgo.NewSvcStatus("AVAIL") + e, err := NewSvcStatus("AVAIL") if err != nil { t.Fatalf("Unexpected error creating new SvcStatus from string \"AVAIL\"\n") } @@ -1741,7 +1741,7 @@ func TestSvcStatus(t *testing.T) { marshalHelper(t, "ACTIVE", &e) - overwritten, err := ofxgo.NewSvcStatus("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewSvcStatus("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new SvcStatus from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } @@ -1769,7 +1769,7 @@ func TestSvcStatus(t *testing.T) { } func TestUsProductType(t *testing.T) { - e, err := ofxgo.NewUsProductType("401K") + e, err := NewUsProductType("401K") if err != nil { t.Fatalf("Unexpected error creating new UsProductType from string \"401K\"\n") } @@ -1786,7 +1786,7 @@ func TestUsProductType(t *testing.T) { marshalHelper(t, "UGMA", &e) - overwritten, err := ofxgo.NewUsProductType("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := NewUsProductType("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil { t.Fatalf("Expected error creating new UsProductType from string \"THISWILLNEVERBEAVALIDENUMSTRING\"\n") } diff --git a/creditcard_test.go b/creditcard_test.go index d487dd6..fea9dad 100644 --- a/creditcard_test.go +++ b/creditcard_test.go @@ -1,7 +1,6 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "strings" "testing" "time" @@ -41,31 +40,31 @@ func TestMarshalCCStatementRequest(t *testing.T) { ` - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", - SpecVersion: ofxgo.OfxVersion203, + SpecVersion: OfxVersion203, } - var request ofxgo.Request + var request Request request.Signon.UserID = "myusername" request.Signon.UserPass = "Pa$$word" request.Signon.Org = "BNK" request.Signon.Fid = "1987" - statementRequest := ofxgo.CCStatementRequest{ + statementRequest := CCStatementRequest{ TrnUID: "913846", - CCAcctFrom: ofxgo.CCAcct{ + CCAcctFrom: CCAcct{ AcctID: "XXXXXXXXXXXX1234", }, - DtStart: ofxgo.NewDateGMT(2017, 1, 1, 0, 0, 0, 0), + DtStart: NewDateGMT(2017, 1, 1, 0, 0, 0, 0), Include: true, } request.CreditCard = append(request.CreditCard, &statementRequest) request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() - request.Signon.DtClient = *ofxgo.NewDateGMT(2017, 3, 31, 15, 38, 48, 0) + request.Signon.DtClient = *NewDateGMT(2017, 3, 31, 15, 38, 48, 0) marshalCheckRequest(t, &request, expectedString) } @@ -82,45 +81,45 @@ OLDFILEUID:NONE NEWFILEUID:NONE 0INFOSUCCESS20170331154648.331[-4:EDT]ENG018172959e850ad-7448-b4ce-4b71-29057763b3060INFOUSD928374448846377520161201154648.688[-5:EST]20170331154648.688[-4:EDT]DEBIT20170209120000[0:GMT]-7.962017020924435657040207171600195SLICE OF NYCREDIT20161228120000[0:GMT]3830.462016122823633637200000258482730Payment Thank You ElectroDEBIT20170327120000[0:GMT]-17.72017032724445727085300442885680KROGER FUEL #9999-933420170331080000.000[-4:EDT]7630.1720170331080000.000[-4:EDT]`) - var expected ofxgo.Response + var expected Response EDT := time.FixedZone("EDT", -4*60*60) EST := time.FixedZone("EST", -5*60*60) - expected.Version = ofxgo.OfxVersion102 + expected.Version = OfxVersion102 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" expected.Signon.Status.Message = "SUCCESS" - expected.Signon.DtServer = *ofxgo.NewDate(2017, 3, 31, 15, 46, 48, 331000000, EDT) + expected.Signon.DtServer = *NewDate(2017, 3, 31, 15, 46, 48, 331000000, EDT) expected.Signon.Language = "ENG" expected.Signon.Org = "01" expected.Signon.Fid = "81729" - var trnamt1, trnamt2, trnamt3 ofxgo.Amount + var trnamt1, trnamt2, trnamt3 Amount trnamt1.SetFrac64(-796, 100) trnamt2.SetFrac64(383046, 100) trnamt3.SetFrac64(-1770, 100) - banktranlist := ofxgo.TransactionList{ - DtStart: *ofxgo.NewDate(2016, 12, 1, 15, 46, 48, 688000000, EST), - DtEnd: *ofxgo.NewDate(2017, 3, 31, 15, 46, 48, 688000000, EDT), - Transactions: []ofxgo.Transaction{ + banktranlist := TransactionList{ + DtStart: *NewDate(2016, 12, 1, 15, 46, 48, 688000000, EST), + DtEnd: *NewDate(2017, 3, 31, 15, 46, 48, 688000000, EDT), + Transactions: []Transaction{ { - TrnType: ofxgo.TrnTypeDebit, - DtPosted: *ofxgo.NewDateGMT(2017, 2, 9, 12, 0, 0, 0), + TrnType: TrnTypeDebit, + DtPosted: *NewDateGMT(2017, 2, 9, 12, 0, 0, 0), TrnAmt: trnamt1, FiTID: "2017020924435657040207171600195", Name: "SLICE OF NY", }, { - TrnType: ofxgo.TrnTypeCredit, - DtPosted: *ofxgo.NewDateGMT(2016, 12, 28, 12, 0, 0, 0), + TrnType: TrnTypeCredit, + DtPosted: *NewDateGMT(2016, 12, 28, 12, 0, 0, 0), TrnAmt: trnamt2, FiTID: "2016122823633637200000258482730", Name: "Payment Thank You Electro", }, { - TrnType: ofxgo.TrnTypeDebit, - DtPosted: *ofxgo.NewDateGMT(2017, 3, 27, 12, 0, 0, 0), + TrnType: TrnTypeDebit, + DtPosted: *NewDateGMT(2017, 3, 27, 12, 0, 0, 0), TrnAmt: trnamt3, FiTID: "2017032724445727085300442885680", Name: "KROGER FUEL #9999", @@ -128,34 +127,34 @@ NEWFILEUID:NONE }, } - var balamt, availbalamt ofxgo.Amount + var balamt, availbalamt Amount balamt.SetFrac64(-933400, 100) availbalamt.SetFrac64(763017, 100) - usd, err := ofxgo.NewCurrSymbol("USD") + usd, err := NewCurrSymbol("USD") if err != nil { t.Fatalf("Unexpected error creating CurrSymbol for USD\n") } - statementResponse := ofxgo.CCStatementResponse{ + statementResponse := CCStatementResponse{ TrnUID: "59e850ad-7448-b4ce-4b71-29057763b306", - Status: ofxgo.Status{ + Status: Status{ Code: 0, Severity: "INFO", }, CurDef: *usd, - CCAcctFrom: ofxgo.CCAcct{ + CCAcctFrom: CCAcct{ AcctID: "9283744488463775", }, BankTranList: &banktranlist, BalAmt: balamt, - DtAsOf: *ofxgo.NewDate(2017, 3, 31, 8, 0, 0, 0, EDT), + DtAsOf: *NewDate(2017, 3, 31, 8, 0, 0, 0, EDT), AvailBalAmt: &availbalamt, - AvailDtAsOf: ofxgo.NewDate(2017, 3, 31, 8, 0, 0, 0, EDT), + AvailDtAsOf: NewDate(2017, 3, 31, 8, 0, 0, 0, EDT), } expected.CreditCard = append(expected.CreditCard, &statementResponse) - response, err := ofxgo.ParseResponse(responseReader) + response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } diff --git a/doc.go b/doc.go index 1da4dfd..1f1d3aa 100644 --- a/doc.go +++ b/doc.go @@ -71,33 +71,32 @@ account and print the balance: import ( "fmt" - "github.com/aclindsa/ofxgo" "os" ) - var client ofxgo.Client // By not initializing them, we accept all default + var client Client // By not initializing them, we accept all default // client values - var request ofxgo.Request + var request Request // These are all specific to you and your financial institution request.URL = "https://ofx.example.com" - request.Signon.UserID = ofxgo.String("john") - request.Signon.UserPass = ofxgo.String("hunter2") - request.Signon.Org = ofxgo.String("MyBank") - request.Signon.Fid = ofxgo.String("0001") + request.Signon.UserID = String("john") + request.Signon.UserPass = String("hunter2") + request.Signon.Org = String("MyBank") + request.Signon.Fid = String("0001") - uid, err := ofxgo.RandomUID() + uid, err := RandomUID() if err != nil { fmt.Println("Error creating uid for transaction:", err) os.Exit(1) } - statementRequest := ofxgo.StatementRequest{ + statementRequest := StatementRequest{ TrnUID: *uid, - BankAcctFrom: ofxgo.BankAcct{ - BankID: ofxgo.String("123456789"), - AcctID: ofxgo.String("11111111111"), - AcctType: ofxgo.AcctTypeChecking, + BankAcctFrom: BankAcct{ + BankID: String("123456789"), + AcctID: String("11111111111"), + AcctType: AcctTypeChecking, }, } @@ -117,7 +116,7 @@ account and print the balance: if len(response.Bank) < 1 { fmt.Println("No banking messages received") - } else if stmt, ok := response.Bank[0].(*ofxgo.StatementResponse); ok { + } else if stmt, ok := response.Bank[0].(*StatementResponse); ok { fmt.Printf("Balance: %s %s (as of %s)\n", stmt.BalAmt, stmt.CurDef, stmt.DtAsOf) } diff --git a/generate_constants.py b/generate_constants.py index 6351720..704d31b 100755 --- a/generate_constants.py +++ b/generate_constants.py @@ -65,8 +65,9 @@ header = """package ofxgo import ( "errors" "fmt" - "github.com/aclindsa/xml" "strings" + + "github.com/aclindsa/xml" ) """ @@ -164,7 +165,7 @@ with open("constants.go", 'w') as f: constNames=constNames, upperValueString=upperValueString)) -test_header = """package ofxgo_test +test_header = """package ofxgo /* * Do not edit this file by hand. It is auto-generated by calling `go generate`. @@ -173,16 +174,16 @@ test_header = """package ofxgo_test */ import ( - "github.com/aclindsa/ofxgo" - "github.com/aclindsa/xml" "strings" "testing" + + "github.com/aclindsa/xml" ) """ test_template = """ func Test{enum}(t *testing.T) {{ - e, err := ofxgo.New{enum}("{firstValueUpper}") + e, err := New{enum}("{firstValueUpper}") if err != nil {{ t.Fatalf("Unexpected error creating new {enum} from string \\\"{firstValueUpper}\\\"\\n") }} @@ -199,7 +200,7 @@ func Test{enum}(t *testing.T) {{ marshalHelper(t, "{lastValueUpper}", &e) - overwritten, err := ofxgo.New{enum}("THISWILLNEVERBEAVALIDENUMSTRING") + overwritten, err := New{enum}("THISWILLNEVERBEAVALIDENUMSTRING") if err == nil {{ t.Fatalf("Expected error creating new {enum} from string \\\"THISWILLNEVERBEAVALIDENUMSTRING\\\"\\n") }} diff --git a/invstmt_test.go b/invstmt_test.go index e1a1e14..b943ed7 100644 --- a/invstmt_test.go +++ b/invstmt_test.go @@ -1,7 +1,6 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "github.com/aclindsa/xml" "reflect" "strings" @@ -49,13 +48,13 @@ func TestMarshalInvStatementRequest(t *testing.T) { ` - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "MYAPP", AppVer: "1234", - SpecVersion: ofxgo.OfxVersion203, + SpecVersion: OfxVersion203, } - var request ofxgo.Request + var request Request request.Signon.UserID = "1998124" request.Signon.UserPass = "Sup3eSekrit" request.Signon.Org = "First Bank" @@ -63,13 +62,13 @@ func TestMarshalInvStatementRequest(t *testing.T) { EST := time.FixedZone("EST", -5*60*60) - statementRequest := ofxgo.InvStatementRequest{ + statementRequest := InvStatementRequest{ TrnUID: "382827d6-e2d0-4396-bf3b-665979285420", - InvAcctFrom: ofxgo.InvAcct{ + InvAcctFrom: InvAcct{ BrokerID: "fi.example.com", AcctID: "82736664", }, - DtStart: ofxgo.NewDate(2016, 1, 1, 0, 0, 0, 0, EST), + DtStart: NewDate(2016, 1, 1, 0, 0, 0, 0, EST), Include: true, IncludeOO: true, IncludePos: true, @@ -79,7 +78,7 @@ func TestMarshalInvStatementRequest(t *testing.T) { request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() - request.Signon.DtClient = *ofxgo.NewDate(2016, 2, 24, 13, 19, 5, 0, EST) + request.Signon.DtClient = *NewDate(2016, 2, 24, 13, 19, 5, 0, EST) marshalCheckRequest(t, &request, expectedString) } @@ -320,35 +319,35 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { `) - var expected ofxgo.Response + var expected Response - expected.Version = ofxgo.OfxVersion203 + expected.Version = OfxVersion203 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" - expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 1, 20, 12, 44, 0) + expected.Signon.DtServer = *NewDateGMT(2017, 4, 1, 20, 12, 44, 0) expected.Signon.Language = "ENG" expected.Signon.Org = "INVSTRUS" expected.Signon.Fid = "9999" - var units1, unitprice1, commission1, total1, amount2 ofxgo.Amount + var units1, unitprice1, commission1, total1, amount2 Amount units1.SetFrac64(100, 1) unitprice1.SetFrac64(229, 1) commission1.SetFrac64(9, 1) total1.SetFrac64(-22909, 1) amount2.SetFrac64(22000, 1) - invtranlist := ofxgo.InvTranList{ - DtStart: *ofxgo.NewDateGMT(2017, 1, 1, 0, 0, 0, 0), - DtEnd: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0), - InvTransactions: []ofxgo.InvTransaction{ - ofxgo.BuyStock{ - InvBuy: ofxgo.InvBuy{ - InvTran: ofxgo.InvTran{ + invtranlist := InvTranList{ + DtStart: *NewDateGMT(2017, 1, 1, 0, 0, 0, 0), + DtEnd: *NewDateGMT(2017, 3, 31, 0, 0, 0, 0), + InvTransactions: []InvTransaction{ + BuyStock{ + InvBuy: InvBuy{ + InvTran: InvTran{ FiTID: "729483191", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), - DtSettle: ofxgo.NewDateGMT(2017, 2, 7, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtSettle: NewDateGMT(2017, 2, 7, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, @@ -356,20 +355,20 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { UnitPrice: unitprice1, Commission: commission1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - BuyType: ofxgo.BuyTypeBuy, + BuyType: BuyTypeBuy, }, }, - BankTransactions: []ofxgo.InvBankTransaction{ + BankTransactions: []InvBankTransaction{ { - Transactions: []ofxgo.Transaction{ + Transactions: []Transaction{ { - TrnType: ofxgo.TrnTypeCredit, - DtPosted: *ofxgo.NewDateGMT(2017, 1, 20, 0, 0, 0, 0), - DtUser: ofxgo.NewDateGMT(2017, 1, 18, 0, 0, 0, 0), - DtAvail: ofxgo.NewDateGMT(2017, 1, 23, 0, 0, 0, 0), + TrnType: TrnTypeCredit, + DtPosted: *NewDateGMT(2017, 1, 20, 0, 0, 0, 0), + DtUser: NewDateGMT(2017, 1, 18, 0, 0, 0, 0), + DtAvail: NewDateGMT(2017, 1, 23, 0, 0, 0, 0), TrnAmt: amount2, FiTID: "993838", @@ -377,33 +376,33 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { Memo: "CHECK 19980", }, }, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, }, } - var availcash, marginbalance, shortbalance, balvalue ofxgo.Amount + var availcash, marginbalance, shortbalance, balvalue Amount availcash.SetFrac64(1673, 100) marginbalance.SetFrac64(-8192, 10) shortbalance.SetFrac64(0, 1) balvalue.SetFrac64(25, 100) - invbalance := ofxgo.InvBalance{ + invbalance := InvBalance{ AvailCash: availcash, MarginBalance: marginbalance, ShortBalance: shortbalance, - BalList: []ofxgo.Balance{ + BalList: []Balance{ { Name: "Sweep Int Rate", Desc: "Current interest rate for sweep account balances", - BalType: ofxgo.BalTypePercent, + BalType: BalTypePercent, Value: balvalue, - DtAsOf: ofxgo.NewDateGMT(2017, 4, 1, 0, 0, 0, 0), + DtAsOf: NewDateGMT(2017, 4, 1, 0, 0, 0, 0), }, }, } - var balamt, availbalamt, posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2, oounits1, oolimitprice1, oounits2, oolimitprice2 ofxgo.Amount + var balamt, availbalamt, posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2, oounits1, oolimitprice1, oounits2, oolimitprice2 Amount balamt.SetFrac64(20029, 100) availbalamt.SetFrac64(20029, 100) posunits1.SetFrac64(200, 1) @@ -417,105 +416,105 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { oounits2.SetFrac64(25, 1) oolimitprice2.SetFrac64(1975, 100) - usd, err := ofxgo.NewCurrSymbol("USD") + usd, err := NewCurrSymbol("USD") if err != nil { t.Fatalf("Unexpected error creating CurrSymbol for USD\n") } - statementResponse := ofxgo.InvStatementResponse{ + statementResponse := InvStatementResponse{ TrnUID: "1a0117ad-692b-4c6a-a21b-020d37d34d49", - Status: ofxgo.Status{ + Status: Status{ Code: 0, Severity: "INFO", }, - DtAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0), + DtAsOf: *NewDateGMT(2017, 3, 31, 0, 0, 0, 0), CurDef: *usd, - InvAcctFrom: ofxgo.InvAcct{ + InvAcctFrom: InvAcct{ BrokerID: "invstrus.com", AcctID: "91827364", }, InvTranList: &invtranlist, - InvPosList: ofxgo.PositionList{ - ofxgo.StockPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + InvPosList: PositionList{ + StockPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits1, UnitPrice: posunitprice1, MktVal: posmktval1, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), Memo: "Price as of previous close", }, }, - ofxgo.OptPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + OptPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "129887339", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits2, UnitPrice: posunitprice2, MktVal: posmktval2, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), }, }, }, InvBal: &invbalance, - InvOOList: ofxgo.OOList{ - ofxgo.OOBuyMF{ - OO: ofxgo.OO{ + InvOOList: OOList{ + OOBuyMF{ + OO: OO{ FiTID: "76464632", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "922908645", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 10, 12, 44, 45, 0), + DtPlaced: *NewDateGMT(2017, 3, 10, 12, 44, 45, 0), Units: oounits1, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionNone, LimitPrice: oolimitprice1, }, - BuyType: ofxgo.BuyTypeBuy, - UnitType: ofxgo.UnitTypeShares, + BuyType: BuyTypeBuy, + UnitType: UnitTypeShares, }, - ofxgo.OOBuyStock{ - OO: ofxgo.OO{ + OOBuyStock{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, LimitPrice: oolimitprice2, }, - BuyType: ofxgo.BuyTypeBuy, + BuyType: BuyTypeBuy, }, }, } expected.InvStmt = append(expected.InvStmt, &statementResponse) - var yield1, yield2, strikeprice, parvalue ofxgo.Amount + var yield1, yield2, strikeprice, parvalue Amount yield1.SetFrac64(192, 100) yield2.SetFrac64(17, 1) strikeprice.SetFrac64(79, 1) parvalue.SetFrac64(10029, 100) - seclist := ofxgo.SecurityList{ - Securities: []ofxgo.Security{ - ofxgo.StockInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + seclist := SecurityList{ + Securities: []Security{ + StockInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, @@ -524,11 +523,11 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { FiID: "99184", }, Yield: yield1, - AssetClass: ofxgo.AssetClassOther, + AssetClass: AssetClassOther, }, - ofxgo.OptInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + OptInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "129887339", UniqueIDType: "CUSIP", }, @@ -536,19 +535,19 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { Ticker: "FERTP", FiID: "882919", }, - OptType: ofxgo.OptTypePut, + OptType: OptTypePut, StrikePrice: strikeprice, - DtExpire: *ofxgo.NewDateGMT(2017, 9, 1, 0, 0, 0, 0), + DtExpire: *NewDateGMT(2017, 9, 1, 0, 0, 0, 0), ShPerCtrct: 100, - SecID: &ofxgo.SecurityID{ + SecID: &SecurityID{ UniqueID: "983322180", UniqueIDType: "CUSIP", }, - AssetClass: ofxgo.AssetClassLargeStock, + AssetClass: AssetClassLargeStock, }, - ofxgo.StockInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + StockInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, @@ -557,11 +556,11 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { FiID: "883897", }, Yield: yield2, - AssetClass: ofxgo.AssetClassSmallStock, + AssetClass: AssetClassSmallStock, }, - ofxgo.MFInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + MFInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "922908645", UniqueIDType: "CUSIP", }, @@ -569,22 +568,22 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { Ticker: "VIMAX", }, }, - ofxgo.DebtInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + DebtInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "99182828", UniqueIDType: "CUSIP", }, SecName: "Someone's Class B Debt", }, ParValue: parvalue, - DebtType: ofxgo.DebtTypeCoupon, - DtCoupon: ofxgo.NewDateGMT(2017, 9, 1, 0, 0, 0, 0), - CouponFreq: ofxgo.CouponFreqQuarterly, + DebtType: DebtTypeCoupon, + DtCoupon: NewDateGMT(2017, 9, 1, 0, 0, 0, 0), + CouponFreq: CouponFreqQuarterly, }, - ofxgo.OtherInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + OtherInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "88181818", UniqueIDType: "CUSIP", }, @@ -596,7 +595,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) { } expected.SecList = append(expected.SecList, &seclist) - response, err := ofxgo.ParseResponse(responseReader) + response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } @@ -769,18 +768,18 @@ NEWFILEUID: NONE `) - var expected ofxgo.Response + var expected Response - expected.Version = ofxgo.OfxVersion102 + expected.Version = OfxVersion102 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" - expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0) + expected.Signon.DtServer = *NewDateGMT(2017, 4, 3, 12, 0, 0, 0) expected.Signon.Language = "ENG" expected.Signon.Org = "VV" expected.Signon.Fid = "1000" // Ignored 1000 - var units1, unitprice1, commission1, fees1, total1, units2, units3 ofxgo.Amount + var units1, unitprice1, commission1, fees1, total1, units2, units3 Amount units1.SetFrac64(-1, 1) unitprice1.SetFrac64(35, 100) commission1.SetFrac64(885, 100) @@ -789,18 +788,18 @@ NEWFILEUID: NONE units2.SetFrac64(-100, 1) units3.SetFrac64(1, 1) - invtranlist := ofxgo.InvTranList{ - DtStart: *ofxgo.NewDateGMT(2016, 12, 6, 12, 0, 0, 0), - DtEnd: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0), - InvTransactions: []ofxgo.InvTransaction{ - ofxgo.SellOpt{ - InvSell: ofxgo.InvSell{ - InvTran: ofxgo.InvTran{ + invtranlist := InvTranList{ + DtStart: *NewDateGMT(2016, 12, 6, 12, 0, 0, 0), + DtEnd: *NewDateGMT(2017, 4, 3, 12, 0, 0, 0), + InvTransactions: []InvTransaction{ + SellOpt{ + InvSell: InvSell{ + InvTran: InvTran{ FiTID: "12341234-20161207-1", - DtTrade: *ofxgo.NewDateGMT(2016, 12, 7, 12, 0, 0, 0), - DtSettle: ofxgo.NewDateGMT(2016, 12, 8, 12, 0, 0, 0), + DtTrade: *NewDateGMT(2016, 12, 7, 12, 0, 0, 0), + DtSettle: NewDateGMT(2016, 12, 8, 12, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "SPY161216C00226000", UniqueIDType: "CUSIP", }, @@ -809,57 +808,57 @@ NEWFILEUID: NONE Commission: commission1, Fees: fees1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - OptSellType: ofxgo.OptSellTypeSellToOpen, + OptSellType: OptSellTypeSellToOpen, ShPerCtrct: 100, }, - ofxgo.ClosureOpt{ - InvTran: ofxgo.InvTran{ + ClosureOpt{ + InvTran: InvTran{ FiTID: "12341234-20161215-1", - DtTrade: *ofxgo.NewDateGMT(2016, 12, 15, 12, 0, 0, 0), - DtSettle: ofxgo.NewDateGMT(2016, 12, 20, 12, 0, 0, 0), + DtTrade: *NewDateGMT(2016, 12, 15, 12, 0, 0, 0), + DtSettle: NewDateGMT(2016, 12, 20, 12, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F10", UniqueIDType: "CUSIP", }, - OptAction: ofxgo.OptActionAssign, + OptAction: OptActionAssign, Units: units2, ShPerCtrct: 100, - SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, }, - ofxgo.ClosureOpt{ - InvTran: ofxgo.InvTran{ + ClosureOpt{ + InvTran: InvTran{ FiTID: "12341234-20161215-2", - DtTrade: *ofxgo.NewDateGMT(2016, 12, 15, 12, 0, 0, 0), - DtSettle: ofxgo.NewDateGMT(2016, 12, 15, 12, 0, 0, 0), + DtTrade: *NewDateGMT(2016, 12, 15, 12, 0, 0, 0), + DtSettle: NewDateGMT(2016, 12, 15, 12, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "SPY161216C00226000", UniqueIDType: "CUSIP", }, - OptAction: ofxgo.OptActionAssign, + OptAction: OptActionAssign, Units: units3, ShPerCtrct: 100, - SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, }, }, } - var availcash, marginbalance, shortbalance ofxgo.Amount + var availcash, marginbalance, shortbalance Amount availcash.SetFrac64(0, 1) marginbalance.SetFrac64(-0, 1) shortbalance.SetFrac64(0, 1) - invbalance := ofxgo.InvBalance{ + invbalance := InvBalance{ AvailCash: availcash, MarginBalance: marginbalance, ShortBalance: shortbalance, } - var posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2 ofxgo.Amount + var posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2 Amount posunits1.SetFrac64(100, 1) posunitprice1.SetFrac64(79, 1) posmktval1.SetFrac64(79000, 1) @@ -867,51 +866,51 @@ NEWFILEUID: NONE posunitprice2.SetFrac64(2987, 100) posmktval2.SetFrac64(2987, 1) - usd, err := ofxgo.NewCurrSymbol("USD") + usd, err := NewCurrSymbol("USD") if err != nil { t.Fatalf("Unexpected error creating CurrSymbol for USD\n") } - statementResponse := ofxgo.InvStatementResponse{ + statementResponse := InvStatementResponse{ TrnUID: "1283719872", - Status: ofxgo.Status{ + Status: Status{ Code: 0, Severity: "INFO", }, - DtAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0), + DtAsOf: *NewDateGMT(2017, 4, 3, 12, 0, 0, 0), CurDef: *usd, - InvAcctFrom: ofxgo.InvAcct{ + InvAcctFrom: InvAcct{ BrokerID: "www.exampletrader.com", AcctID: "12341234", }, InvTranList: &invtranlist, - InvPosList: ofxgo.PositionList{ - ofxgo.StockPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + InvPosList: PositionList{ + StockPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "04956010", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits1, UnitPrice: posunitprice1, MktVal: posmktval1, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 4, 3, 12, 0, 0, 0), }, }, - ofxgo.StockPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + StockPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "36960410", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits2, UnitPrice: posunitprice2, MktVal: posmktval2, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 4, 3, 12, 0, 0, 0), }, }, }, @@ -919,14 +918,14 @@ NEWFILEUID: NONE } expected.InvStmt = append(expected.InvStmt, &statementResponse) - var strikeprice ofxgo.Amount + var strikeprice Amount strikeprice.SetFrac64(226, 1) - seclist := ofxgo.SecurityList{ - Securities: []ofxgo.Security{ - ofxgo.StockInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + seclist := SecurityList{ + Securities: []Security{ + StockInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "78462F10", UniqueIDType: "CUSIP", }, @@ -934,25 +933,25 @@ NEWFILEUID: NONE Ticker: "SPY", }, }, - ofxgo.OptInfo{ - SecInfo: ofxgo.SecInfo{ - SecID: ofxgo.SecurityID{ + OptInfo{ + SecInfo: SecInfo{ + SecID: SecurityID{ UniqueID: "SPY161216C00226000", UniqueIDType: "CUSIP", }, SecName: "SPY Dec 16 2016 226.00 Call", Ticker: "SPY 161216C00226000", }, - OptType: ofxgo.OptTypeCall, + OptType: OptTypeCall, StrikePrice: strikeprice, - DtExpire: *ofxgo.NewDateGMT(2016, 12, 16, 12, 0, 0, 0), + DtExpire: *NewDateGMT(2016, 12, 16, 12, 0, 0, 0), ShPerCtrct: 100, }, }, } expected.SecList = append(expected.SecList, &seclist) - response, err := ofxgo.ParseResponse(responseReader) + response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } @@ -1131,7 +1130,7 @@ func TestUnmarshalInvTranList(t *testing.T) { ` - var units1, unitprice1, commission1, fees1, total1, accrdint, total2, oldunits1, newunits1 ofxgo.Amount + var units1, unitprice1, commission1, fees1, total1, accrdint, total2, oldunits1, newunits1 Amount units1.SetFrac64(100, 1) unitprice1.SetFrac64(229, 1) commission1.SetFrac64(9, 1) @@ -1142,18 +1141,18 @@ func TestUnmarshalInvTranList(t *testing.T) { oldunits1.SetFrac64(100, 1) newunits1.SetFrac64(200, 1) - expected := ofxgo.InvTranList{ - DtStart: *ofxgo.NewDateGMT(2017, 1, 1, 0, 0, 0, 0), - DtEnd: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0), - InvTransactions: []ofxgo.InvTransaction{ - ofxgo.BuyDebt{ - InvBuy: ofxgo.InvBuy{ - InvTran: ofxgo.InvTran{ + expected := InvTranList{ + DtStart: *NewDateGMT(2017, 1, 1, 0, 0, 0, 0), + DtEnd: *NewDateGMT(2017, 3, 31, 0, 0, 0, 0), + InvTransactions: []InvTransaction{ + BuyDebt{ + InvBuy: InvBuy{ + InvTran: InvTran{ FiTID: "81818", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), - DtSettle: ofxgo.NewDateGMT(2017, 2, 7, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtSettle: NewDateGMT(2017, 2, 7, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, @@ -1162,158 +1161,158 @@ func TestUnmarshalInvTranList(t *testing.T) { Commission: commission1, Fees: fees1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, AccrdInt: accrdint, }, - ofxgo.BuyOpt{ - InvBuy: ofxgo.InvBuy{ - InvTran: ofxgo.InvTran{ + BuyOpt{ + InvBuy: InvBuy{ + InvTran: InvTran{ FiTID: "81818", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), Memo: "Something to make a memo about", }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Units: units1, UnitPrice: unitprice1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - OptBuyType: ofxgo.OptBuyTypeBuyToOpen, + OptBuyType: OptBuyTypeBuyToOpen, ShPerCtrct: 100, }, - ofxgo.InvExpense{ - InvTran: ofxgo.InvTran{ + InvExpense{ + InvTran: InvTran{ FiTID: "129837-1111", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Total: fees1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - ofxgo.JrnlSec{ - InvTran: ofxgo.InvTran{ + JrnlSec{ + InvTran: InvTran{ FiTID: "129837-1112", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Units: total2, - SubAcctTo: ofxgo.SubAcctTypeCash, - SubAcctFrom: ofxgo.SubAcctTypeCash, + SubAcctTo: SubAcctTypeCash, + SubAcctFrom: SubAcctTypeCash, }, - ofxgo.JrnlFund{ - InvTran: ofxgo.InvTran{ + JrnlFund{ + InvTran: InvTran{ FiTID: "129837-1112", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, Total: total2, - SubAcctTo: ofxgo.SubAcctTypeCash, - SubAcctFrom: ofxgo.SubAcctTypeCash, + SubAcctTo: SubAcctTypeCash, + SubAcctFrom: SubAcctTypeCash, }, - ofxgo.BuyOther{ - InvBuy: ofxgo.InvBuy{ - InvTran: ofxgo.InvTran{ + BuyOther{ + InvBuy: InvBuy{ + InvTran: InvTran{ FiTID: "81818", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Units: units1, UnitPrice: unitprice1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, }, - ofxgo.MarginInterest{ - InvTran: ofxgo.InvTran{ + MarginInterest{ + InvTran: InvTran{ FiTID: "129837-1112", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, Total: total2, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - ofxgo.SellDebt{ - InvSell: ofxgo.InvSell{ - InvTran: ofxgo.InvTran{ + SellDebt{ + InvSell: InvSell{ + InvTran: InvTran{ FiTID: "129837-1111", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Units: units1, UnitPrice: unitprice1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - SellReason: ofxgo.SellReasonSell, + SellReason: SellReasonSell, }, - ofxgo.RetOfCap{ - InvTran: ofxgo.InvTran{ + RetOfCap{ + InvTran: InvTran{ FiTID: "129837-1111", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Total: total2, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, - ofxgo.Split{ - InvTran: ofxgo.InvTran{ + Split{ + InvTran: InvTran{ FiTID: "129837-1111", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, - SubAcctSec: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, OldUnits: oldunits1, NewUnits: newunits1, Numerator: 2, Denominator: 1, }, - ofxgo.SellOther{ - InvSell: ofxgo.InvSell{ - InvTran: ofxgo.InvTran{ + SellOther{ + InvSell: InvSell{ + InvTran: InvTran{ FiTID: "129837-1111", - DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0), + DtTrade: *NewDateGMT(2017, 2, 3, 0, 0, 0, 0), }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, Units: units1, UnitPrice: unitprice1, Total: total1, - SubAcctSec: ofxgo.SubAcctTypeCash, - SubAcctFund: ofxgo.SubAcctTypeCash, + SubAcctSec: SubAcctTypeCash, + SubAcctFund: SubAcctTypeCash, }, }, }, } - var actual ofxgo.InvTranList + var actual InvTranList err := xml.Unmarshal([]byte(input), &actual) if err != nil { t.Fatalf("Unexpected error unmarshalling InvTranList: %s\n", err) @@ -1400,7 +1399,7 @@ func TestUnmarshalPositionList(t *testing.T) { ` - var posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2 ofxgo.Amount + var posunits1, posunitprice1, posmktval1, posunits2, posunitprice2, posmktval2 Amount posunits1.SetFrac64(200, 1) posunitprice1.SetFrac64(23574, 100) posmktval1.SetFrac64(47148, 1) @@ -1408,77 +1407,77 @@ func TestUnmarshalPositionList(t *testing.T) { posunitprice2.SetFrac64(3, 1) posmktval2.SetFrac64(300, 1) - expected := ofxgo.PositionList{ - ofxgo.OtherPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + expected := PositionList{ + OtherPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits2, UnitPrice: posunitprice2, MktVal: posmktval2, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), }, }, - ofxgo.StockPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + StockPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeShort, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeShort, Units: posunits1, UnitPrice: posunitprice1, MktVal: posmktval1, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), Memo: "Price as of previous close", }, ReinvDiv: true, }, - ofxgo.DebtPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + DebtPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "129887339", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits2, UnitPrice: posunitprice2, MktVal: posmktval2, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), }, }, - ofxgo.OptPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + OptPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "129887339", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits2, UnitPrice: posunitprice2, MktVal: posmktval2, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), }, }, - ofxgo.MFPosition{ - InvPos: ofxgo.InvPosition{ - SecID: ofxgo.SecurityID{ + MFPosition{ + InvPos: InvPosition{ + SecID: SecurityID{ UniqueID: "78462F103", UniqueIDType: "CUSIP", }, - HeldInAcct: ofxgo.SubAcctTypeCash, - PosType: ofxgo.PosTypeLong, + HeldInAcct: SubAcctTypeCash, + PosType: PosTypeLong, Units: posunits1, UnitPrice: posunitprice1, MktVal: posmktval1, - DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0), + DtPriceAsOf: *NewDateGMT(2017, 3, 31, 16, 0, 0, 0), Memo: "Price as of previous close", }, ReinvDiv: true, @@ -1486,7 +1485,7 @@ func TestUnmarshalPositionList(t *testing.T) { }, } - var actual ofxgo.PositionList + var actual PositionList err := xml.Unmarshal([]byte(input), &actual) if err != nil { t.Fatalf("Unexpected error unmarshalling PositionList: %s\n", err) @@ -1675,192 +1674,192 @@ func TestUnmarshalOOList(t *testing.T) { ` - var oounits1, oolimitprice1, oounits2, oolimitprice2 ofxgo.Amount + var oounits1, oolimitprice1, oounits2, oolimitprice2 Amount oounits1.SetFrac64(10, 1) oolimitprice1.SetFrac64(16850, 100) oounits2.SetFrac64(25, 1) oolimitprice2.SetFrac64(1975, 100) - expected := ofxgo.OOList{ - ofxgo.OOBuyDebt{ - OO: ofxgo.OO{ + expected := OOList{ + OOBuyDebt{ + OO: OO{ FiTID: "76464632", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "922908645", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 10, 12, 44, 45, 0), + DtPlaced: *NewDateGMT(2017, 3, 10, 12, 44, 45, 0), Units: oounits1, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationDay, - Restriction: ofxgo.RestrictionNone, + SubAcct: SubAcctTypeCash, + Duration: DurationDay, + Restriction: RestrictionNone, }, Auction: true, }, - ofxgo.OOBuyMF{ - OO: ofxgo.OO{ + OOBuyMF{ + OO: OO{ FiTID: "76464632", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "922908645", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 10, 12, 44, 45, 0), + DtPlaced: *NewDateGMT(2017, 3, 10, 12, 44, 45, 0), Units: oounits1, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionNone, LimitPrice: oolimitprice1, }, - BuyType: ofxgo.BuyTypeBuy, - UnitType: ofxgo.UnitTypeShares, + BuyType: BuyTypeBuy, + UnitType: UnitTypeShares, }, - ofxgo.OOBuyOpt{ - OO: ofxgo.OO{ + OOBuyOpt{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, LimitPrice: oolimitprice2, }, - OptBuyType: ofxgo.OptBuyTypeBuyToClose, + OptBuyType: OptBuyTypeBuyToClose, }, - ofxgo.OOBuyStock{ - OO: ofxgo.OO{ + OOBuyStock{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, LimitPrice: oolimitprice2, }, - BuyType: ofxgo.BuyTypeBuy, + BuyType: BuyTypeBuy, }, - ofxgo.OOBuyOther{ - OO: ofxgo.OO{ + OOBuyOther{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, LimitPrice: oolimitprice2, }, - UnitType: ofxgo.UnitTypeCurrency, + UnitType: UnitTypeCurrency, }, - ofxgo.OOSellDebt{ - OO: ofxgo.OO{ + OOSellDebt{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, }, }, - ofxgo.OOSellMF{ - OO: ofxgo.OO{ + OOSellMF{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, }, - SellType: ofxgo.SellTypeSellShort, - UnitType: ofxgo.UnitTypeShares, + SellType: SellTypeSellShort, + UnitType: UnitTypeShares, SellAll: true, }, - ofxgo.OOSellOpt{ - OO: ofxgo.OO{ + OOSellOpt{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, }, - OptSellType: ofxgo.OptSellTypeSellToOpen, + OptSellType: OptSellTypeSellToOpen, }, - ofxgo.OOSellOther{ - OO: ofxgo.OO{ + OOSellOther{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, }, - UnitType: ofxgo.UnitTypeShares, + UnitType: UnitTypeShares, }, - ofxgo.OOSellStock{ - OO: ofxgo.OO{ + OOSellStock{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, }, - SellType: ofxgo.SellTypeSell, + SellType: SellTypeSell, }, - ofxgo.OOSwitchMF{ - OO: ofxgo.OO{ + OOSwitchMF{ + OO: OO{ FiTID: "999387423", - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422348", UniqueIDType: "CUSIP", }, - DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0), + DtPlaced: *NewDateGMT(2017, 3, 24, 3, 19, 0, 0), Units: oounits2, - SubAcct: ofxgo.SubAcctTypeCash, - Duration: ofxgo.DurationGoodTilCancel, - Restriction: ofxgo.RestrictionAllOrNone, + SubAcct: SubAcctTypeCash, + Duration: DurationGoodTilCancel, + Restriction: RestrictionAllOrNone, }, - SecID: ofxgo.SecurityID{ + SecID: SecurityID{ UniqueID: "899422389", UniqueIDType: "CUSIP", }, - UnitType: ofxgo.UnitTypeCurrency, + UnitType: UnitTypeCurrency, SwitchAll: false, }, } - var actual ofxgo.OOList + var actual OOList err := xml.Unmarshal([]byte(input), &actual) if err != nil { t.Fatalf("Unexpected error unmarshalling OOList: %s\n", err) diff --git a/profile_test.go b/profile_test.go index b15d0c3..b6cb727 100644 --- a/profile_test.go +++ b/profile_test.go @@ -1,7 +1,6 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "strings" "testing" "time" @@ -36,13 +35,13 @@ func TestMarshalProfileRequest(t *testing.T) { ` - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", - SpecVersion: ofxgo.OfxVersion203, + SpecVersion: OfxVersion203, } - var request ofxgo.Request + var request Request request.Signon.UserID = "anonymous00000000000000000000000" request.Signon.UserPass = "anonymous00000000000000000000000" request.Signon.Org = "BNK" @@ -50,15 +49,15 @@ func TestMarshalProfileRequest(t *testing.T) { EST := time.FixedZone("EST", -5*60*60) - profileRequest := ofxgo.ProfileRequest{ + profileRequest := ProfileRequest{ TrnUID: "983373", - DtProfUp: *ofxgo.NewDate(2016, 1, 1, 0, 0, 0, 0, EST), + DtProfUp: *NewDate(2016, 1, 1, 0, 0, 0, 0, EST), } request.Prof = append(request.Prof, &profileRequest) request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() - request.Signon.DtClient = *ofxgo.NewDate(2016, 6, 14, 7, 34, 0, 0, EST) + request.Signon.DtClient = *NewDate(2016, 6, 14, 7, 34, 0, 0, EST) marshalCheckRequest(t, &request, expectedString) } @@ -213,89 +212,89 @@ NEWFILEUID:NONE `) - var expected ofxgo.Response + var expected Response - expected.Version = ofxgo.OfxVersion102 + expected.Version = OfxVersion102 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" - expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 3, 9, 34, 58, 0) + expected.Signon.DtServer = *NewDateGMT(2017, 4, 3, 9, 34, 58, 0) expected.Signon.Language = "ENG" - expected.Signon.DtProfUp = ofxgo.NewDateGMT(2002, 11, 19, 14, 0, 0, 0) + expected.Signon.DtProfUp = NewDateGMT(2002, 11, 19, 14, 0, 0, 0) - profileResponse := ofxgo.ProfileResponse{ + profileResponse := ProfileResponse{ TrnUID: "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab", - Status: ofxgo.Status{ + Status: Status{ Code: 0, Severity: "INFO", }, - MessageSetList: ofxgo.MessageSetList{ - ofxgo.MessageSet{ + MessageSetList: MessageSetList{ + MessageSet{ Name: "SIGNONMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", - OfxSec: ofxgo.OfxSecNone, + OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", - Language: []ofxgo.String{"ENG"}, - SyncMode: ofxgo.SyncModeLite, + Language: []String{"ENG"}, + SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, - ofxgo.MessageSet{ + MessageSet{ Name: "SIGNUPMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", - OfxSec: ofxgo.OfxSecNone, + OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", - Language: []ofxgo.String{"ENG"}, - SyncMode: ofxgo.SyncModeLite, + Language: []String{"ENG"}, + SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, - ofxgo.MessageSet{ + MessageSet{ Name: "INVSTMTMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", - OfxSec: ofxgo.OfxSecNone, + OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", - Language: []ofxgo.String{"ENG"}, - SyncMode: ofxgo.SyncModeLite, + Language: []String{"ENG"}, + SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, - ofxgo.MessageSet{ + MessageSet{ Name: "SECLISTMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", - OfxSec: ofxgo.OfxSecNone, + OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", - Language: []ofxgo.String{"ENG"}, - SyncMode: ofxgo.SyncModeLite, + Language: []String{"ENG"}, + SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, - ofxgo.MessageSet{ + MessageSet{ Name: "PROFMSGSETV1", Ver: 1, URL: "https://ofx.example.com/cgi-ofx/exampleofx", - OfxSec: ofxgo.OfxSecNone, + OfxSec: OfxSecNone, TranspSec: true, SignonRealm: "Example Trade", - Language: []ofxgo.String{"ENG"}, - SyncMode: ofxgo.SyncModeLite, + Language: []String{"ENG"}, + SyncMode: SyncModeLite, RespFileER: false, // Ignored: 300 }, }, - SignonInfoList: []ofxgo.SignonInfo{ + SignonInfoList: []SignonInfo{ { SignonRealm: "Example Trade", Min: 1, Max: 32, - CharType: ofxgo.CharTypeAlphaOrNumeric, + CharType: CharTypeAlphaOrNumeric, CaseSen: false, Special: true, Spaces: false, @@ -303,7 +302,7 @@ NEWFILEUID:NONE ChgPinFirst: false, }, }, - DtProfUp: *ofxgo.NewDateGMT(2002, 11, 19, 14, 0, 0, 0), + DtProfUp: *NewDateGMT(2002, 11, 19, 14, 0, 0, 0), FiName: "Example Trade Financial", Addr1: "5555 Buhunkus Drive", City: "Someville", @@ -319,7 +318,7 @@ NEWFILEUID:NONE } expected.Prof = append(expected.Prof, &profileResponse) - response, err := ofxgo.ParseResponse(responseReader) + response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } diff --git a/request_test.go b/request_test.go index 3712f82..780808e 100644 --- a/request_test.go +++ b/request_test.go @@ -1,7 +1,6 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "regexp" "strings" "testing" @@ -10,7 +9,7 @@ import ( // match leading and trailing whitespace on each line var ignoreSpacesRe = regexp.MustCompile("(?m)^[ \t]+|[ \t]*$[\r\n]+") -func marshalCheckRequest(t *testing.T, request *ofxgo.Request, expected string) { +func marshalCheckRequest(t *testing.T, request *Request, expected string) { t.Helper() buf, err := request.Marshal() if err != nil { diff --git a/response.go b/response.go index f88ee58..355a491 100644 --- a/response.go +++ b/response.go @@ -380,7 +380,7 @@ func DecodeResponse(reader io.Reader) (*Response, error) { // Valid returns whether the Response is valid according to the OFX spec func (or *Response) Valid() (bool, error) { - var errs ErrInvalid + var errs errInvalid if ok, err := or.Signon.Valid(or.Version); !ok { errs.AddErr(err) } @@ -477,11 +477,11 @@ func (or *Response) Marshal() (*bytes.Buffer, error) { return &b, nil } -// ErrInvalid represents validation failures while parsing an OFX response +// errInvalid represents validation failures while parsing an OFX response // If an institution returns slightly malformed data, ParseResponse will return a best-effort parsed response and a validation error. -type ErrInvalid []error +type errInvalid []error -func (e ErrInvalid) Error() string { +func (e errInvalid) Error() string { var errStrings []string for _, err := range e { errStrings = append(errStrings, err.Error()) @@ -489,9 +489,9 @@ func (e ErrInvalid) Error() string { return fmt.Sprintf("Validation failed: %s", strings.Join(errStrings, "; ")) } -func (e *ErrInvalid) AddErr(err error) { +func (e *errInvalid) AddErr(err error) { if err != nil { - if errs, ok := err.(ErrInvalid); ok { + if errs, ok := err.(errInvalid); ok { *e = append(*e, errs...) } else { *e = append(*e, err) @@ -499,7 +499,7 @@ func (e *ErrInvalid) AddErr(err error) { } } -func (e ErrInvalid) ErrOrNil() error { +func (e errInvalid) ErrOrNil() error { if len(e) > 0 { return e } diff --git a/response_test.go b/response_test.go index 54f6895..d288607 100644 --- a/response_test.go +++ b/response_test.go @@ -1,4 +1,4 @@ -package ofxgo_test +package ofxgo import ( "bytes" @@ -9,7 +9,6 @@ import ( "reflect" "testing" - "github.com/aclindsa/ofxgo" "github.com/aclindsa/xml" ) @@ -135,16 +134,16 @@ func checkEqual(t *testing.T, fieldName string, expected, actual reflect.Value) } } -func checkResponsesEqual(t *testing.T, expected, actual *ofxgo.Response) { +func checkResponsesEqual(t *testing.T, expected, actual *Response) { checkEqual(t, "", reflect.ValueOf(expected), reflect.ValueOf(actual)) } -func checkResponseRoundTrip(t *testing.T, response *ofxgo.Response) { +func checkResponseRoundTrip(t *testing.T, response *Response) { b, err := response.Marshal() if err != nil { t.Fatalf("Unexpected error re-marshaling OFX response: %s\n", err) } - roundtripped, err := ofxgo.ParseResponse(b) + roundtripped, err := ParseResponse(b) if err != nil { t.Fatalf("Unexpected error re-parsing OFX response: %s\n", err) } @@ -164,7 +163,7 @@ func TestValidSamples(t *testing.T) { if err != nil { t.Fatalf("Unexpected error opening %s: %s\n", path, err) } - response, err := ofxgo.ParseResponse(file) + response, err := ParseResponse(file) if err != nil { t.Fatalf("Unexpected error parsing OFX response in %s: %s\n", path, err) } @@ -212,12 +211,12 @@ NEWFILEUID:NONE const expectedErr = "Validation failed: Invalid STATUS>SEVERITY; Invalid STATUS>SEVERITY" t.Run("parse response", func(t *testing.T) { - resp, err := ofxgo.ParseResponse(bytes.NewReader([]byte(invalidResponse))) + resp, err := ParseResponse(bytes.NewReader([]byte(invalidResponse))) expectedErr := "Validation failed: Invalid STATUS>SEVERITY; Invalid STATUS>SEVERITY" if err == nil { t.Fatalf("ParseResponse should fail with %q, found nil", expectedErr) } - if _, ok := err.(ofxgo.ErrInvalid); !ok { + if _, ok := err.(errInvalid); !ok { t.Errorf("ParseResponse should return an error with type ErrInvalid, found %T", err) } if err.Error() != expectedErr { @@ -229,7 +228,7 @@ NEWFILEUID:NONE }) t.Run("parse failed", func(t *testing.T) { - resp, err := ofxgo.ParseResponse(bytes.NewReader(nil)) + resp, err := ParseResponse(bytes.NewReader(nil)) if err == nil { t.Error("ParseResponse should fail to decode") } @@ -239,7 +238,7 @@ NEWFILEUID:NONE }) t.Run("decode, then validate response", func(t *testing.T) { - resp, err := ofxgo.DecodeResponse(bytes.NewReader([]byte(invalidResponse))) + resp, err := DecodeResponse(bytes.NewReader([]byte(invalidResponse))) if err != nil { t.Errorf("Unexpected error: %s", err.Error()) } @@ -253,7 +252,7 @@ NEWFILEUID:NONE if err == nil { t.Fatalf("response.Valid() should fail with %q, found nil", expectedErr) } - if _, ok := err.(ofxgo.ErrInvalid); !ok { + if _, ok := err.(errInvalid); !ok { t.Errorf("response.Valid() should return an error of type ErrInvalid, found: %T", err) } if err.Error() != expectedErr { @@ -264,7 +263,7 @@ NEWFILEUID:NONE func TestErrInvalidError(t *testing.T) { expectedErr := `Validation failed: A; B; C` - actualErr := ofxgo.ErrInvalid{ + actualErr := errInvalid{ errors.New("A"), errors.New("B"), errors.New("C"), @@ -276,7 +275,7 @@ func TestErrInvalidError(t *testing.T) { func TestErrInvalidAddErr(t *testing.T) { t.Run("nil error should be a no-op", func(t *testing.T) { - var errs ofxgo.ErrInvalid + var errs errInvalid errs.AddErr(nil) if len(errs) != 0 { t.Errorf("Nil err should not be added") @@ -284,18 +283,18 @@ func TestErrInvalidAddErr(t *testing.T) { }) t.Run("adds an error normally", func(t *testing.T) { - var errs ofxgo.ErrInvalid + var errs errInvalid errs.AddErr(errors.New("some error")) }) t.Run("adding the same type should flatten the errors", func(t *testing.T) { - var errs ofxgo.ErrInvalid - errs.AddErr(ofxgo.ErrInvalid{ + var errs errInvalid + errs.AddErr(errInvalid{ errors.New("A"), errors.New("B"), }) - errs.AddErr(ofxgo.ErrInvalid{ + errs.AddErr(errInvalid{ errors.New("C"), }) if len(errs) != 3 { @@ -305,7 +304,7 @@ func TestErrInvalidAddErr(t *testing.T) { } func TestErrInvalidErrOrNil(t *testing.T) { - var errs ofxgo.ErrInvalid + var errs errInvalid if err := errs.ErrOrNil(); err != nil { t.Errorf("No added errors should return nil, found: %v", err) } @@ -315,11 +314,11 @@ func TestErrInvalidErrOrNil(t *testing.T) { if err == nil { t.Fatal("Expected an error, found nil.") } - if _, ok := err.(ofxgo.ErrInvalid); !ok { - t.Fatalf("Expected err to be of type ErrInvalid, found: %T", err) + if _, ok := err.(errInvalid); !ok { + t.Fatalf("Expected err to be of type errInvalid, found: %T", err) } - errInvalid := err.(ofxgo.ErrInvalid) - if len(errInvalid) != 1 || errInvalid[0] != someError { + errInv := err.(errInvalid) + if len(errInv) != 1 || errInv[0] != someError { t.Errorf("Expected ErrOrNil to return itself, found: %v", err) } } diff --git a/signon_test.go b/signon_test.go index 4942eb5..68a1fee 100644 --- a/signon_test.go +++ b/signon_test.go @@ -1,18 +1,17 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "testing" ) func TestMarshalInvalidSignons(t *testing.T) { - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", - SpecVersion: ofxgo.OfxVersion203, + SpecVersion: OfxVersion203, } - var request ofxgo.Request + var request Request request.Signon.UserID = "myusername" request.Signon.UserPass = "Pa$$word" request.Signon.Org = "BNK" diff --git a/signup_test.go b/signup_test.go index 115ec1f..d4a477b 100644 --- a/signup_test.go +++ b/signup_test.go @@ -1,7 +1,6 @@ -package ofxgo_test +package ofxgo import ( - "github.com/aclindsa/ofxgo" "strings" "testing" "time" @@ -37,27 +36,27 @@ func TestMarshalAcctInfoRequest(t *testing.T) { EST := time.FixedZone("EST", -5*60*60) - var client = ofxgo.BasicClient{ + var client = BasicClient{ AppID: "OFXGO", AppVer: "0001", - SpecVersion: ofxgo.OfxVersion203, + SpecVersion: OfxVersion203, } - var request ofxgo.Request + var request Request request.Signon.UserID = "myusername" request.Signon.UserPass = "Pa$$word" request.Signon.Org = "BNK" request.Signon.Fid = "1987" - acctInfoRequest := ofxgo.AcctInfoRequest{ + acctInfoRequest := AcctInfoRequest{ TrnUID: "e3ad9bda-38fa-4e5b-8099-1bd567ddef7a", - DtAcctUp: *ofxgo.NewDate(2015, 12, 21, 18, 29, 45, 0, EST), + DtAcctUp: *NewDate(2015, 12, 21, 18, 29, 45, 0, EST), } request.Signup = append(request.Signup, &acctInfoRequest) request.SetClientFields(&client) // Overwrite the DtClient value set by SetClientFields to time.Now() - request.Signon.DtClient = *ofxgo.NewDate(2016, 1, 15, 11, 23, 0, 0, EST) + request.Signon.DtClient = *NewDate(2016, 1, 15, 11, 23, 0, 0, EST) marshalCheckRequest(t, &request, expectedString) } @@ -110,38 +109,38 @@ func TestUnmarshalAcctInfoResponse(t *testing.T) { `) - var expected ofxgo.Response + var expected Response - expected.Version = ofxgo.OfxVersion203 + expected.Version = OfxVersion203 expected.Signon.Status.Code = 0 expected.Signon.Status.Severity = "INFO" - expected.Signon.DtServer = *ofxgo.NewDateGMT(2006, 1, 15, 11, 23, 03, 0) + expected.Signon.DtServer = *NewDateGMT(2006, 1, 15, 11, 23, 03, 0) expected.Signon.Language = "ENG" - expected.Signon.DtProfUp = ofxgo.NewDateGMT(2005, 2, 21, 9, 13, 0, 0) - expected.Signon.DtAcctUp = ofxgo.NewDateGMT(2006, 1, 2, 16, 0, 0, 0) + expected.Signon.DtProfUp = NewDateGMT(2005, 2, 21, 9, 13, 0, 0) + expected.Signon.DtAcctUp = NewDateGMT(2006, 1, 2, 16, 0, 0, 0) expected.Signon.Org = "BNK" expected.Signon.Fid = "1987" - bankacctinfo := ofxgo.BankAcctInfo{ - BankAcctFrom: ofxgo.BankAcct{ + bankacctinfo := BankAcctInfo{ + BankAcctFrom: BankAcct{ BankID: "8367556009", AcctID: "000999847", - AcctType: ofxgo.AcctTypeMoneyMrkt, + AcctType: AcctTypeMoneyMrkt, }, SupTxDl: true, XferSrc: true, XferDest: true, - SvcStatus: ofxgo.SvcStatusActive, + SvcStatus: SvcStatusActive, } - acctInfoResponse := ofxgo.AcctInfoResponse{ + acctInfoResponse := AcctInfoResponse{ TrnUID: "10938754", - Status: ofxgo.Status{ + Status: Status{ Code: 0, Severity: "INFO", }, - DtAcctUp: *ofxgo.NewDateGMT(2005, 2, 28, 0, 0, 0, 0), - AcctInfo: []ofxgo.AcctInfo{{ + DtAcctUp: *NewDateGMT(2005, 2, 28, 0, 0, 0, 0), + AcctInfo: []AcctInfo{{ Desc: "Personal Checking", Phone: "888-222-5827", BankAcctInfo: &bankacctinfo, @@ -149,7 +148,7 @@ func TestUnmarshalAcctInfoResponse(t *testing.T) { } expected.Signup = append(expected.Signup, &acctInfoResponse) - response, err := ofxgo.ParseResponse(responseReader) + response, err := ParseResponse(responseReader) if err != nil { t.Fatalf("Unexpected error unmarshalling response: %s\n", err) } diff --git a/types_test.go b/types_test.go index 028bd76..d0765d3 100644 --- a/types_test.go +++ b/types_test.go @@ -1,8 +1,7 @@ -package ofxgo_test +package ofxgo import ( "fmt" - "github.com/aclindsa/ofxgo" "github.com/aclindsa/xml" "reflect" "testing" @@ -57,7 +56,7 @@ func unmarshalHelper(t *testing.T, input string, expected interface{}, overwritt } func TestMarshalInt(t *testing.T) { - var i ofxgo.Int = 927 + var i Int = 927 marshalHelper(t, "927", &i) i = 0 marshalHelper(t, "0", &i) @@ -66,7 +65,7 @@ func TestMarshalInt(t *testing.T) { } func TestUnmarshalInt(t *testing.T) { - var i, overwritten ofxgo.Int = -48394, 0 + var i, overwritten Int = -48394, 0 unmarshalHelper(t, "-48394", &i, &overwritten) i = 0 unmarshalHelper(t, "0", &i, &overwritten) @@ -78,7 +77,7 @@ func TestUnmarshalInt(t *testing.T) { } func TestMarshalAmount(t *testing.T) { - var a ofxgo.Amount + var a Amount a.SetFrac64(8, 1) marshalHelper(t, "8", &a) @@ -95,13 +94,13 @@ func TestMarshalAmount(t *testing.T) { } func TestUnmarshalAmount(t *testing.T) { - var a, overwritten ofxgo.Amount + var a, overwritten Amount // Amount/big.Rat needs a special equality test because reflect.DeepEqual // doesn't always return equal for two values that big.Rat.Cmp() does eq := func(a, b interface{}) bool { - if amountA, ok := a.(*ofxgo.Amount); ok { - if amountB, ok2 := b.(*ofxgo.Amount); ok2 { + if amountA, ok := a.(*Amount); ok { + if amountB, ok2 := b.(*Amount); ok2 { return amountA.Cmp(&amountB.Rat) == 0 } } @@ -127,18 +126,18 @@ func TestUnmarshalAmount(t *testing.T) { } func TestAmountEqual(t *testing.T) { - assertEq := func(a, b ofxgo.Amount) { + assertEq := func(a, b Amount) { if !a.Equal(b) { t.Fatalf("Amounts should be equal but Equal returned false: %s and %s\n", a, b) } } - assertNEq := func(a, b ofxgo.Amount) { + assertNEq := func(a, b Amount) { if a.Equal(b) { t.Fatalf("Amounts should not be equal but Equal returned true: %s and %s\n", a, b) } } - var a, b ofxgo.Amount + var a, b Amount a.SetInt64(-19487135) b.SetInt64(-19487135) assertEq(a, b) @@ -154,7 +153,7 @@ func TestAmountEqual(t *testing.T) { } func TestMarshalDate(t *testing.T) { - var d *ofxgo.Date + var d *Date UTC := time.FixedZone("UTC", 0) GMT_nodesc := time.FixedZone("", 0) EST := time.FixedZone("EST", -5*60*60) @@ -162,35 +161,35 @@ func TestMarshalDate(t *testing.T) { IST := time.FixedZone("IST", (5*60+30)*60) NST := time.FixedZone("NST", -(3*60+30)*60) - d = ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) + d = NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) marshalHelper(t, "20170314150926.053[0:GMT]", d) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT) marshalHelper(t, "20170314150926.053[5.75:NPT]", d) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST) marshalHelper(t, "20170314150926.053[-5:EST]", d) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, UTC) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, UTC) marshalHelper(t, "20170314150926.053[0:UTC]", d) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST) marshalHelper(t, "20170314150926.053[5.50:IST]", d) - d = ofxgo.NewDate(9999, 11, 1, 23, 59, 59, 1000, EST) + d = NewDate(9999, 11, 1, 23, 59, 59, 1000, EST) marshalHelper(t, "99991101235959.000[-5:EST]", d) - d = ofxgo.NewDate(0, 1, 1, 0, 0, 0, 0, IST) + d = NewDate(0, 1, 1, 0, 0, 0, 0, IST) marshalHelper(t, "00000101000000.000[5.50:IST]", d) - d = &ofxgo.Date{Time: time.Unix(0, 0).In(UTC)} + d = &Date{Time: time.Unix(0, 0).In(UTC)} marshalHelper(t, "19700101000000.000[0:UTC]", d) - d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST) + d = NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST) marshalHelper(t, "20170314000026.053[-5:EST]", d) - d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST) + d = NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST) marshalHelper(t, "20170314000026.053[-3.50:NST]", d) // Time zone without textual description - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT_nodesc) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT_nodesc) marshalHelper(t, "20170314150926.053[0]", d) } func TestUnmarshalDate(t *testing.T) { - var d *ofxgo.Date - var overwritten ofxgo.Date + var d *Date + var overwritten Date GMT := time.FixedZone("GMT", 0) EST := time.FixedZone("EST", -5*60*60) NPT := time.FixedZone("NPT", (5*60+45)*60) @@ -199,8 +198,8 @@ func TestUnmarshalDate(t *testing.T) { NST_nodesc := time.FixedZone("", -(3*60+30)*60) eq := func(a, b interface{}) bool { - if dateA, ok := a.(*ofxgo.Date); ok { - if dateB, ok2 := b.(*ofxgo.Date); ok2 { + if dateA, ok := a.(*Date); ok { + if dateB, ok2 := b.(*Date); ok2 { return dateA.Equal(*dateB) } } @@ -208,14 +207,14 @@ func TestUnmarshalDate(t *testing.T) { } // Ensure omitted fields default to the correct values - d = ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) + d = NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) unmarshalHelper2(t, "20170314150926.053[0]", d, &overwritten, eq) unmarshalHelper2(t, "20170314150926.053", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 0, 0, 0, 0, GMT) + d = NewDate(2017, 3, 14, 0, 0, 0, 0, GMT) unmarshalHelper2(t, "20170314", d, &overwritten, eq) // Ensure all signs on time zone offsets are properly handled - d = ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) + d = NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) unmarshalHelper2(t, "20170314150926.053[0:GMT]", d, &overwritten, eq) unmarshalHelper2(t, "20170314150926.053[+0:GMT]", d, &overwritten, eq) unmarshalHelper2(t, "20170314150926.053[-0:GMT]", d, &overwritten, eq) @@ -223,38 +222,38 @@ func TestUnmarshalDate(t *testing.T) { unmarshalHelper2(t, "20170314150926.053[+0]", d, &overwritten, eq) unmarshalHelper2(t, "20170314150926.053[-0]", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT) unmarshalHelper2(t, "20170314150926.053[5.75:NPT]", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST) unmarshalHelper2(t, "20170314150926.053[-5:EST]", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT) unmarshalHelper2(t, "20170314150926.053[0:GMT]", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST) unmarshalHelper2(t, "20170314150926.053[5.50:IST]", d, &overwritten, eq) - d = ofxgo.NewDate(2018, 11, 1, 23, 59, 58, 0, EST) + d = NewDate(2018, 11, 1, 23, 59, 58, 0, EST) unmarshalHelper2(t, "20181101235958.000[-5:EST]", d, &overwritten, eq) - d = ofxgo.NewDate(0, 1, 1, 0, 0, 0, 0, IST) + d = NewDate(0, 1, 1, 0, 0, 0, 0, IST) unmarshalHelper2(t, "00000101000000.000[5.50:IST]", d, &overwritten, eq) - d = &ofxgo.Date{Time: time.Unix(0, 0).In(GMT)} + d = &Date{Time: time.Unix(0, 0).In(GMT)} unmarshalHelper2(t, "19700101000000.000[0:GMT]", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST) + d = NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST) unmarshalHelper2(t, "20170314000026.053[-5:EST]", d, &overwritten, eq) - d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST) + d = NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST) unmarshalHelper2(t, "20170314000026.053[-3.50:NST]", d, &overwritten, eq) // Autopopulate zone without textual description for GMT - d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT) + d = NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT) unmarshalHelper2(t, "20170314150926.053[0]", d, &overwritten, eq) // but not for others: - d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST_nodesc) + d = NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST_nodesc) unmarshalHelper2(t, "20170314000026.053[-3.50]", d, &overwritten, eq) // Make sure we handle poorly-formatted dates (from Vanguard) - d = ofxgo.NewDate(2016, 12, 7, 16, 0, 0, 0, EST) + d = NewDate(2016, 12, 7, 16, 0, 0, 0, EST) unmarshalHelper2(t, "20161207160000.000[-5:EST]610900.500[-9:BST]", d, &overwritten, eq) // extra part intentionally different to ensure the first timezone is parsed // Make sure we properly handle ending newlines - d = ofxgo.NewDate(2018, 11, 1, 23, 59, 58, 0, EST) + d = NewDate(2018, 11, 1, 23, 59, 58, 0, EST) unmarshalHelper2(t, "20181101235958.000[-5:EST]\n", d, &overwritten, eq) unmarshalHelper2(t, "20181101235958.000[-5:EST]\n\t", d, &overwritten, eq) } @@ -263,23 +262,23 @@ func TestDateEqual(t *testing.T) { GMT := time.FixedZone("GMT", 0) EST := time.FixedZone("EST", -5*60*60) - assertEq := func(a, b *ofxgo.Date) { + assertEq := func(a, b *Date) { if !a.Equal(*b) { t.Fatalf("Dates should be equal but Equal returned false: %s and %s\n", *a, *b) } } - assertNEq := func(a, b *ofxgo.Date) { + assertNEq := func(a, b *Date) { if a.Equal(*b) { t.Fatalf("Dates should not be equal but Equal returned true: %s and %s\n", *a, *b) } } // Ensure omitted fields default to the correct values - gmt1 := ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) - gmt2 := ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT) - est1 := ofxgo.NewDate(2017, 3, 14, 10, 9, 26, 53*1000*1000, EST) - est2 := ofxgo.NewDate(2017, 3, 14, 10, 9, 26, 53*1000*1000+1, EST) - est3 := ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST) + gmt1 := NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000) + gmt2 := NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT) + est1 := NewDate(2017, 3, 14, 10, 9, 26, 53*1000*1000, EST) + est2 := NewDate(2017, 3, 14, 10, 9, 26, 53*1000*1000+1, EST) + est3 := NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST) assertEq(gmt1, gmt2) assertEq(gmt2, gmt1) @@ -291,7 +290,7 @@ func TestDateEqual(t *testing.T) { } func TestMarshalString(t *testing.T) { - var s ofxgo.String = "" + var s String = "" marshalHelper(t, "", &s) s = "foo&bar" marshalHelper(t, "foo&bar", &s) @@ -302,7 +301,7 @@ func TestMarshalString(t *testing.T) { } func TestUnmarshalString(t *testing.T) { - var s, overwritten ofxgo.String = "", "" + var s, overwritten String = "", "" unmarshalHelper(t, "", &s, &overwritten) s = "foo&bar" unmarshalHelper(t, "foo&bar", &s, &overwritten) @@ -318,14 +317,14 @@ func TestUnmarshalString(t *testing.T) { } func TestMarshalBoolean(t *testing.T) { - var b ofxgo.Boolean = true + var b Boolean = true marshalHelper(t, "Y", &b) b = false marshalHelper(t, "N", &b) } func TestUnmarshalBoolean(t *testing.T) { - var b, overwritten ofxgo.Boolean = true, false + var b, overwritten Boolean = true, false unmarshalHelper(t, "Y", &b, &overwritten) b = false unmarshalHelper(t, "N", &b, &overwritten) @@ -335,12 +334,12 @@ func TestUnmarshalBoolean(t *testing.T) { } func TestMarshalUID(t *testing.T) { - var u ofxgo.UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04" + var u UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04" marshalHelper(t, "d1cf3d3d-9ef9-4a97-b180-81706829cb04", &u) } func TestUnmarshalUID(t *testing.T) { - var u, overwritten ofxgo.UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04", "" + var u, overwritten UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04", "" unmarshalHelper(t, "d1cf3d3d-9ef9-4a97-b180-81706829cb04", &u, &overwritten) // Make sure stray newlines are handled properly u = "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab" @@ -349,7 +348,7 @@ func TestUnmarshalUID(t *testing.T) { } func TestUIDRecommendedFormat(t *testing.T) { - var u ofxgo.UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04" + var u UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04" if ok, err := u.RecommendedFormat(); !ok || err != nil { t.Fatalf("UID unexpectedly failed validation\n") } @@ -368,7 +367,7 @@ func TestUIDRecommendedFormat(t *testing.T) { } func TestUIDValid(t *testing.T) { - var u ofxgo.UID = "" + var u UID = "" if ok, err := u.Valid(); ok || err == nil { t.Fatalf("Empty UID unexpectedly valid\n") } @@ -383,7 +382,7 @@ func TestUIDValid(t *testing.T) { } func TestRandomUID(t *testing.T) { - uid, err := ofxgo.RandomUID() + uid, err := RandomUID() if err != nil { t.Fatalf("Unexpected error when calling RandomUID: %s\n", err) } @@ -393,46 +392,46 @@ func TestRandomUID(t *testing.T) { } func TestMarshalCurrSymbol(t *testing.T) { - c, _ := ofxgo.NewCurrSymbol("USD") + c, _ := NewCurrSymbol("USD") marshalHelper(t, "USD", &c) } func TestUnmarshalCurrSymbol(t *testing.T) { - var overwritten ofxgo.CurrSymbol - c, _ := ofxgo.NewCurrSymbol("USD") + var overwritten CurrSymbol + c, _ := NewCurrSymbol("USD") unmarshalHelper(t, "USD", c, &overwritten) // Make sure stray newlines are handled properly - c, _ = ofxgo.NewCurrSymbol("EUR") + c, _ = NewCurrSymbol("EUR") unmarshalHelper(t, "EUR\n", c, &overwritten) unmarshalHelper(t, "EUR\n\t", c, &overwritten) } func TestCurrSymbolEqual(t *testing.T) { - usd1, _ := ofxgo.NewCurrSymbol("USD") - usd2, _ := ofxgo.NewCurrSymbol("USD") + usd1, _ := NewCurrSymbol("USD") + usd2, _ := NewCurrSymbol("USD") if !usd1.Equal(*usd2) { t.Fatalf("Two \"USD\" CurrSymbols returned !Equal()\n") } - xxx, _ := ofxgo.NewCurrSymbol("XXX") + xxx, _ := NewCurrSymbol("XXX") if usd1.Equal(*xxx) { t.Fatalf("\"USD\" and \"XXX\" CurrSymbols returned Equal()\n") } } func TestCurrSymbolValid(t *testing.T) { - var initial ofxgo.CurrSymbol + var initial CurrSymbol ok, err := initial.Valid() if ok || err == nil { t.Fatalf("CurrSymbol unexpectedly returned Valid() for initial value\n") } - ars, _ := ofxgo.NewCurrSymbol("ARS") + ars, _ := NewCurrSymbol("ARS") ok, err = ars.Valid() if !ok || err != nil { t.Fatalf("CurrSymbol unexpectedly returned !Valid() for \"ARS\": %s\n", err.Error()) } - xxx, _ := ofxgo.NewCurrSymbol("XXX") + xxx, _ := NewCurrSymbol("XXX") ok, err = xxx.Valid() if ok || err == nil { t.Fatalf("CurrSymbol unexpectedly returned Valid() for \"XXX\"\n") @@ -440,21 +439,21 @@ func TestCurrSymbolValid(t *testing.T) { } func TestNewCurrSymbol(t *testing.T) { - curr, err := ofxgo.NewCurrSymbol("GBP") + curr, err := NewCurrSymbol("GBP") if err != nil { t.Fatalf("Unexpected error calling NewCurrSymbol: %s\n", err) } if curr.String() != "GBP" { t.Fatalf("Created CurrSymbol doesn't print \"GBP\" as string representation\n") } - curr, err = ofxgo.NewCurrSymbol("AFN") + curr, err = NewCurrSymbol("AFN") if err != nil { t.Fatalf("Unexpected error calling NewCurrSymbol: %s\n", err) } if curr.String() != "AFN" { t.Fatalf("Created CurrSymbol doesn't print \"AFN\" as string representation\n") } - curr, err = ofxgo.NewCurrSymbol("BLAH") + curr, err = NewCurrSymbol("BLAH") if err == nil { t.Fatalf("NewCurrSymbol didn't error on invalid currency identifier\n") }