github.com/prysmaticlabs/prysm@v1.4.4/slasher/rpc/service_test.go (about)

     1  package rpc
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"testing"
     7  
     8  	"github.com/prysmaticlabs/prysm/shared/testutil/assert"
     9  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    10  	logTest "github.com/sirupsen/logrus/hooks/test"
    11  )
    12  
    13  func TestLifecycle_OK(t *testing.T) {
    14  	hook := logTest.NewGlobal()
    15  	rpcService := NewService(context.Background(), &Config{
    16  		Port:     "7348",
    17  		CertFlag: "alice.crt",
    18  		KeyFlag:  "alice.key",
    19  	})
    20  
    21  	rpcService.Start()
    22  
    23  	require.LogsContain(t, hook, "listening on port")
    24  	require.NoError(t, rpcService.Stop())
    25  }
    26  
    27  func TestStatus_CredentialError(t *testing.T) {
    28  	credentialErr := errors.New("credentialError")
    29  	s := &Service{credentialError: credentialErr}
    30  
    31  	assert.ErrorContains(t, s.credentialError.Error(), s.Status())
    32  }
    33  
    34  func TestRPC_InsecureEndpoint(t *testing.T) {
    35  	hook := logTest.NewGlobal()
    36  	rpcService := NewService(context.Background(), &Config{
    37  		Port: "7777",
    38  	})
    39  
    40  	rpcService.Start()
    41  
    42  	require.LogsContain(t, hook, "listening on port")
    43  	require.NoError(t, rpcService.Stop())
    44  }