From 51f20a76c509e690aea81350b1b67517ed3e2d18 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 11 Jun 2021 14:53:07 +0300 Subject: [PATCH] [#307] v2/accounting/test: Do not allocate memory if `!empty` Move all memory allocation and field settings in `Generate...(empty bool)` functions behind `if !empty` check. Signed-off-by: Pavel Karpy --- v2/accounting/test/generate.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/v2/accounting/test/generate.go b/v2/accounting/test/generate.go index b2c0d955..abd9fb85 100644 --- a/v2/accounting/test/generate.go +++ b/v2/accounting/test/generate.go @@ -9,7 +9,10 @@ import ( func GenerateBalanceRequest(empty bool) *accounting.BalanceRequest { m := new(accounting.BalanceRequest) - m.SetBody(GenerateBalanceRequestBody(empty)) + if !empty { + m.SetBody(GenerateBalanceRequestBody(false)) + } + m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) @@ -19,7 +22,9 @@ func GenerateBalanceRequest(empty bool) *accounting.BalanceRequest { func GenerateBalanceRequestBody(empty bool) *accounting.BalanceRequestBody { m := new(accounting.BalanceRequestBody) - m.SetOwnerID(accountingtest.GenerateOwnerID(empty)) + if !empty { + m.SetOwnerID(accountingtest.GenerateOwnerID(false)) + } return m } @@ -27,7 +32,10 @@ func GenerateBalanceRequestBody(empty bool) *accounting.BalanceRequestBody { func GenerateBalanceResponse(empty bool) *accounting.BalanceResponse { m := new(accounting.BalanceResponse) - m.SetBody(GenerateBalanceResponseBody(empty)) + if !empty { + m.SetBody(GenerateBalanceResponseBody(false)) + } + m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) @@ -37,7 +45,9 @@ func GenerateBalanceResponse(empty bool) *accounting.BalanceResponse { func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponseBody { m := new(accounting.BalanceResponseBody) - m.SetBalance(GenerateDecimal(empty)) + if !empty { + m.SetBalance(GenerateDecimal(false)) + } return m }