Skip to content

--assert-body-eq "" can never pass #22

Description

@korya

Problem

AssertBodyEqual short-circuits on an empty body before comparing:

if len(res.BodyBytes) == 0 {
    return fmt.Errorf("body: expected %q, missing", expContent)
}

So asserting that a body equals the empty string always fails — and the error message is self-refuting.

Reproduction

$ http-assert --assert-body-eq '' http://127.0.0.1:8791/empty    # 204, empty body
[:] HTTP/1.1 204 No Content
- body: expected "", missing
[exit=93]

Related

AssertBodyMatch has the same shape: a pattern that legitimately matches the empty string (e.g. ^$) can never pass.

Affected code

assertions.go — AssertBodyEqual, AssertBodyMatch

Suggested fix

Drop the special-case and compare directly. The "missing" guard only exists to produce a nicer message; it should not change the verdict.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions