2018-08-01 22:08:44 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLifecycle(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
2018-08-08 22:43:25 +00:00
|
|
|
rpcService := NewRPCService(context.Background(), &Config{Port: "9999", CertFlag: "alice.crt", KeyFlag: "alice.key"})
|
2018-08-01 22:08:44 +00:00
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprintf("RPC server listening on port :%s", rpcService.port))
|
|
|
|
|
|
|
|
rpcService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBadEndpoint(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
rpcService := NewRPCService(context.Background(), &Config{Port: "ralph merkle!!!"})
|
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprintf("Could not listen to port :%s", rpcService.port))
|
|
|
|
|
|
|
|
rpcService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|