Add basic test

This commit is contained in:
Roland Shoemaker 2016-01-25 11:17:12 -08:00
parent f02864fb7e
commit d1428e164e
3 changed files with 28 additions and 2 deletions

View File

@ -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
}

25
cmd/config_test.go Normal file
View File

@ -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)
}
}

1
cmd/test_secret Normal file
View File

@ -0,0 +1 @@
secret