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

refactor: use utils.AssertEqual instead of t.Fatal on some tests #2653

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,7 @@ func Test_App_Shutdown(t *testing.T) {
t.Parallel()
app := &App{}
if err := app.Shutdown(); err != nil {
if err.Error() != "shutdown: server is not running" {
t.Fatal()
}
utils.AssertEqual(t, "shutdown: server is not running", err.Error())
}
})
}
Expand Down
68 changes: 23 additions & 45 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,15 @@ func Test_Ctx_Body_With_Compression(t *testing.T) {
if strings.Contains(tCase.contentEncoding, "gzip") {
var b bytes.Buffer
gz := gzip.NewWriter(&b)

_, err := gz.Write(tCase.body)
if err != nil {
t.Fatal(err)
}
if err = gz.Flush(); err != nil {
t.Fatal(err)
}
if err = gz.Close(); err != nil {
t.Fatal(err)
}
utils.AssertEqual(t, nil, err)

err = gz.Flush()
utils.AssertEqual(t, nil, err)

err = gz.Close()
utils.AssertEqual(t, nil, err)
tCase.body = b.Bytes()
}

Expand Down Expand Up @@ -619,9 +618,8 @@ func Test_Ctx_ParamParser(t *testing.T) {
RoleID uint `params:"roleId"`
}
d := new(Demo)
if err := ctx.ParamsParser(d); err != nil {
t.Fatal(err)
}

utils.AssertEqual(t, nil, ctx.ParamsParser(d))
utils.AssertEqual(t, uint(111), d.UserID)
utils.AssertEqual(t, uint(222), d.RoleID)
return nil
Expand Down Expand Up @@ -4946,21 +4944,17 @@ func Test_Ctx_BodyStreamWriter(t *testing.T) {
}
fmt.Fprintf(w, "body writer line 2\n")
})
if !ctx.IsBodyStream() {
t.Fatal("IsBodyStream must return true")
}

utils.AssertEqual(t, true, ctx.IsBodyStream())

s := ctx.Response.String()
br := bufio.NewReader(bytes.NewBufferString(s))
var resp fasthttp.Response
if err := resp.Read(br); err != nil {
t.Fatalf("Error when reading response: %s", err)
}
utils.AssertEqual(t, nil, resp.Read(br))

body := string(resp.Body())
expectedBody := "body writer line 1\nbody writer line 2\n"
if body != expectedBody {
t.Fatalf("unexpected body: %q. Expecting %q", body, expectedBody)
}
utils.AssertEqual(t, expectedBody, body)
}

// go test -v -run=^$ -bench=Benchmark_Ctx_BodyStreamWriter -benchmem -count=4
Expand Down Expand Up @@ -5010,14 +5004,10 @@ func TestCtx_ParamsInt(t *testing.T) {
num, err := c.ParamsInt("user")

// Check the number matches
if num != 1111 {
t.Fatalf("Expected number 1111 from the path, got %d", num)
}
utils.AssertEqual(t, 1111, num)

// Check no errors are returned, because we want NO errors in this one
if err != nil {
t.Fatalf("Expected nil error for 1111 test, got " + err.Error())
}
utils.AssertEqual(t, nil, err)

return nil
})
Expand All @@ -5030,14 +5020,10 @@ func TestCtx_ParamsInt(t *testing.T) {
num, err := c.ParamsInt("user")

// Check the number matches
if num != 0 {
t.Fatalf("Expected number 0 from the path, got %d", num)
}
utils.AssertEqual(t, 0, num)

// Check an error is returned, because we want NO errors in this one
if err == nil {
t.Fatal("Expected non nil error for bad req test, got nil")
}
utils.AssertEqual(t, true, err != nil)

return nil
})
Expand All @@ -5050,14 +5036,10 @@ func TestCtx_ParamsInt(t *testing.T) {
num, err := c.ParamsInt("user", 1111)

// Check the number matches
if num != 2222 {
t.Fatalf("Expected number 2222 from the path, got %d", num)
}
utils.AssertEqual(t, 2222, num)

// Check no errors are returned, because we want NO errors in this one
if err != nil {
t.Fatalf("Expected nil error for 2222 test, got " + err.Error())
}
utils.AssertEqual(t, nil, err)

return nil
})
Expand All @@ -5070,14 +5052,10 @@ func TestCtx_ParamsInt(t *testing.T) {
num, err := c.ParamsInt("user", 1111)

// Check the number matches
if num != 1111 {
t.Fatalf("Expected number 1111 from the path, got %d", num)
}
utils.AssertEqual(t, 1111, num)

// Check an error is returned, because we want NO errors in this one
if err != nil {
t.Fatalf("Expected nil error for 1111 test, got " + err.Error())
}
utils.AssertEqual(t, nil, err)

return nil
})
Expand Down
Loading
Loading