Skip to content

Commit

Permalink
Ban require.EqualValues (ava-labs#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored May 3, 2023
1 parent a583991 commit c125bc1
Show file tree
Hide file tree
Showing 37 changed files with 298 additions and 294 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ linters-settings:
forbid:
- 'require\.Error$(# ErrorIs should be used instead)?'
- 'require\.ErrorContains$(# ErrorIs should be used instead)?'
- 'require\.EqualValues$(# Equal should be used instead)?'
exclude_godoc_examples: false
# https://golangci-lint.run/usage/linters#gosec
gosec:
Expand Down
5 changes: 3 additions & 2 deletions api/admin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,10 @@ func TestGetLoggerLevel(t *testing.T) {
tt.loggerName,
)
require.ErrorIs(err, tt.clientErr)
if tt.clientErr == nil {
require.EqualValues(tt.serviceResponse, res)
if tt.clientErr != nil {
return
}
require.Equal(tt.serviceResponse, res)
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions indexer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestIndexClient(t *testing.T) {
}
index, err := client.GetIndex(context.Background(), ids.Empty)
require.NoError(err)
require.EqualValues(5, index)
require.Equal(uint64(5), index)
}
{
// Test GetLastAccepted
Expand All @@ -64,9 +64,9 @@ func TestIndexClient(t *testing.T) {
}
container, index, err := client.GetLastAccepted(context.Background())
require.NoError(err)
require.EqualValues(id, container.ID)
require.EqualValues(bytes, container.Bytes)
require.EqualValues(index, 10)
require.Equal(id, container.ID)
require.Equal(bytes, container.Bytes)
require.Equal(uint64(10), index)
}
{
// Test GetContainerRange
Expand All @@ -88,8 +88,8 @@ func TestIndexClient(t *testing.T) {
containers, err := client.GetContainerRange(context.Background(), 1, 10)
require.NoError(err)
require.Len(containers, 1)
require.EqualValues(id, containers[0].ID)
require.EqualValues(bytes, containers[0].Bytes)
require.Equal(id, containers[0].ID)
require.Equal(bytes, containers[0].Bytes)
}
{
// Test IsAccepted
Expand Down Expand Up @@ -125,8 +125,8 @@ func TestIndexClient(t *testing.T) {
}
container, index, err := client.GetContainerByID(context.Background(), id)
require.NoError(err)
require.EqualValues(id, container.ID)
require.EqualValues(bytes, container.Bytes)
require.EqualValues(index, 10)
require.Equal(id, container.ID)
require.Equal(bytes, container.Bytes)
require.Equal(uint64(10), index)
}
}
14 changes: 7 additions & 7 deletions indexer/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ func TestIndex(t *testing.T) {

lastAcceptedIndex, ok := idx.lastAcceptedIndex()
require.True(ok)
require.EqualValues(i, lastAcceptedIndex)
require.EqualValues(i+1, idx.nextAcceptedIndex)
require.Equal(i, lastAcceptedIndex)
require.Equal(i+1, idx.nextAcceptedIndex)

gotContainer, err := idx.GetContainerByID(containerID)
require.NoError(err)
require.Equal(containerBytes, gotContainer.Bytes)

gotIndex, err := idx.GetIndex(containerID)
require.NoError(err)
require.EqualValues(i, gotIndex)
require.Equal(i, gotIndex)

gotContainer, err = idx.GetContainerByIndex(i)
require.NoError(err)
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestIndex(t *testing.T) {
for _, container := range containersList {
require.False(sawContainers.Contains(container.ID)) // Should only see this container once
require.Contains(containers, container.ID)
require.EqualValues(containers[container.ID], container.Bytes)
require.Equal(containers[container.ID], container.Bytes)
// Timestamps should be non-decreasing
require.True(container.Timestamp >= lastTimestamp)
lastTimestamp = container.Timestamp
Expand Down Expand Up @@ -150,8 +150,8 @@ func TestIndexGetContainerByRangeMaxPageSize(t *testing.T) {
containers, err = idx.GetContainerRange(MaxFetchedByRange-1, MaxFetchedByRange)
require.NoError(err)
require.Len(containers, 2)
require.EqualValues(containers[1], containers2[MaxFetchedByRange-1])
require.EqualValues(containers[0], containers2[MaxFetchedByRange-2])
require.Equal(containers[1], containers2[MaxFetchedByRange-1])
require.Equal(containers[0], containers2[MaxFetchedByRange-2])
}

func TestDontIndexSameContainerTwice(t *testing.T) {
Expand All @@ -173,5 +173,5 @@ func TestDontIndexSameContainerTwice(t *testing.T) {
require.ErrorIs(err, errNoContainerAtIndex)
gotContainer, err := idx.GetContainerByID(containerID)
require.NoError(err)
require.EqualValues(gotContainer.Bytes, []byte{1, 2, 3}, "should not have accepted same container twice")
require.Equal([]byte{1, 2, 3}, gotContainer.Bytes)
}
28 changes: 14 additions & 14 deletions indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ func TestIndexer(t *testing.T) {
previouslyIndexed, err = idxr.previouslyIndexed(chain1Ctx.ChainID)
require.NoError(err)
require.True(previouslyIndexed)
require.EqualValues(1, server.timesCalled)
require.EqualValues("index/chain1", server.bases[0])
require.EqualValues("/block", server.endpoints[0])
require.Equal(1, server.timesCalled)
require.Equal("index/chain1", server.bases[0])
require.Equal("/block", server.endpoints[0])
require.Len(idxr.blockIndices, 1)
require.Len(idxr.txIndices, 0)
require.Len(idxr.vtxIndices, 0)
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestIndexer(t *testing.T) {
// Verify GetIndex is right
index, err := blkIdx.GetIndex(blkID)
require.NoError(err)
require.EqualValues(0, index)
require.Zero(index)

// Verify GetContainerByIndex is right
container, err = blkIdx.GetContainerByIndex(0)
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestIndexer(t *testing.T) {
container, err = blkIdx.GetLastAccepted()
require.NoError(err)
require.Equal(blkID, container.ID)
require.EqualValues(1, server.timesCalled) // block index for chain
require.Equal(1, server.timesCalled) // block index for chain
require.Contains(server.endpoints, "/block")

// Register a DAG chain
Expand All @@ -272,7 +272,7 @@ func TestIndexer(t *testing.T) {
dagVM := vertex.NewMockLinearizableVM(ctrl)
idxr.RegisterChain("chain2", chain2Ctx, dagVM)
require.NoError(err)
require.EqualValues(4, server.timesCalled) // block index for chain, block index for dag, vtx index, tx index
require.Equal(4, server.timesCalled) // block index for chain, block index for dag, vtx index, tx index
require.Contains(server.bases, "index/chain2")
require.Contains(server.endpoints, "/block")
require.Contains(server.endpoints, "/vtx")
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestIndexer(t *testing.T) {
// Verify GetIndex is right
index, err = vtxIdx.GetIndex(vtxID)
require.NoError(err)
require.EqualValues(0, index)
require.Zero(index)

// Verify GetContainerByIndex is right
vtx, err = vtxIdx.GetContainerByIndex(0)
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestIndexer(t *testing.T) {
// Verify GetIndex is right
index, err = txIdx.GetIndex(txID)
require.NoError(err)
require.EqualValues(0, index)
require.Zero(index)

// Verify GetContainerByIndex is right
tx, err = txIdx.GetContainerByIndex(0)
Expand All @@ -373,13 +373,13 @@ func TestIndexer(t *testing.T) {
// happen on the block/tx index. Similar for tx.
lastAcceptedTx, err := txIdx.GetLastAccepted()
require.NoError(err)
require.EqualValues(txID, lastAcceptedTx.ID)
require.Equal(txID, lastAcceptedTx.ID)
lastAcceptedVtx, err := vtxIdx.GetLastAccepted()
require.NoError(err)
require.EqualValues(vtxID, lastAcceptedVtx.ID)
require.Equal(vtxID, lastAcceptedVtx.ID)
lastAcceptedBlk, err := blkIdx.GetLastAccepted()
require.NoError(err)
require.EqualValues(blkID, lastAcceptedBlk.ID)
require.Equal(blkID, lastAcceptedBlk.ID)

// Close the indexer again
require.NoError(config.DB.(*versiondb.Database).Commit())
Expand All @@ -397,13 +397,13 @@ func TestIndexer(t *testing.T) {
// Verify state
lastAcceptedTx, err = idxr.txIndices[chain2Ctx.ChainID].GetLastAccepted()
require.NoError(err)
require.EqualValues(txID, lastAcceptedTx.ID)
require.Equal(txID, lastAcceptedTx.ID)
lastAcceptedVtx, err = idxr.vtxIndices[chain2Ctx.ChainID].GetLastAccepted()
require.NoError(err)
require.EqualValues(vtxID, lastAcceptedVtx.ID)
require.Equal(vtxID, lastAcceptedVtx.ID)
lastAcceptedBlk, err = idxr.blockIndices[chain1Ctx.ChainID].GetLastAccepted()
require.NoError(err)
require.EqualValues(blkID, lastAcceptedBlk.ID)
require.Equal(blkID, lastAcceptedBlk.ID)
}

// Make sure the indexer doesn't allow incomplete indices unless explicitly allowed
Expand Down
2 changes: 1 addition & 1 deletion network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func TestSend(t *testing.T) {
toSend := set.Set[ids.NodeID]{}
toSend.Add(nodeIDs[1])
sentTo := net0.Send(outboundGetMsg, toSend, constants.PrimaryNetworkID, subnets.NoOpAllower)
require.EqualValues(toSend, sentTo)
require.Equal(toSend, sentTo)

inboundGetMsg := <-received
require.Equal(message.GetOp, inboundGetMsg.Op())
Expand Down
14 changes: 7 additions & 7 deletions network/peer/ip_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ func TestIPSigner(t *testing.T) {

signedIP1, err := s.GetSignedIP()
require.NoError(err)
require.EqualValues(dynIP.IPPort(), signedIP1.IPPort)
require.EqualValues(10, signedIP1.Timestamp)
require.Equal(dynIP.IPPort(), signedIP1.IPPort)
require.Equal(uint64(10), signedIP1.Timestamp)

s.clock.Set(time.Unix(11, 0))

signedIP2, err := s.GetSignedIP()
require.NoError(err)
require.EqualValues(dynIP.IPPort(), signedIP2.IPPort)
require.EqualValues(10, signedIP2.Timestamp)
require.EqualValues(signedIP1.Signature, signedIP2.Signature)
require.Equal(dynIP.IPPort(), signedIP2.IPPort)
require.Equal(uint64(10), signedIP2.Timestamp)
require.Equal(signedIP1.Signature, signedIP2.Signature)

dynIP.SetIP(net.IPv4(1, 2, 3, 4))

signedIP3, err := s.GetSignedIP()
require.NoError(err)
require.EqualValues(dynIP.IPPort(), signedIP3.IPPort)
require.EqualValues(11, signedIP3.Timestamp)
require.Equal(dynIP.IPPort(), signedIP3.IPPort)
require.Equal(uint64(11), signedIP3.Timestamp)
require.NotEqualValues(signedIP2.Signature, signedIP3.Signature)
}
4 changes: 2 additions & 2 deletions network/throttling/bandwidth_throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestBandwidthThrottler(t *testing.T) {
require.True(ok)
require.NotNil(throttler.log)
require.NotNil(throttler.limiters)
require.EqualValues(throttler.RefillRate, 8)
require.EqualValues(throttler.MaxBurstSize, 10)
require.Equal(config.RefillRate, throttler.RefillRate)
require.Equal(config.MaxBurstSize, throttler.MaxBurstSize)
require.Len(throttler.limiters, 0)

// Add a node
Expand Down
10 changes: 5 additions & 5 deletions network/throttling/inbound_msg_buffer_throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func TestMsgBufferThrottler(t *testing.T) {
throttler.Acquire(context.Background(), nodeID1)
throttler.Acquire(context.Background(), nodeID1)
require.Len(throttler.nodeToNumProcessingMsgs, 1)
require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID1])
require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID1])

// Acquire shouldn't block for other node
throttler.Acquire(context.Background(), nodeID2)
throttler.Acquire(context.Background(), nodeID2)
throttler.Acquire(context.Background(), nodeID2)
require.Len(throttler.nodeToNumProcessingMsgs, 2)
require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID1])
require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID2])
require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID1])
require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID2])

// Acquire should block for 4th acquire
done := make(chan struct{})
Expand All @@ -53,7 +53,7 @@ func TestMsgBufferThrottler(t *testing.T) {
// fourth acquire should be unblocked
<-done
require.Len(throttler.nodeToNumProcessingMsgs, 2)
require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID2])
require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID2])

// Releasing from other node should have no effect
throttler.release(nodeID2)
Expand All @@ -80,7 +80,7 @@ func TestMsgBufferThrottlerContextCancelled(t *testing.T) {
throttler.Acquire(vdr1Context, nodeID1)
throttler.Acquire(vdr1Context, nodeID1)
require.Len(throttler.nodeToNumProcessingMsgs, 1)
require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID1])
require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID1])

// Acquire should block for 4th acquire
done := make(chan struct{})
Expand Down
Loading

0 comments on commit c125bc1

Please sign in to comment.