mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-19 21:56:22 +00:00
p2p: support private peer IDs in new p2p stack (#6409)
Pass a set of private peer ids to the `PeerManager` and any node that exists in this set is not returned in the `Advertise` method. closes: #6405
This commit is contained in:
+30
-13
@@ -4,15 +4,32 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSplitAndTrimEmpty(t *testing.T) {
|
||||
testCases := []struct {
|
||||
s string
|
||||
sep string
|
||||
cutset string
|
||||
expected []string
|
||||
}{
|
||||
{"a,b,c", ",", " ", []string{"a", "b", "c"}},
|
||||
{" a , b , c ", ",", " ", []string{"a", "b", "c"}},
|
||||
{" a, b, c ", ",", " ", []string{"a", "b", "c"}},
|
||||
{" a, ", ",", " ", []string{"a"}},
|
||||
{" ", ",", " ", []string{}},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
require.Equal(t, tc.expected, SplitAndTrimEmpty(tc.s, tc.sep, tc.cutset), "%s", tc.s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringInSlice(t *testing.T) {
|
||||
assert.True(t, StringInSlice("a", []string{"a", "b", "c"}))
|
||||
assert.False(t, StringInSlice("d", []string{"a", "b", "c"}))
|
||||
assert.True(t, StringInSlice("", []string{""}))
|
||||
assert.False(t, StringInSlice("", []string{}))
|
||||
require.True(t, StringInSlice("a", []string{"a", "b", "c"}))
|
||||
require.False(t, StringInSlice("d", []string{"a", "b", "c"}))
|
||||
require.True(t, StringInSlice("", []string{""}))
|
||||
require.False(t, StringInSlice("", []string{}))
|
||||
}
|
||||
|
||||
func TestIsASCIIText(t *testing.T) {
|
||||
@@ -20,22 +37,22 @@ func TestIsASCIIText(t *testing.T) {
|
||||
"", "\xC2", "\xC2\xA2", "\xFF", "\x80", "\xF0", "\n", "\t",
|
||||
}
|
||||
for _, v := range notASCIIText {
|
||||
assert.False(t, IsASCIIText(v), "%q is not ascii-text", v)
|
||||
require.False(t, IsASCIIText(v), "%q is not ascii-text", v)
|
||||
}
|
||||
asciiText := []string{
|
||||
" ", ".", "x", "$", "_", "abcdefg;", "-", "0x00", "0", "123",
|
||||
}
|
||||
for _, v := range asciiText {
|
||||
assert.True(t, IsASCIIText(v), "%q is ascii-text", v)
|
||||
require.True(t, IsASCIIText(v), "%q is ascii-text", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestASCIITrim(t *testing.T) {
|
||||
assert.Equal(t, ASCIITrim(" "), "")
|
||||
assert.Equal(t, ASCIITrim(" a"), "a")
|
||||
assert.Equal(t, ASCIITrim("a "), "a")
|
||||
assert.Equal(t, ASCIITrim(" a "), "a")
|
||||
assert.Panics(t, func() { ASCIITrim("\xC2\xA2") })
|
||||
require.Equal(t, ASCIITrim(" "), "")
|
||||
require.Equal(t, ASCIITrim(" a"), "a")
|
||||
require.Equal(t, ASCIITrim("a "), "a")
|
||||
require.Equal(t, ASCIITrim(" a "), "a")
|
||||
require.Panics(t, func() { ASCIITrim("\xC2\xA2") })
|
||||
}
|
||||
|
||||
func TestStringSliceEqual(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user