Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent d78be6a commit daffa58
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/alitto/pond v1.9.2
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10
github.com/bluele/gcache v0.0.2
github.com/formancehq/go-libs v1.7.2-0.20240924160248-25cc3741eba3
github.com/formancehq/go-libs v1.7.2-0.20240926132511-af18433b7404
github.com/formancehq/stack/ledger/client v0.0.0-00010101000000-000000000000
github.com/go-chi/chi/v5 v5.1.0
github.com/go-chi/cors v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/formancehq/go-libs v1.7.2-0.20240924160248-25cc3741eba3 h1:kVhzD+1pd8U8e423d15DQTscWAD4602VdRomuIebqiE=
github.com/formancehq/go-libs v1.7.2-0.20240924160248-25cc3741eba3/go.mod h1:ynmWBbsdhVyjE+MxneMErtgd/RnNAk892VuIhZE2fps=
github.com/formancehq/go-libs v1.7.2-0.20240926132511-af18433b7404 h1:OJJV0eSxdyjrHDadGYzVkdwrQdoD7d/LSx3G5GlkFK8=
github.com/formancehq/go-libs v1.7.2-0.20240926132511-af18433b7404/go.mod h1:ynmWBbsdhVyjE+MxneMErtgd/RnNAk892VuIhZE2fps=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec=
Expand Down
4 changes: 2 additions & 2 deletions internal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const (
)

type Account struct {
Address string `json:"address,type:varchar"`
Metadata metadata.Metadata `json:"metadata,type:jsonb"`
Address string `json:"address"`
Metadata metadata.Metadata `json:"metadata"`
FirstUsage time.Time `json:"-"`
InsertionDate time.Time `json:"_"`
UpdatedAt time.Time `json:"-"`
Expand Down
3 changes: 3 additions & 0 deletions internal/api/v1/controllers_accounts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func countAccounts(w http.ResponseWriter, r *http.Request) {
return nil, err
}
options.QueryBuilder, err = buildAccountsFilterQuery(r)
if err != nil {
return nil, err
}
return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil
})
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/api/v1/controllers_accounts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func listAccounts(w http.ResponseWriter, r *http.Request) {
return nil, err
}
options.QueryBuilder, err = buildAccountsFilterQuery(r)
if err != nil {
return nil, err
}
return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil
})
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/api/v1/controllers_balances_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func getBalances(w http.ResponseWriter, r *http.Request) {
return nil, err
}
options.QueryBuilder, err = buildAccountsFilterQuery(r)
if err != nil {
return nil, err
}
return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil
})
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions internal/api/v2/controllers_ledgers_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ func TestListLedgers(t *testing.T) {
require.Equal(t, http.StatusOK, rec.Code)
cursor := api.DecodeCursorResponse[ledger.Ledger](t, rec.Body)

for i, l := range tc.returnData {
tc.returnData[i] = l
}

require.Equal(t, tc.returnData, cursor.Data)
} else {
require.Equal(t, tc.expectedStatusCode, rec.Code)
Expand Down
4 changes: 2 additions & 2 deletions internal/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (s *DeleteMetadataLogPayload) UnmarshalJSON(data []byte) error {
id, err = strconv.ParseInt(string(x.TargetID), 10, 64)
id = int(id.(int64))
default:
return fmt.Errorf("unknown type " + x.TargetType)
return fmt.Errorf("unknown type '%s'", x.TargetType)
}
if err != nil {
return err
Expand Down Expand Up @@ -320,7 +320,7 @@ func HydrateLog(_type LogType, data []byte) (any, error) {
case RevertedTransactionLogType:
payload = &RevertedTransactionLogPayload{}
default:
return nil, fmt.Errorf("unknown type " + _type.String())
return nil, fmt.Errorf("unknown type '%s'", _type)
}
err := json.Unmarshal(data, &payload)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/machine/funding.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (f Funding) Take(amount *MonetaryInt) (Funding, Funding, error) {
return fp.Account.String()
})

return Funding{}, Funding{}, NewErrInsufficientFund(fmt.Sprintf("account(s) %s had/have insufficient funds", strings.Join(lstAccounts, "|")))
return Funding{}, Funding{}, NewErrInsufficientFund("account(s) %s had/have insufficient funds", strings.Join(lstAccounts, "|"))
}
return result, remainder, nil
}
Expand Down
12 changes: 6 additions & 6 deletions internal/machine/vm/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (m *Machine) tick() (bool, error) {
}
allotment, err := machine.NewAllotment(portions)
if err != nil {
return true, machine.NewErrInvalidScript(err.Error())
return true, machine.NewErrInvalidScript("%s", err)
}
m.pushValue(*allotment)

