Skip to content

Commit ecbedc4

Browse files
authored
CI: Enable linting for tests (#1632)
* use linter for tests * fix lint * remove failing AddBlock(&genBlock) from TestDeleteTransactions
1 parent 6dce903 commit ecbedc4

18 files changed

+74
-68
lines changed

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
run:
22
timeout: 5m
3-
tests: false
3+
tests: true
44

55
linters:
66
disable-all: true
@@ -66,4 +66,4 @@ issues:
6666

6767
# revive: ignore some rules
6868
- "^unused-parameter: parameter"
69-
- "^package-comments: should have a package comment"
69+
- "^package-comments: should have a package comment"

api/app_boxes_fixtures_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"fmt"
77
"testing"
88

9-
"github.com/algorand/indexer/v3/idb/postgres"
109
"github.com/stretchr/testify/require"
1110

1211
"github.com/algorand/avm-abi/apps"
12+
"github.com/algorand/indexer/v3/idb/postgres"
13+
"github.com/algorand/indexer/v3/util/test"
14+
1315
"github.com/algorand/go-algorand-sdk/v2/crypto"
1416
sdk "github.com/algorand/go-algorand-sdk/v2/types"
15-
"github.com/algorand/indexer/v3/util/test"
1617
)
1718

1819
func goalEncode(t *testing.T, s string) string {
@@ -23,7 +24,7 @@ func goalEncode(t *testing.T, s string) string {
2324
return string(b2)
2425
}
2526

26-
var goalEncodingExamples map[string]string = map[string]string{
27+
var goalEncodingExamples = map[string]string{
2728
"str": "str",
2829
"string": "string",
2930
"int": "42",

api/handlers_e2e_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/stretchr/testify/assert"
2020
"github.com/stretchr/testify/require"
2121

22+
"github.com/algorand/avm-abi/apps"
2223
"github.com/algorand/indexer/v3/api/generated/v2"
2324
"github.com/algorand/indexer/v3/idb"
2425
"github.com/algorand/indexer/v3/idb/postgres"
@@ -27,7 +28,6 @@ import (
2728
"github.com/algorand/indexer/v3/util"
2829
"github.com/algorand/indexer/v3/util/test"
2930

30-
"github.com/algorand/avm-abi/apps"
3131
"github.com/algorand/go-algorand-sdk/v2/crypto"
3232
"github.com/algorand/go-algorand-sdk/v2/encoding/json"
3333
sdk "github.com/algorand/go-algorand-sdk/v2/types"
@@ -80,7 +80,7 @@ func setupIdb(t *testing.T, genesis sdk.Genesis) (*postgres.IndexerDb, func()) {
8080
Block: test.MakeGenesisBlock(),
8181
Delta: sdk.LedgerStateDelta{},
8282
}
83-
db.AddBlock(&vb)
83+
require.NoError(t, db.AddBlock(&vb))
8484
require.NoError(t, err)
8585

8686
return db, newShutdownFunc
@@ -1738,6 +1738,7 @@ func TestGetBlockWithCompression(t *testing.T) {
17381738
// we now make sure that compression flag works with other flags.
17391739
notCompressedBlock = getBlockFunc(t, true, false)
17401740
compressedBlock = getBlockFunc(t, true, true)
1741+
require.Equal(t, notCompressedBlock, compressedBlock)
17411742
require.Equal(t, len(*notCompressedBlock.Transactions), 0)
17421743
}
17431744

api/handlers_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import (
1717
"github.com/stretchr/testify/mock"
1818
"github.com/stretchr/testify/require"
1919

20-
sdkcrypto "github.com/algorand/go-algorand-sdk/v2/crypto"
21-
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
22-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
2320
"github.com/algorand/indexer/v3/api/generated/v2"
2421
"github.com/algorand/indexer/v3/idb"
2522
"github.com/algorand/indexer/v3/idb/mocks"
2623
"github.com/algorand/indexer/v3/types"
24+
25+
sdkcrypto "github.com/algorand/go-algorand-sdk/v2/crypto"
26+
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
27+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
2728
)
2829

2930
func TestTransactionParamToTransactionFilter(t *testing.T) {
@@ -1187,7 +1188,7 @@ func TestBigNumbers(t *testing.T) {
11871188
c := e.NewContext(req, rec1)
11881189

11891190
// call handler
1190-
tc.callHandler(c, *si)
1191+
require.NoError(t, tc.callHandler(c, *si))
11911192
assert.Equal(t, http.StatusNotFound, rec1.Code)
11921193
bodyStr := rec1.Body.String()
11931194
require.Contains(t, bodyStr, tc.errString)
@@ -1234,7 +1235,7 @@ func TestRewindRoundParameterRejected(t *testing.T) {
12341235
c := e.NewContext(req, rec1)
12351236

12361237
// call handler
1237-
tc.callHandler(c, *si)
1238+
require.NoError(t, tc.callHandler(c, *si))
12381239
assert.Equal(t, http.StatusBadRequest, rec1.Code)
12391240
bodyStr := rec1.Body.String()
12401241
require.Contains(t, bodyStr, tc.errString)

api/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/sirupsen/logrus/hooks/test"
1010
"github.com/stretchr/testify/require"
1111

12-
"github.com/algorand/go-algorand-sdk/v2/types"
13-
1412
"github.com/algorand/indexer/v3/idb"
13+
14+
"github.com/algorand/go-algorand-sdk/v2/types"
1515
)
1616

1717
func TestCallWithTimeoutTimesOut(t *testing.T) {

cmd/algorand-indexer/daemon_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
log "github.com/sirupsen/logrus"
1313
"github.com/spf13/pflag"
1414
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1516

1617
"github.com/algorand/indexer/v3/config"
1718
"github.com/algorand/indexer/v3/util"
@@ -23,7 +24,7 @@ func TestParameterConfigErrorWhenBothFileTypesArePresent(t *testing.T) {
2324
indexerDataDir := t.TempDir()
2425
for _, configFiletype := range config.FileTypes {
2526
autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
26-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
27+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
2728
}
2829

2930
daemonConfig := &daemonConfig{}
@@ -41,7 +42,7 @@ func TestIndexerConfigErrorWhenBothFileTypesArePresent(t *testing.T) {
4142
indexerDataDir := t.TempDir()
4243
for _, configFiletype := range config.FileTypes {
4344
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
44-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
45+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
4546
}
4647

4748
daemonConfig := &daemonConfig{}
@@ -59,7 +60,7 @@ func TestConfigWithEnableAllParamsExpectError(t *testing.T) {
5960
for _, configFiletype := range config.FileTypes {
6061
indexerDataDir := t.TempDir()
6162
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
62-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
63+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
6364
daemonConfig := &daemonConfig{}
6465
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
6566
daemonConfig.indexerDataDir = indexerDataDir
@@ -88,7 +89,7 @@ func TestConfigInvalidExpectError(t *testing.T) {
8889
b := bytes.NewBufferString("")
8990
indexerDataDir := t.TempDir()
9091
tempConfigFile := indexerDataDir + "/indexer-alt.yml"
91-
os.WriteFile(tempConfigFile, []byte(";;;"), fs.ModePerm)
92+
require.NoError(t, os.WriteFile(tempConfigFile, []byte(";;;"), fs.ModePerm))
9293
daemonConfig := &daemonConfig{}
9394
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
9495
daemonConfig.indexerDataDir = indexerDataDir
@@ -102,7 +103,7 @@ func TestConfigInvalidExpectError(t *testing.T) {
102103
func TestConfigSpecifiedTwiceExpectError(t *testing.T) {
103104
indexerDataDir := t.TempDir()
104105
tempConfigFile := indexerDataDir + "/indexer.yml"
105-
os.WriteFile(tempConfigFile, []byte{}, fs.ModePerm)
106+
require.NoError(t, os.WriteFile(tempConfigFile, []byte{}, fs.ModePerm))
106107
daemonConfig := &daemonConfig{}
107108
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
108109
daemonConfig.indexerDataDir = indexerDataDir
@@ -120,7 +121,7 @@ func TestLoadAPIConfigGivenAutoLoadAndUserSuppliedExpectError(t *testing.T) {
120121

121122
autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
122123
userSuppliedPath := filepath.Join(indexerDataDir, "foobar.yml")
123-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
124+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
124125
cfg := &daemonConfig{}
125126
cfg.indexerDataDir = indexerDataDir
126127
cfg.suppliedAPIConfigFile = userSuppliedPath
@@ -149,7 +150,7 @@ func TestLoadAPIConfigGivenAutoLoadExpectSuccess(t *testing.T) {
149150
indexerDataDir := t.TempDir()
150151

151152
autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
152-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
153+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
153154
cfg := &daemonConfig{}
154155
cfg.indexerDataDir = indexerDataDir
155156

@@ -180,7 +181,7 @@ func TestIndexerPidFileCreateFailExpectError(t *testing.T) {
180181
for _, configFiletype := range config.FileTypes {
181182
indexerDataDir := t.TempDir()
182183
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
183-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
184+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
184185

185186
invalidDir := filepath.Join(indexerDataDir, "foo", "bar")
186187
cfg := &daemonConfig{}

cmd/validator/core/validator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"github.com/jarcoal/httpmock"
88
"github.com/stretchr/testify/require"
99

10-
"github.com/algorand/go-algorand-sdk/v2/types"
11-
1210
"github.com/algorand/indexer/v3/api"
11+
12+
"github.com/algorand/go-algorand-sdk/v2/types"
1313
)
1414

1515
type mockProcessor struct {

idb/idb_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"github.com/stretchr/testify/assert"
77
"github.com/stretchr/testify/require"
88

9-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
109
"github.com/algorand/indexer/v3/idb"
1110
"github.com/algorand/indexer/v3/util/test"
11+
12+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1213
)
1314

1415
func TestTxnRowNext(t *testing.T) {

idb/postgres/internal/encoding/encoding_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
8-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
9-
itypes "github.com/algorand/indexer/v3/types"
107
"github.com/stretchr/testify/assert"
118
"github.com/stretchr/testify/require"
129

1310
"github.com/algorand/indexer/v3/idb"
1411
"github.com/algorand/indexer/v3/idb/postgres/internal/types"
12+
itypes "github.com/algorand/indexer/v3/types"
13+
14+
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
15+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1516
)
1617

1718
func TestEncodeSignedTxnWithAD(t *testing.T) {
@@ -42,7 +43,7 @@ func TestEncodeSignedTxnWithAD(t *testing.T) {
4243
var stxn sdk.SignedTxnWithAD
4344
for _, mt := range testTxns {
4445
t.Run(mt.name, func(t *testing.T) {
45-
msgpack.Decode(mt.msgpack, &stxn)
46+
require.NoError(t, msgpack.Decode(mt.msgpack, &stxn))
4647
js := EncodeSignedTxnWithAD(stxn)
4748
require.Equal(t, mt.json, string(js))
4849
})

idb/postgres/internal/migrations/convert_account_data/m_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"testing"
77

8-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
98
"github.com/stretchr/testify/assert"
109
"github.com/stretchr/testify/require"
1110

@@ -16,6 +15,8 @@ import (
1615
cad "github.com/algorand/indexer/v3/idb/postgres/internal/migrations/convert_account_data"
1716
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
1817
pgutil "github.com/algorand/indexer/v3/idb/postgres/internal/util"
18+
19+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1920
)
2021

2122
func makeAddress(i int) sdk.Address {

0 commit comments

Comments
 (0)