Skip to content

Commit f57b7e2

Browse files
Niels Widgerkisielk
authored andcommitted
Don't use t.Run in tests, not supported in earlier Go versions
This package is meant to work on Go versions going back to Go 1.3, which means tests can't use testing.T.Run which doesn't exists in Go 1.6 and earlier.
1 parent 3ab3680 commit f57b7e2

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

cookie_go111_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package sessions
44

55
import (
66
"net/http"
7-
"strconv"
87
"testing"
98
)
109

@@ -19,14 +18,12 @@ func TestNewCookieFromOptionsSameSite(t *testing.T) {
1918
{http.SameSiteStrictMode},
2019
}
2120
for i, v := range tests {
22-
t.Run(strconv.Itoa(i+1), func(t *testing.T) {
23-
options := &Options{
24-
SameSite: v.sameSite,
25-
}
26-
cookie := newCookieFromOptions("", "", options)
27-
if cookie.SameSite != v.sameSite {
28-
t.Fatalf("bad cookie sameSite: got %v, want %v", cookie.SameSite, v.sameSite)
29-
}
30-
})
21+
options := &Options{
22+
SameSite: v.sameSite,
23+
}
24+
cookie := newCookieFromOptions("", "", options)
25+
if cookie.SameSite != v.sameSite {
26+
t.Fatalf("%v: bad cookie sameSite: got %v, want %v", i+1, cookie.SameSite, v.sameSite)
27+
}
3128
}
3229
}

cookie_test.go

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sessions
22

33
import (
4-
"strconv"
54
"testing"
65
)
76

@@ -25,36 +24,34 @@ func TestNewCookieFromOptions(t *testing.T) {
2524
{"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, false},
2625
}
2726
for i, v := range tests {
28-
t.Run(strconv.Itoa(i+1), func(t *testing.T) {
29-
options := &Options{
30-
Path: v.path,
31-
Domain: v.domain,
32-
MaxAge: v.maxAge,
33-
Secure: v.secure,
34-
HttpOnly: v.httpOnly,
35-
}
36-
cookie := newCookieFromOptions(v.name, v.value, options)
37-
if cookie.Name != v.name {
38-
t.Fatalf("bad cookie name: got %q, want %q", cookie.Name, v.name)
39-
}
40-
if cookie.Value != v.value {
41-
t.Fatalf("bad cookie value: got %q, want %q", cookie.Value, v.value)
42-
}
43-
if cookie.Path != v.path {
44-
t.Fatalf("bad cookie path: got %q, want %q", cookie.Path, v.path)
45-
}
46-
if cookie.Domain != v.domain {
47-
t.Fatalf("bad cookie domain: got %q, want %q", cookie.Domain, v.domain)
48-
}
49-
if cookie.MaxAge != v.maxAge {
50-
t.Fatalf("bad cookie maxAge: got %q, want %q", cookie.MaxAge, v.maxAge)
51-
}
52-
if cookie.Secure != v.secure {
53-
t.Fatalf("bad cookie secure: got %v, want %v", cookie.Secure, v.secure)
54-
}
55-
if cookie.HttpOnly != v.httpOnly {
56-
t.Fatalf("bad cookie httpOnly: got %v, want %v", cookie.HttpOnly, v.httpOnly)
57-
}
58-
})
27+
options := &Options{
28+
Path: v.path,
29+
Domain: v.domain,
30+
MaxAge: v.maxAge,
31+
Secure: v.secure,
32+
HttpOnly: v.httpOnly,
33+
}
34+
cookie := newCookieFromOptions(v.name, v.value, options)
35+
if cookie.Name != v.name {
36+
t.Fatalf("%v: bad cookie name: got %q, want %q", i+1, cookie.Name, v.name)
37+
}
38+
if cookie.Value != v.value {
39+
t.Fatalf("%v: bad cookie value: got %q, want %q", i+1, cookie.Value, v.value)
40+
}
41+
if cookie.Path != v.path {
42+
t.Fatalf("%v: bad cookie path: got %q, want %q", i+1, cookie.Path, v.path)
43+
}
44+
if cookie.Domain != v.domain {
45+
t.Fatalf("%v: bad cookie domain: got %q, want %q", i+1, cookie.Domain, v.domain)
46+
}
47+
if cookie.MaxAge != v.maxAge {
48+
t.Fatalf("%v: bad cookie maxAge: got %q, want %q", i+1, cookie.MaxAge, v.maxAge)
49+
}
50+
if cookie.Secure != v.secure {
51+
t.Fatalf("%v: bad cookie secure: got %v, want %v", i+1, cookie.Secure, v.secure)
52+
}
53+
if cookie.HttpOnly != v.httpOnly {
54+
t.Fatalf("%v: bad cookie httpOnly: got %v, want %v", i+1, cookie.HttpOnly, v.httpOnly)
55+
}
5956
}
6057
}

0 commit comments

Comments
 (0)