forked from kuskoman/logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
38 lines (35 loc) · 1.05 KB
/
server_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
package server
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestNewAppServer(t *testing.T) {
t.Run("Test handling of /metrics endpoint", func(t *testing.T) {
server := NewAppServer("", "8080")
req, err := http.NewRequest("GET", "/metrics", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
server.Handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("unexpected status code: got %v want %v", status, http.StatusOK)
}
})
t.Run("Test handling of / endpoint", func(t *testing.T) {
server := NewAppServer("", "8080")
req, err := http.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
server.Handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusMovedPermanently {
t.Errorf("unexpected status code: got %v want %v", status, http.StatusMovedPermanently)
}
if location := rr.Header().Get("Location"); location != "/metrics" {
t.Errorf("unexpected redirect location: got %v want %v", location, "/metrics")
}
})
}