nicklaw5 / helix

A Twitch Helix API client written in Go.
MIT License
240 stars 91 forks source link

Fix query builder adding all struct fields as parameters #176

Closed pajlada closed 1 year ago

pajlada commented 1 year ago

To test, print the request being made in something like the "BanUser" request, it will show this: https://api.twitch.tv/helix/moderation/bans?=%7B60++22484632%7D&=117166826&=117166826

This is because the buildQueryString builder doesn't care if the query tag exists, it'll add values with an empty key.

The test run before the fix commit:

$ go test -v -p 1 -run 'Query'
=== RUN   TestQueryStringBuilderAllQuery
=== PAUSE TestQueryStringBuilderAllQuery
=== RUN   TestQueryStringBuilderPartialQuery
=== PAUSE TestQueryStringBuilderPartialQuery
=== RUN   TestQueryStringBuilderNoQuery
=== PAUSE TestQueryStringBuilderNoQuery
=== CONT  TestQueryStringBuilderAllQuery
=== CONT  TestQueryStringBuilderNoQuery
--- PASS: TestQueryStringBuilderAllQuery (0.00s)
=== NAME  TestQueryStringBuilderNoQuery
    helix_test.go:732: expected q to be "", got "=value&=value"
--- FAIL: TestQueryStringBuilderNoQuery (0.00s)
=== CONT  TestQueryStringBuilderPartialQuery
    helix_test.go:707: expected q to be "foo=value", got "=value&foo=value"
--- FAIL: TestQueryStringBuilderPartialQuery (0.00s)
FAIL
exit status 1
FAIL    github.com/nicklaw5/helix/v2    0.003s

The lack of coverage has to do with previously-parsed-as-query-params-code that is now correctly only serialized into the json body during tests.

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 4096371677


Files with Coverage Reduction New Missed Lines %
extension_pubsub.go 3 85.71%
helix.go 22 89.77%
<!-- Total: 25 -->
Totals Coverage Status
Change from base Build 4093193027: -0.2%
Covered Lines: 1457
Relevant Lines: 1567

💛 - Coveralls