From b66b54701e21f7c48258a7798df936209f3cabcb Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 26 Nov 2016 17:49:34 -0500 Subject: [PATCH] Adds unit test for LoadCert --- cmd.cover.out | 14 +++++++------- cmd/shell_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/cmd.cover.out b/cmd.cover.out index cc1ad9659..f50844247 100644 --- a/cmd.cover.out +++ b/cmd.cover.out @@ -49,13 +49,13 @@ github.com/letsencrypt/boulder/cmd/shell.go:147.4,147.46 1 0 github.com/letsencrypt/boulder/cmd/shell.go:150.4,153.46 4 0 github.com/letsencrypt/boulder/cmd/shell.go:144.31,146.5 1 0 github.com/letsencrypt/boulder/cmd/shell.go:147.46,149.5 1 0 -github.com/letsencrypt/boulder/cmd/shell.go:168.53,169.16 1 0 -github.com/letsencrypt/boulder/cmd/shell.go:173.2,174.16 2 0 -github.com/letsencrypt/boulder/cmd/shell.go:178.2,179.49 2 0 -github.com/letsencrypt/boulder/cmd/shell.go:184.2,185.8 2 0 -github.com/letsencrypt/boulder/cmd/shell.go:169.16,172.3 2 0 -github.com/letsencrypt/boulder/cmd/shell.go:174.16,176.3 1 0 -github.com/letsencrypt/boulder/cmd/shell.go:179.49,182.3 2 0 +github.com/letsencrypt/boulder/cmd/shell.go:168.53,169.16 1 4 +github.com/letsencrypt/boulder/cmd/shell.go:173.2,174.16 2 3 +github.com/letsencrypt/boulder/cmd/shell.go:178.2,179.49 2 2 +github.com/letsencrypt/boulder/cmd/shell.go:184.2,185.8 2 1 +github.com/letsencrypt/boulder/cmd/shell.go:169.16,172.3 2 1 +github.com/letsencrypt/boulder/cmd/shell.go:174.16,176.3 1 1 +github.com/letsencrypt/boulder/cmd/shell.go:179.49,182.3 2 1 github.com/letsencrypt/boulder/cmd/shell.go:193.31,196.16 3 0 github.com/letsencrypt/boulder/cmd/shell.go:199.2,200.16 2 0 github.com/letsencrypt/boulder/cmd/shell.go:203.2,205.16 3 0 diff --git a/cmd/shell_test.go b/cmd/shell_test.go index 04b7ce249..a674ff740 100644 --- a/cmd/shell_test.go +++ b/cmd/shell_test.go @@ -130,3 +130,33 @@ func TestVersionString(t *testing.T) { expected := fmt.Sprintf("Versions: test=(TestBuildID RightNow!) Golang=(%s) BuildHost=(Localhost)", runtime.Version()) test.AssertEquals(t, versionStr, expected) } + +func TestLoadCert(t *testing.T) { + testCases := []struct { + path string + expectedErr string + }{ + { + "", + "Issuer certificate was not provided in config.", + }, + { + "../does/not/exist", + "open ../does/not/exist: no such file or directory", + }, + { + "../test/test-ca.key", + "Invalid certificate value returned", + }, + } + + for _, tc := range testCases { + _, err := LoadCert(tc.path) + test.AssertError(t, err, fmt.Sprintf("LoadCert(%q) did not error", tc.path)) + test.AssertEquals(t, err.Error(), tc.expectedErr) + } + + bytes, err := LoadCert("../test/test-ca.pem") + test.AssertNotError(t, err, "LoadCert(../test/test-ca.pem) errored") + test.AssertNotEquals(t, len(bytes), 0) +}