-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtraefiktimestampheader_test.go
More file actions
44 lines (35 loc) · 989 Bytes
/
traefiktimestampheader_test.go
File metadata and controls
44 lines (35 loc) · 989 Bytes
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
package traefiktimestampheader
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestTimestampHeader(t *testing.T) {
cfg := CreateConfig()
ctx := context.Background()
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
// Create the plugin
plugin, err := New(ctx, next, cfg, "timestamp-header")
if err != nil {
t.Fatalf("Failed to create plugin: %v", err)
}
recorder := httptest.NewRecorder()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil)
if err != nil {
t.Fatal(err)
}
// Call the plugin
plugin.ServeHTTP(recorder, req)
// Validate the header
headerValue := req.Header.Get("x-request-received-at")
if headerValue == "" {
t.Fatalf("Expected 'request-received-at' header, but got none")
}
// Parse and validate the timestamp format
_, err = time.Parse(time.RFC3339Nano, headerValue)
if err != nil {
t.Errorf("Invalid timestamp format in header: %v", err)
}
}