From faebdaeaae32a5d6408f3d86fd28daa134a11536 Mon Sep 17 00:00:00 2001 From: John Starich Date: Tue, 10 Mar 2020 20:53:16 -0500 Subject: [PATCH] Add test for getting ledger opening balances --- ledger/ledger_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ledger/ledger_test.go b/ledger/ledger_test.go index 55ef1c4..b77b5f9 100644 --- a/ledger/ledger_test.go +++ b/ledger/ledger_test.go @@ -913,3 +913,27 @@ func TestSize(t *testing.T) { require.NoError(t, err) assert.Equal(t, len(txns), l.Size()) } + +func TestOpeningBalances(t *testing.T) { + l, err := New(nil) + require.NoError(t, err) + _, ok := l.OpeningBalances() + assert.False(t, ok, "No opening balance expected") + + txns := []Transaction{ + { + Date: parseDate(t, "2020/01/01"), + Payee: "some payee", + Postings: []Posting{ + {Account: "assets", Amount: *decFloat(10)}, + {Account: "liabilities", Amount: *decFloat(32)}, + {Account: "*Opening-Balances", Tags: map[string]string{idTag: OpeningBalanceID}}, + }, + }, + } + l, err = New(txns) + require.NoError(t, err) + opening, ok := l.OpeningBalances() + require.True(t, ok) + assert.Equal(t, txns[0], opening) +}