Expand All @@ -294,7 +294,7 @@ func (m *Machine) tick() (bool, error) {
account := pop[machine.AccountAddress](m)
funding, err := m.withdrawAll(account, overdraft.Asset, overdraft.Amount)
if err != nil {
return true, machine.NewErrInvalidScript(err.Error())
return true, machine.NewErrInvalidScript("%s", err)
}
m.pushValue(*funding)

Expand All @@ -303,7 +303,7 @@ func (m *Machine) tick() (bool, error) {
account := pop[machine.AccountAddress](m)
funding, err := m.withdrawAlways(account, mon)
if err != nil {
return true, machine.NewErrInvalidScript(err.Error())
return true, machine.NewErrInvalidScript("%s", err)
}
m.pushValue(*funding)

Expand All @@ -315,7 +315,7 @@ func (m *Machine) tick() (bool, error) {
}
result, remainder, err := funding.Take(mon.Amount)
if err != nil {
return true, machine.NewErrInsufficientFund(err.Error())
return true, machine.NewErrInsufficientFund("%s", err)
}
m.pushValue(remainder)
m.pushValue(result)
Expand Down Expand Up @@ -366,7 +366,7 @@ func (m *Machine) tick() (bool, error) {
for i := 0; i < n; i++ {
res, err := result.Concat(fundings_rev[n-1-i])
if err != nil {
return true, machine.NewErrInvalidScript(err.Error())
return true, machine.NewErrInvalidScript("%s", err)
}
result = res
}
Expand Down Expand Up @@ -637,7 +637,7 @@ func (m *Machine) ResolveResources(ctx context.Context, store Store) error {
func (m *Machine) SetVarsFromJSON(vars map[string]string) error {
v, err := m.Program.ParseVariablesJSON(vars)
if err != nil {
return machine.NewErrInvalidVars(err.Error())
return machine.NewErrInvalidVars("%s", err)
}
m.Vars = v
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/ledger/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (account Account) toCore() ledger.ExpandedAccount {
}

var (
balanceRegex = regexp.MustCompile("balance\\[(.*)\\]")
balanceRegex = regexp.MustCompile(`balance\\[(.*)\\]`)
)

func convertOperatorToSQL(operator string) string {
Expand Down
1 change: 1 addition & 0 deletions internal/storage/ledger/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ledger
import (
"context"
"fmt"

"github.com/formancehq/go-libs/platform/postgres"

"github.com/formancehq/ledger/internal/tracing"
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/ledger/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

var (
metadataRegex = regexp.MustCompile("metadata\\[(.+)\\]")
metadataRegex = regexp.MustCompile(`metadata\\[(.+)\\]`)
)

type Transaction struct {
Expand Down
7 changes: 4 additions & 3 deletions internal/storage/ledger/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ func TestTransactionDeleteMetadata(t *testing.T) {
require.Equal(t, metadata.Metadata{"foo2": "bar2"}, tx.Metadata)

// delete a not existing metadata
tx1, modified, err = store.DeleteTransactionMetadata(ctx, tx1.ID, "foo1")
_, modified, err = store.DeleteTransactionMetadata(ctx, tx1.ID, "foo1")
require.NoError(t, err)
require.False(t, modified)

// delete metadata of a non existing transaction
tx1, modified, err = store.DeleteTransactionMetadata(ctx, 10, "foo1")
_, modified, err = store.DeleteTransactionMetadata(ctx, 10, "foo1")
require.Error(t, err)
require.True(t, errors.Is(err, postgres.ErrNotFound))
require.False(t, modified)
Expand Down Expand Up @@ -480,7 +480,7 @@ func TestTransactionsRevert(t *testing.T) {
require.Equal(t, tx1, *revertedTx)

// try to revert again
revertedTx, reverted, err = store.RevertTransaction(ctx, tx1.ID)
_, reverted, err = store.RevertTransaction(ctx, tx1.ID)
require.NoError(t, err)
require.False(t, reverted)

Expand Down Expand Up @@ -571,6 +571,7 @@ func TestTransactionsList(t *testing.T) {
_, _, err = store.UpdateTransactionMetadata(ctx, tx3BeforeRevert.ID, metadata.Metadata{
"additional_metadata": "true",
})
require.NoError(t, err)

// refresh tx3
// we can't take the result of the call on RevertTransaction nor UpdateTransactionMetadata as the result does not contains pc(e)v
Expand Down
3 changes: 2 additions & 1 deletion pkg/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package testserver
import (
"context"
"fmt"
"github.com/uptrace/bun"
"io"
"net/http"
"strings"
"testing"
"time"

"github.com/uptrace/bun"

"github.com/formancehq/go-libs/bun/bunconnect"
"github.com/formancehq/go-libs/httpclient"
"github.com/formancehq/go-libs/httpserver"
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"database/sql"
"encoding/json"
"fmt"
"io"
"math/big"

"github.com/formancehq/go-libs/logging"
"github.com/formancehq/go-libs/pointer"
. "github.com/formancehq/go-libs/testing/api"
Expand All @@ -17,8 +20,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/uptrace/bun"
"io"
"math/big"
)

var _ = Context("Ledger integration tests", func() {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ func (h HaveCoherentStateMatcher) Match(actual interface{}) (success bool, err e
}

func (h HaveCoherentStateMatcher) FailureMessage(_ interface{}) (message string) {
return fmt.Sprintf("server should has coherent state")
return "server should has coherent state"
}

func (h HaveCoherentStateMatcher) NegatedFailureMessage(_ interface{}) (message string) {
return fmt.Sprintf("server should not has coherent state but has")
return "server should not has coherent state but has"
}

var _ types.GomegaMatcher = (*HaveCoherentStateMatcher)(nil)
Expand Down

0 comments on commit daffa58

Please sign in to comment.