Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/chiPublic

Commit7335050

Browse files
Fix condition in TestRedirectSlashes (#856)
* Fix condition in TestRedirectSlashes* Improve test logs in middleware/strip_test.go---------Co-authored-by: Vojtech Vitek <vojtech.vitek@golang.cz>
1 parentdf0303d commit7335050

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

‎middleware/strip_test.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ func TestStripSlashes(t *testing.T) {
3737
deferts.Close()
3838

3939
if_,resp:=testRequest(t,ts,"GET","/",nil);resp!="root" {
40-
t.Fatalf(resp)
40+
t.Fatal(resp)
4141
}
4242
if_,resp:=testRequest(t,ts,"GET","//",nil);resp!="root" {
43-
t.Fatalf(resp)
43+
t.Fatal(resp)
4444
}
4545
if_,resp:=testRequest(t,ts,"GET","/accounts/admin",nil);resp!="admin" {
46-
t.Fatalf(resp)
46+
t.Fatal(resp)
4747
}
4848
if_,resp:=testRequest(t,ts,"GET","/accounts/admin/",nil);resp!="admin" {
49-
t.Fatalf(resp)
49+
t.Fatal(resp)
5050
}
5151
if_,resp:=testRequest(t,ts,"GET","/nothing-here",nil);resp!="nothing here" {
52-
t.Fatalf(resp)
52+
t.Fatal(resp)
5353
}
5454
}
5555

@@ -80,22 +80,22 @@ func TestStripSlashesInRoute(t *testing.T) {
8080
deferts.Close()
8181

8282
if_,resp:=testRequest(t,ts,"GET","/hi",nil);resp!="hi" {
83-
t.Fatalf(resp)
83+
t.Fatal(resp)
8484
}
8585
if_,resp:=testRequest(t,ts,"GET","/hi/",nil);resp!="nothing here" {
86-
t.Fatalf(resp)
86+
t.Fatal(resp)
8787
}
8888
if_,resp:=testRequest(t,ts,"GET","/accounts/admin",nil);resp!="accounts index" {
89-
t.Fatalf(resp)
89+
t.Fatal(resp)
9090
}
9191
if_,resp:=testRequest(t,ts,"GET","/accounts/admin/",nil);resp!="accounts index" {
92-
t.Fatalf(resp)
92+
t.Fatal(resp)
9393
}
9494
if_,resp:=testRequest(t,ts,"GET","/accounts/admin/query",nil);resp!="admin" {
95-
t.Fatalf(resp)
95+
t.Fatal(resp)
9696
}
9797
if_,resp:=testRequest(t,ts,"GET","/accounts/admin/query/",nil);resp!="admin" {
98-
t.Fatalf(resp)
98+
t.Fatal(resp)
9999
}
100100
}
101101

@@ -125,33 +125,33 @@ func TestRedirectSlashes(t *testing.T) {
125125
ts:=httptest.NewServer(r)
126126
deferts.Close()
127127

128-
ifresp,body:=testRequest(t,ts,"GET","/",nil);body!="root"&&resp.StatusCode!=200 {
129-
t.Fatalf(body)
128+
ifresp,body:=testRequest(t,ts,"GET","/",nil);body!="root"||resp.StatusCode!=200 {
129+
t.Fatal(body,resp.StatusCode)
130130
}
131131

132132
// NOTE: the testRequest client will follow the redirection..
133-
ifresp,body:=testRequest(t,ts,"GET","//",nil);body!="root"&&resp.StatusCode!=200 {
134-
t.Fatalf(body)
133+
ifresp,body:=testRequest(t,ts,"GET","//",nil);body!="root"||resp.StatusCode!=200 {
134+
t.Fatal(body,resp.StatusCode)
135135
}
136136

137-
ifresp,body:=testRequest(t,ts,"GET","/accounts/admin",nil);body!="admin"&&resp.StatusCode!=200 {
138-
t.Fatalf(body)
137+
ifresp,body:=testRequest(t,ts,"GET","/accounts/admin",nil);body!="admin"||resp.StatusCode!=200 {
138+
t.Fatal(body,resp.StatusCode)
139139
}
140140

141141
// NOTE: the testRequest client will follow the redirection..
142-
ifresp,body:=testRequest(t,ts,"GET","/accounts/admin/",nil);body!="admin"&&resp.StatusCode!=200 {
143-
t.Fatalf(body)
142+
ifresp,body:=testRequest(t,ts,"GET","/accounts/admin/",nil);body!="admin"||resp.StatusCode!=200 {
143+
t.Fatal(body,resp.StatusCode)
144144
}
145145

146-
ifresp,body:=testRequest(t,ts,"GET","/nothing-here",nil);body!="nothing here"&&resp.StatusCode!=200 {
147-
t.Fatalf(body)
146+
ifresp,body:=testRequest(t,ts,"GET","/nothing-here",nil);body!="nothing here"||resp.StatusCode!=404 {
147+
t.Fatal(body,resp.StatusCode)
148148
}
149149

150150
// Ensure redirect Location url is correct
151151
{
152152
resp,body:=testRequestNoRedirect(t,ts,"GET","/accounts/someuser/",nil)
153153
ifresp.StatusCode!=301 {
154-
t.Fatalf(body)
154+
t.Fatal(body,resp.StatusCode)
155155
}
156156
location:=resp.Header.Get("Location")
157157
if!strings.HasPrefix(location,"//")||!strings.HasSuffix(location,"/accounts/someuser") {
@@ -163,7 +163,7 @@ func TestRedirectSlashes(t *testing.T) {
163163
{
164164
resp,body:=testRequestNoRedirect(t,ts,"GET","/accounts/someuser/?a=1&b=2",nil)
165165
ifresp.StatusCode!=301 {
166-
t.Fatalf(body)
166+
t.Fatal(body,resp.StatusCode)
167167
}
168168
location:=resp.Header.Get("Location")
169169
if!strings.HasPrefix(location,"//")||!strings.HasSuffix(location,"/accounts/someuser?a=1&b=2") {
@@ -180,8 +180,8 @@ func TestRedirectSlashes(t *testing.T) {
180180
ifu,err:=url.Parse(ts.URL);err!=nil&&resp.Request.URL.Host!=u.Host {
181181
t.Fatalf("host should remain the same. got: %q, want: %q",resp.Request.URL.Host,ts.URL)
182182
}
183-
ifbody!="nothing here"&&resp.StatusCode!=404 {
184-
t.Fatalf(body)
183+
ifbody!="nothing here"||resp.StatusCode!=404 {
184+
t.Fatal(body,resp.StatusCode)
185185
}
186186
}
187187
}
@@ -192,8 +192,8 @@ func TestRedirectSlashes(t *testing.T) {
192192
ifu,err:=url.Parse(ts.URL);err!=nil&&resp.Request.URL.Host!=u.Host {
193193
t.Fatalf("host should remain the same. got: %q, want: %q",resp.Request.URL.Host,ts.URL)
194194
}
195-
ifbody!="nothing here"&&resp.StatusCode!=404 {
196-
t.Fatalf(body)
195+
ifbody!="nothing here"||resp.StatusCode!=404 {
196+
t.Fatal(body,resp.StatusCode)
197197
}
198198
}
199199
}
@@ -219,21 +219,21 @@ func TestStripSlashesWithNilContext(t *testing.T) {
219219
deferts.Close()
220220

221221
if_,resp:=testRequest(t,ts,"GET","/",nil);resp!="root" {
222-
t.Fatalf(resp)
222+
t.Fatal(resp)
223223
}
224224
if_,resp:=testRequest(t,ts,"GET","//",nil);resp!="root" {
225-
t.Fatalf(resp)
225+
t.Fatal(resp)
226226
}
227227
if_,resp:=testRequest(t,ts,"GET","/accounts",nil);resp!="accounts" {
228-
t.Fatalf(resp)
228+
t.Fatal(resp)
229229
}
230230
if_,resp:=testRequest(t,ts,"GET","/accounts/",nil);resp!="accounts" {
231-
t.Fatalf(resp)
231+
t.Fatal(resp)
232232
}
233233
if_,resp:=testRequest(t,ts,"GET","/accounts/admin",nil);resp!="admin" {
234-
t.Fatalf(resp)
234+
t.Fatal(resp)
235235
}
236236
if_,resp:=testRequest(t,ts,"GET","/accounts/admin/",nil);resp!="admin" {
237-
t.Fatalf(resp)
237+
t.Fatal(resp)
238238
}
239239
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp