From d1428e164ee4e184345d4b4daba0e74b5805d505 Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Mon, 25 Jan 2016 11:17:12 -0800 Subject: [PATCH] Add basic test --- cmd/config.go | 4 ++-- cmd/config_test.go | 25 +++++++++++++++++++++++++ cmd/test_secret | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 cmd/config_test.go create mode 100644 cmd/test_secret diff --git a/cmd/config.go b/cmd/config.go index de7c67c7a..f425a883a 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -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 } diff --git a/cmd/config_test.go b/cmd/config_test.go new file mode 100644 index 000000000..5b52d1c6f --- /dev/null +++ b/cmd/config_test.go @@ -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) + } +} diff --git a/cmd/test_secret b/cmd/test_secret new file mode 100644 index 000000000..d97c5eada --- /dev/null +++ b/cmd/test_secret @@ -0,0 +1 @@ +secret