-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* topic manager - renamed to topic manager - extracted from pubsub.go - added tests * msg router test * test cfg defaults + fix pointer reciever * makefile: fix test-cov * test read config * fix gen priv key + test
- Loading branch information
Showing
12 changed files
with
333 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package commons | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDefaults(t *testing.T) { | ||
t.Run("Config", func(t *testing.T) { | ||
cfg := &Config{} | ||
cfg.Defaults() | ||
require.Equal(t, 15*time.Second, cfg.DialTimeout) | ||
require.Equal(t, 1024, cfg.MsgRouterQueueSize) | ||
require.Equal(t, 10, cfg.MsgRouterWorkers) | ||
require.Empty(t, cfg.ListenAddrs) | ||
require.Empty(t, cfg.PSK) | ||
}) | ||
|
||
t.Run("ConnManagerConfig", func(t *testing.T) { | ||
cfg := &ConnManagerConfig{} | ||
cfg.Defaults() | ||
require.Equal(t, 5, cfg.LowWaterMark) | ||
require.Equal(t, 25, cfg.HighWaterMark) | ||
require.Equal(t, time.Minute, cfg.GracePeriod) | ||
}) | ||
|
||
t.Run("DiscoveryConfig", func(t *testing.T) { | ||
cfg := &DiscoveryConfig{} | ||
cfg.Defaults() | ||
require.Equal(t, ModeServer, cfg.Mode) | ||
require.Equal(t, "p2pmq", cfg.ProtocolPrefix) | ||
}) | ||
|
||
t.Run("MsgValidationConfig", func(t *testing.T) { | ||
cfg := &MsgValidationConfig{} | ||
cfg.Defaults(nil) | ||
require.Equal(t, time.Second*5, cfg.Timeout) | ||
require.Equal(t, 10, cfg.Concurrency) | ||
|
||
cfg.Concurrency = 4 | ||
cfg2 := &MsgValidationConfig{} | ||
cfg2.Defaults(cfg) | ||
require.Equal(t, time.Second*5, cfg2.Timeout) | ||
require.Equal(t, 4, cfg2.Concurrency) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package commons | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReadConfig(t *testing.T) { | ||
t.Run("happy path yaml", func(t *testing.T) { | ||
cfgPath := "resources/config/default.p2pmq.yaml" | ||
cfg, err := ReadConfig(path.Join("..", cfgPath)) | ||
require.NoError(t, err) | ||
require.Len(t, cfg.ListenAddrs, 1) | ||
require.Equal(t, "/ip4/0.0.0.0/tcp/5101", cfg.ListenAddrs[0]) | ||
}) | ||
|
||
t.Run("non existing json file", func(t *testing.T) { | ||
cfgPath := "resources/config/non-existing.p2pmq.json" | ||
_, err := ReadConfig(path.Join("..", cfgPath)) | ||
require.Error(t, err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package commons | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetOrGeneratePrivateKey(t *testing.T) { | ||
sk, skb64, err := GetOrGeneratePrivateKey("") | ||
require.NoError(t, err) | ||
require.NotNil(t, sk) | ||
require.NotEmpty(t, skb64) | ||
|
||
sk2, sk2b64, err := GetOrGeneratePrivateKey(skb64) | ||
require.NoError(t, err) | ||
require.NotNil(t, sk2) | ||
require.Equal(t, skb64, sk2b64) | ||
require.True(t, sk.Equals(sk2)) | ||
|
||
t.Run("bad input", func(t *testing.T) { | ||
sk, _, err := GetOrGeneratePrivateKey("bad input") | ||
require.Error(t, err) | ||
require.Nil(t, sk) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.