Bug fixes, Go 1.23 and dependency upgrade, lint - #54
Merged
Conversation
…scalar Len, GreaterThan and LessThan called reflect.Value.Len on whatever the expression returned, which panics for numbers and booleans and so aborts the test (and any sequence diagram report) rather than failing it. They now return an error for values that have no length. The failure messages for GreaterThan and LessThan were also the wrong way round. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contains, Equal, NotEqual and the JWT assertions formatted non-string values with %s, producing messages such as '%!s(float64=1)'. The JWT error for a malformed token also referred to a 'secret' rather than the signature. Underlying errors are now wrapped with %w. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Matches discarded the error from evaluating the expression, so an unparsable body, an invalid expression and a missing key were all reported as 'no match for pattern'. The error is now returned, in line with the other assertions; 'no match for pattern' is kept for a JSON null. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Root always inserted a dot between the root and each sub-expression,
so Root("$.items").Equal("[0].id", 1) evaluated "$.items.[0].id",
which the jsonpath parser rejects. The dot is now only inserted when
the sub-expression does not start with one or with a bracket, and a
trailing dot on the root is tolerated.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
CopyRequest dereferenced a nil request while CopyResponse handled nil, and CopyResponse shared its header value slices with the original. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The workflow ran on Go 1.13 and 1.14 with actions that are no longer maintained. It now tests on 1.23 and stable across Linux, macOS and Windows with the race detector, and runs golangci-lint with the same configuration as apitest. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…er int Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
apitest.New takes a name, not a handler; the examples now use apitest.Handler. The badge points at the workflow file, the mocks package (jsonpath matchers for mock request bodies) is documented, and the Root section shows bracketed sub-expressions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Maintenance pass over the library: bug fixes with regression tests, one deliberate behaviour change, three new chain methods, a Go and dependency upgrade, and modernisation. Commits are one change each.
Behaviour change
Presentnow passes (andNotPresentfails) for fields holdingfalse,0or"". Any zero value used to be treated as absent, contradicting the documented behaviour of checking presence without evaluating the value.null, empty arrays and empty objects are still absent, and the README now spells this out.New
Len,GreaterThanandLessThanon the assertion chain, so they can be used underChainandRoot.Bug fixes
Len,GreaterThanandLessThanpanicked (viareflect.Value.Len) when the expression returned a number or boolean, which aborts the test rather than failing it. They now return an error. Their failure messages were also inverted.Contains,Equal,NotEqualand the JWT assertions formatted non-string values with%s, producing%!s(float64=1)in messages. Errors are now wrapped with%w.Matchesdiscarded the error from evaluating the expression, so invalid JSON, an invalid expression and a missing key were all reported as "no match for pattern". The error is now returned, as the other assertions do. One existing test's expected message changed accordingly.Root("$.items").Equal("[0].id", 1)evaluated$.items.[0].id, which the parser rejects. A dot is now only inserted when the sub-expression does not start with a bracket or dot.http.CopyRequest(nil)panicked andCopyResponseshared header slices with the original.Upgrade
go 1.13→go 1.23; apitest v1.5.10 → v1.6.1; testify v1.7.0 → v1.12.1.-race, plus a golangci-lint job using the same config as apitest.io/ioutil→io,interface{}→any, lint clean.Tests and docs
jsonpathandhttppackages, which had none.apitest.New(handler)examples did not compile (Newtakes a name); themockspackage was undocumented.Supersedes the dependency and
io/anyparts of #53.🤖 Generated with Claude Code