aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-03-14 22:37:59 +0700
committerShulhan <ms@kilabit.info>2021-03-14 22:40:05 +0700
commite7552ad0189f761875bc1c2ca3dd716d43a01e0d (patch)
treefd68ec29d23fb9a807a7382088020e3b17d446fd /lib/http
parent882727d89c8e7f9b9761009ccdca1af8c18d0a30 (diff)
downloadpakakeh.go-e7552ad0189f761875bc1c2ca3dd716d43a01e0d.tar.xz
all: refactoring the test.Assert and test.AssertBench signature
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/requestmethod_test.go2
-rw-r--r--lib/http/requesttype_test.go2
-rw-r--r--lib/http/response_test.go12
-rw-r--r--lib/http/responsetype_test.go2
-rw-r--r--lib/http/route_test.go8
-rw-r--r--lib/http/server_test.go53
6 files changed, 35 insertions, 44 deletions
diff --git a/lib/http/requestmethod_test.go b/lib/http/requestmethod_test.go
index dde4b0fd..e0ef4cae 100644
--- a/lib/http/requestmethod_test.go
+++ b/lib/http/requestmethod_test.go
@@ -37,6 +37,6 @@ func TestRequestMethod_String(t *testing.T) {
}
for _, c := range cases {
- test.Assert(t, "RequestMethod.String", c.exp, c.m.String(), true)
+ test.Assert(t, "RequestMethod.String", c.exp, c.m.String())
}
}
diff --git a/lib/http/requesttype_test.go b/lib/http/requesttype_test.go
index 52aaef36..85f30f3e 100644
--- a/lib/http/requesttype_test.go
+++ b/lib/http/requesttype_test.go
@@ -23,6 +23,6 @@ func TestRequestType_String(t *testing.T) {
}
for _, c := range cases {
- test.Assert(t, "RequestMethod.String", c.exp, c.rt.String(), true)
+ test.Assert(t, "RequestMethod.String", c.exp, c.rt.String())
}
}
diff --git a/lib/http/response_test.go b/lib/http/response_test.go
index ffd57388..4625b35d 100644
--- a/lib/http/response_test.go
+++ b/lib/http/response_test.go
@@ -107,12 +107,12 @@ func TestParseResponseHeader(t *testing.T) {
got, rest, err := ParseResponseHeader(c.raw)
if err != nil {
- test.Assert(t, "error", c.expErr, err.Error(), true)
+ test.Assert(t, "error", c.expErr, err.Error())
continue
}
- test.Assert(t, "http.Response", c.expResp, got, true)
- test.Assert(t, "rest", c.expRest, rest, true)
+ test.Assert(t, "http.Response", c.expResp, got)
+ test.Assert(t, "rest", c.expRest, rest)
}
}
@@ -176,11 +176,11 @@ func TestParseHeaders(t *testing.T) {
header, rest, err := parseHeaders(c.raw)
if err != nil {
- test.Assert(t, "error", c.expErr, err.Error(), true)
+ test.Assert(t, "error", c.expErr, err.Error())
continue
}
- test.Assert(t, "header", c.exp, header, true)
- test.Assert(t, "rest", c.expRest, rest, true)
+ test.Assert(t, "header", c.exp, header)
+ test.Assert(t, "rest", c.expRest, rest)
}
}
diff --git a/lib/http/responsetype_test.go b/lib/http/responsetype_test.go
index 030fc8f8..2a2926c3 100644
--- a/lib/http/responsetype_test.go
+++ b/lib/http/responsetype_test.go
@@ -30,6 +30,6 @@ func TestResponseType_String(t *testing.T) {
}
for _, c := range cases {
- test.Assert(t, "ResponseType.String", c.exp, c.restype.String(), true)
+ test.Assert(t, "ResponseType.String", c.exp, c.restype.String())
}
}
diff --git a/lib/http/route_test.go b/lib/http/route_test.go
index 83cfc491..1a84c447 100644
--- a/lib/http/route_test.go
+++ b/lib/http/route_test.go
@@ -106,11 +106,11 @@ func TestNewRoute(t *testing.T) {
got, err := newRoute(c.ep)
if err != nil {
- test.Assert(t, "error", c.expError, err.Error(), true)
+ test.Assert(t, "error", c.expError, err.Error())
continue
}
- test.Assert(t, "newRoute", c.exp, got, true)
+ test.Assert(t, "newRoute", c.exp, got)
}
}
@@ -242,8 +242,8 @@ func TestRoute_parse(t *testing.T) {
for _, tp := range c.paths {
gotVals, gotOK := rute.parse(tp.path)
- test.Assert(t, "vals", tp.expVals, gotVals, true)
- test.Assert(t, "ok", tp.expOK, gotOK, true)
+ test.Assert(t, "vals", tp.expVals, gotVals)
+ test.Assert(t, "ok", tp.expOK, gotOK)
}
}
}
diff --git a/lib/http/server_test.go b/lib/http/server_test.go
index 91564f27..1f87fa45 100644
--- a/lib/http/server_test.go
+++ b/lib/http/server_test.go
@@ -129,7 +129,7 @@ func TestRegisterDelete(t *testing.T) {
err := testServer.RegisterEndpoint(c.ep)
if err != nil {
- test.Assert(t, "error", c.expError, err.Error(), true)
+ test.Assert(t, "error", c.expError, err.Error())
continue
}
@@ -157,17 +157,17 @@ func TestRegisterDelete(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+
if c.expStatusCode != http.StatusOK {
continue
}
- test.Assert(t, "Body", c.expBody, string(body), true)
+ test.Assert(t, "Body", c.expBody, string(body))
gotContentType := res.Header.Get(HeaderContentType)
- test.Assert(t, "Content-Type", c.expContentType, gotContentType, true)
+ test.Assert(t, "Content-Type", c.expContentType, gotContentType)
}
}
@@ -235,8 +235,7 @@ func TestRegisterEvaluator(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
}
}
@@ -304,8 +303,8 @@ func TestRegisterGet(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode, true)
- test.Assert(t, "Body", c.expBody, string(body), true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Body", c.expBody, string(body))
}
}
@@ -371,13 +370,10 @@ func TestRegisterHead(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
- test.Assert(t, "Body", c.expBody, string(body), true)
- test.Assert(t, "Header.ContentType", c.expContentType,
- res.Header[HeaderContentType], true)
- test.Assert(t, "Header.ContentLength", c.expContentLength,
- res.Header[HeaderContentLength], true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Body", c.expBody, string(body))
+ test.Assert(t, "Header.ContentType", c.expContentType, res.Header[HeaderContentType])
+ test.Assert(t, "Header.ContentLength", c.expContentLength, res.Header[HeaderContentLength])
}
}
@@ -438,9 +434,8 @@ func TestRegisterPatch(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
- test.Assert(t, "Body", c.expBody, string(body), true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Body", c.expBody, string(body))
}
}
@@ -511,9 +506,8 @@ k=vv`,
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
- test.Assert(t, "Body", c.expBody, string(body), true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Body", c.expBody, string(body))
}
}
@@ -571,9 +565,8 @@ func TestRegisterPut(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
- test.Assert(t, "Body", c.expBody, string(body), true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Body", c.expBody, string(body))
}
}
@@ -637,9 +630,8 @@ func TestServeHTTPOptions(t *testing.T) {
gotAllow := res.Header.Get("Allow")
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
- test.Assert(t, "Allow", c.expAllow, gotAllow, true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Allow", c.expAllow, gotAllow)
}
}
@@ -791,8 +783,7 @@ func TestStatusError(t *testing.T) {
t.Fatal(e)
}
- test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode,
- true)
- test.Assert(t, "Body", c.expBody, string(body), true)
+ test.Assert(t, "StatusCode", c.expStatusCode, res.StatusCode)
+ test.Assert(t, "Body", c.expBody, string(body))
}
}