corbym / gocrest

GoCrest - Hamcrest-like matchers for Go
BSD 3-Clause "New" or "Revised" License
105 stars 7 forks source link

Matchers: has.ElementsWith and has.StructWithValues #1

Closed jpolack closed 3 years ago

jpolack commented 3 years ago

I implemented two new matchers:

has.ElementsWith: Checks wether each element of an array/slice matches all expectations has.StructWithValues: Allows to check single struct fields

Can be combined in a way that now we can check if f.e.:

[
  {
    "id": "someId1",
    "someOmittedField": true
  },
  {
    "id": "someId2",
    "someOmittedField": false
  }
]

has structs that have an id field with the prefix someId

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.4%) to 99.58% when pulling 18016b79f860c0137a247915deca112fa9a1004f on jpolack:master into 56a1405d0a13b15f43bbc7f9b4fc93733475c42d on corbym:master.

jpolack commented 3 years ago

Thanks for your Feedback!

I am wondering why coveralls does not track that last line. I checked it locally and this test case should cover the missing line: https://github.com/corbym/gocrest/pull/1/files#diff-1a13e117c42f75f290b07b9587f7401c2f91a32980298f6e0bc547de98865e51R817 🤔

Is there a possiblity to call coveralls locally? go test ./... -cover just gives me the coverage for the gocrest package but not the subpackages.

jpolack commented 3 years ago

One thing I want to get mentioned: With these matchers one can write quite complex assertions. And the way we currently describe the errors might be too long, because atm we would print all assertions, even the ones that succeded. A future improvement could be to change that and just print the assertions that failed (maybe with a property path) and the actual value (maybe as a stack)

corbym commented 3 years ago

Thanks for your Feedback!

I am wondering why coveralls does not track that last line. I checked it locally and this test case should cover the missing line: https://github.com/corbym/gocrest/pull/1/files#diff-1a13e117c42f75f290b07b9587f7401c2f91a32980298f6e0bc547de98865e51R817 🤔

Is there a possiblity to call coveralls locally? go test ./... -cover just gives me the coverage for the gocrest package but not the subpackages.

I think coveralls is having a bit of a paddy. I will merge your code and then check out what is happening from there.

corbym commented 3 years ago

One thing I want to get mentioned: With these matchers one can write quite complex assertions. And the way we currently describe the errors might be too long, because atm we would print all assertions, even the ones that succeded. A future improvement could be to change that and just print the assertions that failed (maybe with a property path) and the actual value (maybe as a stack)

I have opened an issue for this. It will be esp. useful when allOf and anyOf or the variadic parametered matchers are called.

corbym commented 3 years ago

Thanks for your Feedback!

I am wondering why coveralls does not track that last line. I checked it locally and this test case should cover the missing line: https://github.com/corbym/gocrest/pull/1/files#diff-1a13e117c42f75f290b07b9587f7401c2f91a32980298f6e0bc547de98865e51R817 🤔

Is there a possiblity to call coveralls locally? go test ./... -cover just gives me the coverage for the gocrest package but not the subpackages.

I found the reason for this: the test was assigning the actual string to an interface{} type and that was Panicking in the for loop rather than the default method.

This has been fixed.