baloo icon indicating copy to clipboard operation
baloo copied to clipboard

Ignoring the error returned by the Done() method

Open ablondin opened this issue 1 year ago • 0 comments

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.

ablondin avatar Apr 18 '24 16:04 ablondin