Skip to content

Improve error checks in tests #130

Open
@dbanck

Description

@dbanck

Go 1.19 discovered a minor flaw in our tests in #129: second argument to errors.As should not be *error

Changing the type of expectedErr in our test table to interface{} silenced that error for now but defeated the purpose of testing if the function throws the correct error. So currently, any error (or even any non nil value) will make the test pass.

Proposal

There are a couple of different solutions to solve this:

  1. compare string representations, i.e. given.Error() == expected.Error()
  2. use reflection
  3. avoid table tests altogether
  4. include a pointer to a function which takes an error and returns a boolean

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions