update table-driven tests: expected errors

This commit is contained in:
Caner Çıdam 2017-12-28 18:06:20 +03:00 committed by Frank Mueller
parent 90123f4f40
commit c0acd033a1
1 changed files with 22 additions and 22 deletions

View File

@ -221,7 +221,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
whisperServiceReturn []interface{} whisperServiceReturn []interface{}
address string address string
password string password string
fail bool expectedError error
}{ }{
{ {
"success", "success",
@ -229,7 +229,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
[]interface{}{s.shh, nil}, []interface{}{s.shh, nil},
s.address, s.address,
s.password, s.password,
false, nil,
}, },
{ {
"fail_keyStore", "fail_keyStore",
@ -237,7 +237,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
[]interface{}{s.shh, nil}, []interface{}{s.shh, nil},
s.address, s.address,
s.password, s.password,
true, testErrKeyStore,
}, },
{ {
"fail_whisperService", "fail_whisperService",
@ -245,7 +245,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
[]interface{}{nil, testErrWhisper}, []interface{}{nil, testErrWhisper},
s.address, s.address,
s.password, s.password,
true, testErrWhisper,
}, },
{ {
"fail_wrongAddress", "fail_wrongAddress",
@ -253,7 +253,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
[]interface{}{s.shh, nil}, []interface{}{s.shh, nil},
"wrong-address", "wrong-address",
s.password, s.password,
true, ErrAddressToAccountMappingFailure,
}, },
{ {
"fail_wrongPassword", "fail_wrongPassword",
@ -261,7 +261,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
[]interface{}{s.shh, nil}, []interface{}{s.shh, nil},
s.address, s.address,
"wrong-password", "wrong-password",
true, errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given passphrase"),
}, },
} }
@ -271,8 +271,8 @@ func (s *ManagerTestSuite) TestSelectAccount() {
s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes() s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
s.nodeManager.EXPECT().WhisperService().Return(testCase.whisperServiceReturn...).AnyTimes() s.nodeManager.EXPECT().WhisperService().Return(testCase.whisperServiceReturn...).AnyTimes()
err := s.accManager.SelectAccount(testCase.address, testCase.password) err := s.accManager.SelectAccount(testCase.address, testCase.password)
if testCase.fail { if testCase.expectedError != nil {
s.Error(err) s.Equal(testCase.expectedError, err)
} else { } else {
s.NoError(err) s.NoError(err)
} }
@ -304,35 +304,35 @@ func (s *ManagerTestSuite) TestCreateChildAccount() {
address string address string
password string password string
accountKeyStoreReturn []interface{} accountKeyStoreReturn []interface{}
fail bool expectedError error
}{ }{
{ {
"success", "success",
s.address, s.address,
s.password, s.password,
[]interface{}{s.keyStore, nil}, []interface{}{s.keyStore, nil},
false, nil,
}, },
{ {
"fail_keyStore", "fail_keyStore",
s.address, s.address,
s.password, s.password,
[]interface{}{nil, testErrKeyStore}, []interface{}{nil, testErrKeyStore},
true, testErrKeyStore,
}, },
{ {
"fail_wrongAddress", "fail_wrongAddress",
"wrong-address", "wrong-address",
s.password, s.password,
[]interface{}{s.keyStore, nil}, []interface{}{s.keyStore, nil},
true, ErrAddressToAccountMappingFailure,
}, },
{ {
"fail_wrongPassword", "fail_wrongPassword",
s.address, s.address,
"wrong-password", "wrong-password",
[]interface{}{s.keyStore, nil}, []interface{}{s.keyStore, nil},
true, errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given passphrase"),
}, },
} }
@ -341,8 +341,8 @@ func (s *ManagerTestSuite) TestCreateChildAccount() {
s.reinitMock() s.reinitMock()
s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes() s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
childAddr, childPubKey, err := s.accManager.CreateChildAccount(testCase.address, testCase.password) childAddr, childPubKey, err := s.accManager.CreateChildAccount(testCase.address, testCase.password)
if testCase.fail { if testCase.expectedError != nil {
s.Error(err) s.Equal(testCase.expectedError, err)
} else { } else {
s.NoError(err) s.NoError(err)
s.NotEmpty(childAddr) s.NotEmpty(childAddr)
@ -441,35 +441,35 @@ func (s *ManagerTestSuite) TestAddressToDecryptedAccount() {
accountKeyStoreReturn []interface{} accountKeyStoreReturn []interface{}
address string address string
password string password string
fail bool expectedError error
}{ }{
{ {
"success", "success",
[]interface{}{s.keyStore, nil}, []interface{}{s.keyStore, nil},
s.address, s.address,
s.password, s.password,
false, nil,
}, },
{ {
"fail_keyStore", "fail_keyStore",
[]interface{}{nil, testErrKeyStore}, []interface{}{nil, testErrKeyStore},
s.address, s.address,
s.password, s.password,
true, testErrKeyStore,
}, },
{ {
"fail_wrongAddress", "fail_wrongAddress",
[]interface{}{s.keyStore, nil}, []interface{}{s.keyStore, nil},
"wrong-address", "wrong-address",
s.password, s.password,
true, ErrAddressToAccountMappingFailure,
}, },
{ {
"fail_wrongPassword", "fail_wrongPassword",
[]interface{}{s.keyStore, nil}, []interface{}{s.keyStore, nil},
s.address, s.address,
"wrong-password", "wrong-password",
true, errors.New("could not decrypt key with given passphrase"),
}, },
} }
@ -478,8 +478,8 @@ func (s *ManagerTestSuite) TestAddressToDecryptedAccount() {
s.reinitMock() s.reinitMock()
s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes() s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
acc, key, err := s.accManager.AddressToDecryptedAccount(testCase.address, testCase.password) acc, key, err := s.accManager.AddressToDecryptedAccount(testCase.address, testCase.password)
if testCase.fail { if testCase.expectedError != nil {
s.Error(err) s.Equal(testCase.expectedError, err)
} else { } else {
s.NoError(err) s.NoError(err)
s.NotNil(acc) s.NotNil(acc)