Skip to content

Comments

add unit tests and minor fixes for resolveCollectorRefs()#220

Merged
burningalchemist merged 2 commits intoburningalchemist:masterfrom
hhromic:fix-rescollrefs
Apr 16, 2023
Merged

add unit tests and minor fixes for resolveCollectorRefs()#220
burningalchemist merged 2 commits intoburningalchemist:masterfrom
hhromic:fix-rescollrefs

Conversation

@hhromic
Copy link
Contributor

@hhromic hhromic commented Apr 15, 2023

After my shameful programming errors in PR #194, some of them reported in #210 and fixed in #208, I decided to shield the codebase a bit against this type of mistakes by adding unit tests for the resolveCollectorRefs() function. In particular:

  • NoGlobbing test: checks that non-globbed collector references are correctly resolved.
  • Globbing test: checks that globbed collector references are correctly resolved.
  • NoCollectorRefs test: checks that resolveCollectorRefs() resolves to empty when no collector references are given.
  • UnknownCollector test: checks that resolveCollectorRefs() errors correctly when a collector reference is invalid.

All of the above tests (with the exception of Globbing) pass with the implementation in 0.9.3 (before globbing support).

Only the NoCollectorRefs test passes with the implementation in 0.10.0 (after globbing support => apologies again!).

The NoCollectorRefs and UnknownCollector tests do not pass with the implementation in master (after the fix in #208). The NoGlobbing test passes/fails in a non-deterministic manner because resolveCollectorRefs() no longer returns the resolved collectors in the same order as in 0.9.3. Note that order does not really matter, but still wanted to stay correct.

All of the above is now also fixed in a second commit in this PR, bringing resolveCollectorRefs() to its previous behaviour when not using globbing patterns in collector references:

  • return non-globbed resolved collectors in the order they are found
  • do not error when no collectors are resolved

The Makefile and the GitHub build.yml workflow in the project already have testing support, so all of this will be automatically executed in future PRs/commits. For example:

Local machine:

$ make test
>> running tests
?       github.com/burningalchemist/sql_exporter        [no test files]
?       github.com/burningalchemist/sql_exporter/cmd/sql_exporter       [no test files]
?       github.com/burningalchemist/sql_exporter/errors [no test files]
ok      github.com/burningalchemist/sql_exporter/config 0.036s

GitHub workflow:
image

I hope this helps to avoid these silly mistakes in future contributions :)

--

fixes #210

hhromic added 2 commits April 16, 2023 00:40
* return non-globbed resolved collectors in the order they are found
* do not error when no collectors are resolved
@burningalchemist
Copy link
Owner

Hey @hhromic, thanks heaps for the fix and introducing tests - this is a memorable event! 🚀

I plan to refactor the code, but before that a good test coverage is a must. So you definitely improved my motivation. 😃

Thanks again and no worries about the issue. 🙂👍

@burningalchemist burningalchemist merged commit 2c79621 into burningalchemist:master Apr 16, 2023
@hhromic hhromic deleted the fix-rescollrefs branch April 16, 2023 15:31
@hhromic
Copy link
Contributor Author

hhromic commented Apr 17, 2023

I plan to refactor the code, but before that a good test coverage is a must. So you definitely improved my motivation. 😃

I fully understand what it is to be unmotivated, so I'm glad you feel more motivated!
As I mentioned in the test suite source, I think a nice improvement for the codebase is to implement typed errors consistently. Recent versions of Go have very nice support for wrapped errors too. Maybe I can find some time to help you with that if you want to go into this direction.

Thanks again and no worries about the issue. 🙂👍

Happy to help. I still have pending to implement configuration via env variables :) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.10.0 seems to have broken the configuration

2 participants