Encapsulating and fixing unit tests

This commit is contained in:
Juan Leni
2019-04-03 14:15:50 +02:00
parent 07501137c4
commit d9b3001d13
15 changed files with 122 additions and 103 deletions
@@ -313,7 +313,7 @@ func (th *TestHarness) Shutdown(err error) {
}
// newTestHarnessSignerRemote creates our client instance which we will use for testing.
func newTestHarnessSignerRemote(logger log.Logger, cfg TestHarnessConfig) (*privval.SignerValidatorEndpoint, error) {
func newTestHarnessSignerRemote(logger log.Logger, cfg TestHarnessConfig) (*privval.SignerListenerEndpoint, error) {
proto, addr := cmn.ProtocolAndAddress(cfg.BindAddr)
if proto == "unix" {
// make sure the socket doesn't exist - if so, try to delete it
@@ -346,7 +346,7 @@ func newTestHarnessSignerRemote(logger log.Logger, cfg TestHarnessConfig) (*priv
logger.Error("Unsupported protocol (must be unix:// or tcp://)", "proto", proto)
return nil, newTestHarnessError(ErrInvalidParameters, nil, fmt.Sprintf("Unsupported protocol: %s", proto))
}
return privval.NewSignerValidatorEndpoint(logger, svln), nil
return privval.NewSignerListenerEndpoint(logger, svln), nil
}
func newTestHarnessError(code int, err error, info string) *TestHarnessError {
@@ -85,7 +85,7 @@ func TestRemoteSignerTestHarnessMaxAcceptRetriesReached(t *testing.T) {
func TestRemoteSignerTestHarnessSuccessfulRun(t *testing.T) {
harnessTest(
t,
func(th *TestHarness) *privval.SignerServiceEndpoint {
func(th *TestHarness) *privval.SignerDialerEndpoint {
return newMockRemoteSigner(t, th, th.fpv.Key.PrivKey, false, false)
},
NoError,
@@ -95,7 +95,7 @@ func TestRemoteSignerTestHarnessSuccessfulRun(t *testing.T) {
func TestRemoteSignerPublicKeyCheckFailed(t *testing.T) {
harnessTest(
t,
func(th *TestHarness) *privval.SignerServiceEndpoint {
func(th *TestHarness) *privval.SignerDialerEndpoint {
return newMockRemoteSigner(t, th, ed25519.GenPrivKey(), false, false)
},
ErrTestPublicKeyFailed,
@@ -105,7 +105,7 @@ func TestRemoteSignerPublicKeyCheckFailed(t *testing.T) {
func TestRemoteSignerProposalSigningFailed(t *testing.T) {
harnessTest(
t,
func(th *TestHarness) *privval.SignerServiceEndpoint {
func(th *TestHarness) *privval.SignerDialerEndpoint {
return newMockRemoteSigner(t, th, th.fpv.Key.PrivKey, true, false)
},
ErrTestSignProposalFailed,
@@ -115,15 +115,15 @@ func TestRemoteSignerProposalSigningFailed(t *testing.T) {
func TestRemoteSignerVoteSigningFailed(t *testing.T) {
harnessTest(
t,
func(th *TestHarness) *privval.SignerServiceEndpoint {
func(th *TestHarness) *privval.SignerDialerEndpoint {
return newMockRemoteSigner(t, th, th.fpv.Key.PrivKey, false, true)
},
ErrTestSignVoteFailed,
)
}
func newMockRemoteSigner(t *testing.T, th *TestHarness, privKey crypto.PrivKey, breakProposalSigning bool, breakVoteSigning bool) *privval.SignerServiceEndpoint {
return privval.NewSignerServiceEndpoint(
func newMockRemoteSigner(t *testing.T, th *TestHarness, privKey crypto.PrivKey, breakProposalSigning bool, breakVoteSigning bool) *privval.SignerDialerEndpoint {
return privval.NewSignerDialerEndpoint(
th.logger,
th.chainID,
types.NewMockPVWithParams(privKey, breakProposalSigning, breakVoteSigning),
@@ -136,7 +136,7 @@ func newMockRemoteSigner(t *testing.T, th *TestHarness, privKey crypto.PrivKey,
}
// For running relatively standard tests.
func harnessTest(t *testing.T, rsMaker func(th *TestHarness) *privval.SignerServiceEndpoint, expectedExitCode int) {
func harnessTest(t *testing.T, rsMaker func(th *TestHarness) *privval.SignerDialerEndpoint, expectedExitCode int) {
cfg := makeConfig(t, 100, 3)
defer cleanup(cfg)