2020-03-24 18:30:21 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2020-08-18 12:41:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
2020-08-13 16:22:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-03-24 18:30:21 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLifecycle_OK(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
rpcService := NewService(context.Background(), &Config{
|
|
|
|
Port: "7348",
|
|
|
|
CertFlag: "alice.crt",
|
|
|
|
KeyFlag: "alice.key",
|
|
|
|
})
|
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
2020-08-13 16:22:25 +00:00
|
|
|
require.LogsContain(t, hook, "listening on port")
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, rpcService.Stop())
|
2020-03-24 18:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatus_CredentialError(t *testing.T) {
|
|
|
|
credentialErr := errors.New("credentialError")
|
|
|
|
s := &Service{credentialError: credentialErr}
|
|
|
|
|
2020-08-18 12:41:25 +00:00
|
|
|
assert.ErrorContains(t, s.credentialError.Error(), s.Status())
|
2020-03-24 18:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRPC_InsecureEndpoint(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
rpcService := NewService(context.Background(), &Config{
|
|
|
|
Port: "7777",
|
|
|
|
})
|
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
2020-10-12 16:12:00 +00:00
|
|
|
require.LogsContain(t, hook, "listening on port")
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, rpcService.Stop())
|
2020-03-24 18:30:21 +00:00
|
|
|
}
|