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

Ignoring the error returned by the Done() method #32

Open
ablondin opened this issue Apr 18, 2024 · 0 comments
Open

Ignoring the error returned by the Done() method #32

ablondin opened this issue Apr 18, 2024 · 0 comments

Comments

@ablondin
Copy link

Hi!

A few days ago, I started using the Go linter (with Go 1.21). When running it on my Baloo tests, there were many warnings about ignoring the error returned by the Done() method.

Even when looking at the first example below:

package simple

import (
  "testing"

  "gopkg.in/h2non/baloo.v3"
)

// test stores the HTTP testing client preconfigured
var test = baloo.New("http://httpbin.org")

func TestBalooSimple(t *testing.T) {
  test.Get("/get").
    SetHeader("Foo", "Bar").
    Expect(t).
    Status(200).
    Header("Server", "apache").
    Type("json").
    JSON(map[string]string{"bar": "foo"}).
    Done() // Warning: Error return value of `(gopkg.in/h2non/baloo.v3.Expect).Done` is not checked (errcheck)
}

Is there a good way to use Baloo without having the warning? One possibility would be to write this:

package simple

import (
  "testing"

  "gopkg.in/h2non/baloo.v3"
)

// test stores the HTTP testing client preconfigured
var test = baloo.New("http://httpbin.org")

func TestBalooSimple(t *testing.T) {
  err := test.Get("/get").
    SetHeader("Foo", "Bar").
    Expect(t).
    Status(200).
    Header("Server", "apache").
    Type("json").
    JSON(map[string]string{"bar": "foo"}).
    Done()
  if err != nil {
    t.Error(err)
  }
}

But then the error is reported twice and it makes writing tests less friendly/readable.

It seems that the best way to handle this would be to remove the returned error from the Done() method signature, or to provide another method that does not return the error.

Any thought? @h2non: I am willing to write a pull request if you agree with one of my propositions or if you have another one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant