prysm-pulse/validator/client/service_test.go
Raul Jordan 04615cb97b
Add Validator RPC Endpoint to Retrieve Beacon + Validator Logs Websocket Endpoints (#7981)
* add logs endpoint

* commands to retrieve logs endpoints

* ensure works at runtime

* add auth
2020-11-27 18:28:45 +00:00

71 lines
1.9 KiB
Go

package client
import (
"context"
"testing"
"time"
"github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
logTest "github.com/sirupsen/logrus/hooks/test"
)
var _ shared.Service = (*ValidatorService)(nil)
var _ BeaconNodeInfoFetcher = (*ValidatorService)(nil)
var _ GenesisFetcher = (*ValidatorService)(nil)
var _ SyncChecker = (*ValidatorService)(nil)
func TestStop_CancelsContext(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
vs := &ValidatorService{
ctx: ctx,
cancel: cancel,
}
assert.NoError(t, vs.Stop())
select {
case <-time.After(1 * time.Second):
t.Error("Context not canceled within 1s")
case <-vs.ctx.Done():
}
}
func TestLifecycle(t *testing.T) {
hook := logTest.NewGlobal()
// Use canceled context so that the run function exits immediately..
ctx, cancel := context.WithCancel(context.Background())
cancel()
validatorService := &ValidatorService{
ctx: ctx,
cancel: cancel,
endpoint: "merkle tries",
withCert: "alice.crt",
}
validatorService.Start()
require.NoError(t, validatorService.Stop(), "Could not stop service")
require.LogsContain(t, hook, "Stopping service")
}
func TestLifecycle_Insecure(t *testing.T) {
hook := logTest.NewGlobal()
// Use canceled context so that the run function exits immediately.
ctx, cancel := context.WithCancel(context.Background())
cancel()
validatorService := &ValidatorService{
ctx: ctx,
cancel: cancel,
endpoint: "merkle tries",
}
validatorService.Start()
require.LogsContain(t, hook, "You are using an insecure gRPC connection")
require.NoError(t, validatorService.Stop(), "Could not stop service")
require.LogsContain(t, hook, "Stopping service")
}
func TestStatus_NoConnectionError(t *testing.T) {
validatorService := &ValidatorService{}
assert.ErrorContains(t, "no connection", validatorService.Status())
}