Add basic test
This commit is contained in:
parent
f02864fb7e
commit
d1428e164e
|
@ -230,9 +230,9 @@ func (pc *PasswordConfig) Pass() (string, error) {
|
|||
if pc.PasswordFile != "" {
|
||||
contents, err := ioutil.ReadFile(pc.PasswordFile)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
return "", err
|
||||
}
|
||||
return string(contents), nil
|
||||
return strings.TrimRight(string(contents), "\n"), nil
|
||||
}
|
||||
return pc.Password, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/letsencrypt/boulder/test"
|
||||
)
|
||||
|
||||
func TestPasswordConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
pc PasswordConfig
|
||||
expected string
|
||||
}{
|
||||
{pc: PasswordConfig{}, expected: ""},
|
||||
{pc: PasswordConfig{Password: "config"}, expected: "config"},
|
||||
{pc: PasswordConfig{Password: "config", PasswordFile: "test_secret"}, expected: "secret"},
|
||||
{pc: PasswordConfig{PasswordFile: "test_secret"}, expected: "secret"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
password, err := tc.pc.Pass()
|
||||
test.AssertNotError(t, err, "Failed to retrieve password")
|
||||
test.AssertEquals(t, password, tc.expected)
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
secret
|
Loading…
Reference in New Issue