mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 15:31:20 +00:00
17169e5a2d
* slasher grpc client * do not export * slasher on a different package * fix featureconfig * change to rough time * revert roughtime * remove extra comma * revert order change * goimports * fix comments and tests * fix package name * revert reorder * comment for start * service * fix visibility * external slasher validator protection implementation * gaz * fix comment * add comments * nishant feedback * raul feedback * preston feedback * fix flags * fix imports * fix imports * port 4002 * added tests * fix log * fix imports * fix imports name * raul feedback * gaz * terence comment * change name * runtime fixes * add flag check Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func TestEnterPassword(t *testing.T) {
|
|
type rets struct {
|
|
pw string
|
|
err error
|
|
}
|
|
var tt = []struct {
|
|
name string
|
|
rets []rets
|
|
expectedErr error
|
|
expectedPw string
|
|
}{
|
|
{
|
|
"first_match",
|
|
[]rets{{"abcd", nil}, {"abcd", nil}},
|
|
nil,
|
|
"abcd",
|
|
},
|
|
{
|
|
"first_match_with_newline",
|
|
[]rets{{"abcd\n", nil}, {"abcd", nil}},
|
|
nil,
|
|
"abcd",
|
|
},
|
|
{
|
|
"first_match_with_newline_confirm",
|
|
[]rets{{"abcd", nil}, {"abcd\n", nil}},
|
|
nil,
|
|
"abcd",
|
|
},
|
|
{
|
|
"first_match_both_newline",
|
|
[]rets{{"abcd\n", nil}, {"abcd\n", nil}},
|
|
nil,
|
|
"abcd",
|
|
},
|
|
{
|
|
"second_match",
|
|
[]rets{{"abcd", nil}, {"aba", nil}, {"abcd", nil}, {"abcd", nil}},
|
|
nil,
|
|
"abcd",
|
|
},
|
|
{
|
|
"cant_read",
|
|
[]rets{{"pw", errors.New("i/o fail")}},
|
|
errors.New("i/o fail"),
|
|
"",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
m := NewMockPasswordReader(ctrl)
|
|
for _, ret := range tc.rets {
|
|
m.EXPECT().ReadPassword().Return(ret.pw, ret.err)
|
|
}
|
|
pw, err := EnterPassword(true, m)
|
|
if pw != tc.expectedPw {
|
|
t.Errorf("got %v, wanted %v", pw, tc.expectedPw)
|
|
}
|
|
if err == nil && tc.expectedErr != nil {
|
|
t.Errorf("got nil err, expected %v err", tc.expectedErr.Error())
|
|
}
|
|
if err != nil && tc.expectedErr != nil && errors.Cause(err).Error() != tc.expectedErr.Error() {
|
|
t.Errorf("got %v, wanted %v", errors.Cause(err), tc.expectedErr.Error())
|
|
}
|
|
})
|
|
}
|
|
}
|