1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

testlib: Add GenerateCert function

This patch moves the GenerateCert function from the smtpsrv tests to the
common testlib, so it can be used by other tests in the future.
This commit is contained in:
Alberto Bertogli
2021-10-15 11:16:46 +01:00
parent ed38945fca
commit 90d385556f
3 changed files with 103 additions and 76 deletions

View File

@@ -96,3 +96,25 @@ func TestWaitFor(t *testing.T) {
t.Errorf("WaitFor(false) worked")
}
}
func TestGenerateCert(t *testing.T) {
dir := MustTempDir(t)
defer os.RemoveAll(dir)
conf, err := GenerateCert(dir)
if err != nil {
t.Errorf("GenerateCert returned error: %v", err)
}
if conf.ServerName != "localhost" {
t.Errorf("Config server name %q != localhost", conf.ServerName)
}
if conf.RootCAs == nil {
t.Errorf("Config had an empty RootCAs pool")
}
}
func TestGenerateCertBadDir(t *testing.T) {
conf, err := GenerateCert("/doesnotexist/")
if err == nil || conf != nil {
t.Fatalf("GenerateCert returned non-error: %v / %v", conf, err)
}
}