Skip to content

🐛 [Bug]: Fiber returns err: test: got empty #4053

@SamTV12345

Description

@SamTV12345

Bug Description

The problem is that I currently get test: got empty response in my go fiber tests. The tests worked reliably in v2. I don't know exactly what the problem is because they are just normal fiber.Handler methods.

How to Reproduce

Steps to reproduce the behavior:

  1. Go to https://github.com/ether/etherpad-go
  2. Check out the branch feature/fiber-v3
  3. Open the test/api/groups/groups_api_test.go
  4. Run the tests. They all error out with nil pointers for response

Expected Behavior

They should run as expected and return the expected json structure.

Fiber Version

v3.0.0

Code Snippet (optional)

func CreateGroup(store *lib.InitStore) fiber.Handler {
	return func(c fiber.Ctx) error {
		groupId := "g." + utils.RandomString(16)
		err := store.Store.SaveGroup(groupId)
		if err != nil {
			return c.Status(500).JSON(errors.InternalServerError)
		}
		return c.JSON(GroupIDResponse{
			GroupID: groupId,
		})
	}
}

Test:

func testCreateGroupSuccess(t *testing.T, tsStore testutils.TestDataStore) {
	initStore := tsStore.ToInitStore()
	groups.Init(initStore)

	req := httptest.NewRequest("POST", "/admin/api/groups", nil)
	resp, err := initStore.C.Test(req, fiber.TestConfig{Timeout: 5000})

	assert.NoError(t, err)
	assert.Equal(t, 200, resp.StatusCode)

	var response groups.GroupIDResponse
	body, _ := io.ReadAll(resp.Body)
	_ = json.Unmarshal(body, &response)

	assert.NotEmpty(t, response.GroupID)
	assert.True(t, len(response.GroupID) > 2)
	assert.Equal(t, "g.", response.GroupID[:2])
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions