-
Notifications
You must be signed in to change notification settings - Fork 31
/
main_test.go
40 lines (34 loc) · 848 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"errors"
"testing"
)
func TestAskPass(t *testing.T) {
someError := errors.New("some error")
tests := []struct {
passFromFunc []byte
errFromFunc error
passwordOut string
errOut error
}{
{nil, nil, "", nil},
{[]byte(""), nil, "", nil},
{[]byte("password1"), nil, "password1", nil},
{[]byte("password2"), nil, "password2", nil},
{nil, someError, "", someError},
}
for _, test := range tests {
// update global wrapper
getPasswdFunc = func() ([]byte, error) {
return test.passFromFunc, test.errFromFunc
}
password, err := askPass()
if password != test.passwordOut || err != test.errOut {
t.Errorf("askPass() failed. input: %v, %v. output: %v, %v. expected: %v, %v",
test.passFromFunc, test.errFromFunc,
password, err,
test.passwordOut, test.errOut,
)
}
}
}