Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandled error in hooks test #2070

Merged
merged 14 commits into from Sep 2, 2022
15 changes: 10 additions & 5 deletions helpers_test.go
Expand Up @@ -22,7 +22,8 @@ func Test_Utils_ETag(t *testing.T) {
t.Run("Not Status OK", func(t *testing.T) {
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
c.SendString("Hello, World!")
err := c.SendString("Hello, World!")
utils.AssertEqual(t, nil, err)
c.Status(201)
setETag(c, false)
utils.AssertEqual(t, "", string(c.Response().Header.Peek(HeaderETag)))
Expand All @@ -38,7 +39,8 @@ func Test_Utils_ETag(t *testing.T) {
t.Run("Has HeaderIfNoneMatch", func(t *testing.T) {
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
c.SendString("Hello, World!")
err := c.SendString("Hello, World!")
utils.AssertEqual(t, nil, err)
c.Request().Header.Set(HeaderIfNoneMatch, `"13-1831710635"`)
setETag(c, false)
utils.AssertEqual(t, 304, c.Response().StatusCode())
Expand All @@ -49,7 +51,8 @@ func Test_Utils_ETag(t *testing.T) {
t.Run("No HeaderIfNoneMatch", func(t *testing.T) {
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
c.SendString("Hello, World!")
err := c.SendString("Hello, World!")
utils.AssertEqual(t, nil, err)
setETag(c, false)
utils.AssertEqual(t, `"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
})
Expand All @@ -60,7 +63,8 @@ func Benchmark_Utils_ETag(b *testing.B) {
app := New()
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
c.SendString("Hello, World!")
err := c.SendString("Hello, World!")
utils.AssertEqual(b, nil, err)
for n := 0; n < b.N; n++ {
setETag(c, false)
}
Expand All @@ -73,7 +77,8 @@ func Test_Utils_ETag_Weak(t *testing.T) {
t.Run("Set Weak", func(t *testing.T) {
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
c.SendString("Hello, World!")
err := c.SendString("Hello, World!")
utils.AssertEqual(t, nil, err)
setETag(c, true)
utils.AssertEqual(t, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
})
Expand Down
16 changes: 10 additions & 6 deletions hooks_test.go
Expand Up @@ -42,7 +42,8 @@ func Test_Hook_OnName(t *testing.T) {
defer bytebufferpool.Put(buf)

app.Hooks().OnName(func(r Route) error {
buf.WriteString(r.Name)
_, err := buf.WriteString(r.Name)
utils.AssertEqual(t, nil, err)

return nil
})
Expand Down Expand Up @@ -84,8 +85,8 @@ func Test_Hook_OnGroup(t *testing.T) {
defer bytebufferpool.Put(buf)

app.Hooks().OnGroup(func(g Group) error {
buf.WriteString(g.Prefix)

_, err := buf.WriteString(g.Prefix)
utils.AssertEqual(t, nil, err)
return nil
})

Expand All @@ -104,7 +105,8 @@ func Test_Hook_OnGroupName(t *testing.T) {
defer bytebufferpool.Put(buf)

app.Hooks().OnGroupName(func(g Group) error {
buf.WriteString(g.name)
_, err := buf.WriteString(g.name)
utils.AssertEqual(t, nil, err)

return nil
})
Expand Down Expand Up @@ -143,7 +145,8 @@ func Test_Hook_OnShutdown(t *testing.T) {
defer bytebufferpool.Put(buf)

app.Hooks().OnShutdown(func() error {
buf.WriteString("shutdowning")
_, err := buf.WriteString("shutdowning")
utils.AssertEqual(t, nil, err)

return nil
})
Expand All @@ -163,7 +166,8 @@ func Test_Hook_OnListen(t *testing.T) {
defer bytebufferpool.Put(buf)

app.Hooks().OnListen(func() error {
buf.WriteString("ready")
_, err := buf.WriteString("ready")
utils.AssertEqual(t, nil, err)

return nil
})
Expand Down
12 changes: 9 additions & 3 deletions listen_test.go
Expand Up @@ -166,12 +166,18 @@ func captureOutput(f func()) string {
go func() {
var buf bytes.Buffer
wg.Done()
io.Copy(&buf, reader)
_, err := io.Copy(&buf, reader)
if err != nil {
panic(err)
}
out <- buf.String()
}()
wg.Wait()
f()
writer.Close()
err = writer.Close()
if err != nil {
panic(err)
}
return <-out
}

Expand Down Expand Up @@ -244,6 +250,6 @@ func Test_App_print_Route_with_group(t *testing.T) {
utils.AssertEqual(t, true, strings.Contains(printRoutesMessage, "/v1/test/fiber/*"))
}

func emptyHandler(c *Ctx) error {
func emptyHandler(_ *Ctx) error {
return nil
}
4 changes: 2 additions & 2 deletions path.go
Expand Up @@ -61,7 +61,7 @@ const (
paramConstraintDataSeparator byte = ',' // separator of datas of type constraint for a parameter
)

// parameter constraint types
// TypeConstraint parameter constraint types
type TypeConstraint int16

type Constraint struct {
Expand Down Expand Up @@ -260,7 +260,7 @@ func (routeParser *routeParser) analyseParameterPart(pattern string) (string, *r
// Check has constraint
var constraints []*Constraint

if hasConstraint := (parameterConstraintStart != -1 && parameterConstraintEnd != -1); hasConstraint {
if hasConstraint := parameterConstraintStart != -1 && parameterConstraintEnd != -1; hasConstraint {
constraintString := pattern[parameterConstraintStart+1 : parameterConstraintEnd]
userconstraints := splitNonEscaped(constraintString, string(parameterConstraintSeparatorChars))
constraints = make([]*Constraint, 0, len(userconstraints))
Expand Down