mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-13 22:28:36 -07:00
*: add subtests for all table driven tests
Because we use testify, this is less useful than normal, but this is still best practice for table-driven tests.
This commit is contained in:
@@ -43,11 +43,13 @@ func TestClientID(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range clientTable {
|
||||
var clientID ClientID
|
||||
copy(clientID[:], []byte(tt.clientID))
|
||||
parsedID := NewClientID(PeerIDFromString(tt.peerID))
|
||||
if parsedID != clientID {
|
||||
t.Error("Incorrectly parsed peer ID", tt.peerID, "as", parsedID)
|
||||
}
|
||||
t.Run(tt.peerID, func(t *testing.T) {
|
||||
var clientID ClientID
|
||||
copy(clientID[:], []byte(tt.clientID))
|
||||
parsedID := NewClientID(PeerIDFromString(tt.peerID))
|
||||
if parsedID != clientID {
|
||||
t.Error("Incorrectly parsed peer ID", tt.peerID, "as", parsedID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bittorrent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -22,8 +23,10 @@ func TestNew(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range table {
|
||||
got, err := NewEvent(tt.data)
|
||||
require.Equal(t, err, tt.expectedErr, "errors should equal the expected value")
|
||||
require.Equal(t, got, tt.expected, "events should equal the expected value")
|
||||
t.Run(fmt.Sprintf("%#v expecting %s", tt.data, tt.expectedErr), func(t *testing.T) {
|
||||
got, err := NewEvent(tt.data)
|
||||
require.Equal(t, err, tt.expectedErr, "errors should equal the expected value")
|
||||
require.Equal(t, got, tt.expected, "events should equal the expected value")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user