From 24e5b18ded8588d4bbeeccc21748170aa51bb012 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 23 Feb 2022 22:08:47 +0000 Subject: [PATCH] Implement linter fixes --- postgres/numeric/numeric.go | 9 ++------- postgres/numeric/numeric_test.go | 10 ++++++++-- postgres/ynab-import.go | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/postgres/numeric/numeric.go b/postgres/numeric/numeric.go index 149c615..cf1ff73 100644 --- a/postgres/numeric/numeric.go +++ b/postgres/numeric/numeric.go @@ -18,16 +18,11 @@ func Zero() Numeric { } func FromInt64(value int64) Numeric { - num := Numeric{} - num.Set(value) - return num + return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Status: pgtype.Present}} } func FromInt64WithExp(value int64, exp int32) Numeric { - num := Numeric{} - num.Set(value) - num.Exp = exp - return num + return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Exp: exp, Status: pgtype.Present}} } func (n Numeric) GetFloat64() float64 { diff --git a/postgres/numeric/numeric_test.go b/postgres/numeric/numeric_test.go index a49ab14..b7ef5e9 100644 --- a/postgres/numeric/numeric_test.go +++ b/postgres/numeric/numeric_test.go @@ -12,6 +12,7 @@ type TestCaseMarshalJSON struct { } func TestMarshalJSON(t *testing.T) { + t.Parallel() tests := []TestCaseMarshalJSON{ {numeric.Zero(), `0`}, {numeric.MustParse("1.23"), "1.23"}, @@ -21,8 +22,10 @@ func TestMarshalJSON(t *testing.T) { {numeric.MustParse("-1,24"), "-1.24"}, {numeric.MustParse("-123456789.12345"), "-123456789.12345"}, } - for _, test := range tests { + for i := range tests { + test := tests[i] t.Run(test.Result, func(t *testing.T) { + t.Parallel() z := test.Value result, err := z.MarshalJSON() if err != nil { @@ -44,6 +47,7 @@ type TestCaseParse struct { } func TestParse(t *testing.T) { + t.Parallel() tests := []TestCaseParse{ {numeric.FromInt64WithExp(0, 0), `0`}, {numeric.FromInt64WithExp(1, 0), `1`}, @@ -60,8 +64,10 @@ func TestParse(t *testing.T) { {numeric.FromInt64WithExp(-124, -2), "-1,24"}, {numeric.FromInt64WithExp(-12345678912345, -5), "-123456789.12345"}, } - for _, test := range tests { + for i := range tests { + test := tests[i] t.Run(test.Value, func(t *testing.T) { + t.Parallel() result, err := numeric.Parse(test.Value) if err != nil { t.Error(err) diff --git a/postgres/ynab-import.go b/postgres/ynab-import.go index 384e373..83c5f9d 100644 --- a/postgres/ynab-import.go +++ b/postgres/ynab-import.go @@ -296,7 +296,7 @@ func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payee } func GetAmount(inflow string, outflow string) (numeric.Numeric, error) { - in, err := numeric.Parse(inflow) + in, err := numeric.ParseCurrency(inflow) if err != nil { return in, fmt.Errorf("parse inflow: %w", err) } @@ -306,7 +306,7 @@ func GetAmount(inflow string, outflow string) (numeric.Numeric, error) { } // if inflow is zero, use outflow - out, err := numeric.Parse("-" + outflow) + out, err := numeric.ParseCurrency("-" + outflow) if err != nil { return out, fmt.Errorf("parse outflow: %w", err) }