From e8bc42d84ce000740c8b623f2ba86df610c29e00 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 26 Feb 2021 12:52:54 +0100 Subject: [PATCH] Add certificate_test.go. --- webserver/certificate_test.go | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 webserver/certificate_test.go diff --git a/webserver/certificate_test.go b/webserver/certificate_test.go new file mode 100644 index 0000000..0441caa --- /dev/null +++ b/webserver/certificate_test.go @@ -0,0 +1,51 @@ +package webserver + +import ( + "testing" +) + +func TestGenerateCertificate(t *testing.T) { + _, err := generateCertificate() + if err != nil { + t.Errorf("generateCertificate: %v", err) + } +} + +func BenchmarkGenerateCertificate(b *testing.B) { + for i := 0; i < b.N; i++ { + _, err := generateCertificate() + if err != nil { + b.Errorf("generateCertificate: %v", err) + } + } +} + +func TestGetCertificate(t *testing.T) { + cert1, err := getCertificate("/tmp/no/such/file") + if err != nil { + t.Errorf("getCertificate: %v", err) + } + + cert2, err := getCertificate("/tmp/no/such/file") + if err != nil { + t.Errorf("getCertificate: %v", err) + } + + if cert1 != cert2 { + t.Errorf("cert1 != cert2") + } +} + +func BenchmarkGetCertificate(b *testing.B) { + _, err := getCertificate("/tmp/no/such/file") + if err != nil { + b.Errorf("getCertificate: %v", err) + } + b.StartTimer() + for i := 0; i < b.N; i++ { + _, err := getCertificate("/tmp/no/such/file") + if err != nil { + b.Errorf("getCertificate: %v", err) + } + } +}