-
Notifications
You must be signed in to change notification settings - Fork 5
/
x509_test.go
46 lines (39 loc) · 1.19 KB
/
x509_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
// TestX509RequestHandler provides test of GET method for our service
func TestX509RequestHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(x509RequestHandler)
handler.ServeHTTP(rr, req)
// since we don't provide valid cert we should get http.StatusUnauthorized
if status := rr.Code; status != http.StatusUnauthorized {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
}
// BenchmarkX509RequestHandler provides test of GET method for our service
func BenchmarkX509RequestHandler(b *testing.B) {
req, err := http.NewRequest("GET", "/", nil)
if err != nil {
b.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(x509RequestHandler)
// perform benchmark test
for n := 0; n < b.N; n++ {
handler.ServeHTTP(rr, req)
// since we don't provide valid cert we should get http.StatusUnauthorized
if status := rr.Code; status != http.StatusUnauthorized {
b.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
}
}