Skip to content

Commit c1f5b4a

Browse files
committed
Refactor tests
Signed-off-by: Adam Reese <[email protected]>
1 parent 0b1e2f8 commit c1f5b4a

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ func init() {
1010
r := redirect.NewSpinRedirect()
1111
spinhttp.Handle(r.HandleFunc)
1212
}
13-
14-
func main() {
15-
}

redirect/redirect_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestWithPath(t *testing.T) {
3030
wantURL string
3131
}
3232

33-
var tests = []test{
33+
tests := []test{
3434
{
3535
"include_path false",
3636
testConfigReader{},
@@ -51,20 +51,22 @@ func TestWithPath(t *testing.T) {
5151
},
5252
}
5353

54-
for _, test := range tests {
55-
r := &SpinRedirect{
56-
cfg: &test.cfg,
57-
}
54+
for _, tc := range tests {
55+
t.Run(tc.name, func(t *testing.T) {
56+
r := &SpinRedirect{
57+
cfg: &tc.cfg,
58+
}
5859

59-
dest := "http://localhost"
60-
req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost%s", test.reqPath), nil)
61-
if err != nil {
62-
t.Fatalf("failed to create new http request: %s", err.Error())
63-
}
60+
dest := "http://localhost"
61+
req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost%s", tc.reqPath), nil)
62+
if err != nil {
63+
t.Fatalf("failed to create new http request: %s", err)
64+
}
6465

65-
gotURL := r.WithPath(dest, req)
66-
if gotURL != test.wantURL {
67-
t.Fatalf("test '%s' failed: got '%s', want '%s'", test.name, gotURL, test.wantURL)
68-
}
66+
gotURL := r.WithPath(dest, req)
67+
if gotURL != tc.wantURL {
68+
t.Fatalf("failed: got '%s', want '%s'", gotURL, tc.wantURL)
69+
}
70+
})
6971
}
7072
}

0 commit comments

Comments
 (0)