forked from alexedwards/scs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_go120_test.go
61 lines (43 loc) · 1.07 KB
/
session_go120_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build go1.20
// +build go1.20
package scs
import (
"fmt"
"net/http"
"testing"
"time"
)
func TestFlusher(t *testing.T) {
t.Parallel()
sessionManager := New()
sessionManager.Lifetime = 500 * time.Millisecond
mux := http.NewServeMux()
mux.HandleFunc("/get", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, ok := w.(http.Flusher)
fmt.Fprint(w, ok)
}))
ts := newTestServer(t, sessionManager.LoadAndSave(mux))
defer ts.Close()
ts.execute(t, "/put")
_, body := ts.execute(t, "/get")
if body != "true" {
t.Errorf("want %q; got %q", "true", body)
}
}
func TestHijacker(t *testing.T) {
t.Parallel()
sessionManager := New()
sessionManager.Lifetime = 500 * time.Millisecond
mux := http.NewServeMux()
mux.HandleFunc("/get", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, ok := w.(http.Hijacker)
fmt.Fprint(w, ok)
}))
ts := newTestServer(t, sessionManager.LoadAndSave(mux))
defer ts.Close()
ts.execute(t, "/put")
_, body := ts.execute(t, "/get")
if body != "true" {
t.Errorf("want %q; got %q", "true", body)
}
}