-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide error when no config was found #323
Provide error when no config was found #323
Conversation
28a57b8
to
f39b7d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a couple of unit tests to https://github.com/k8snetworkplumbingwg/whereabouts/blob/master/pkg/config/config_test.go ?
Let me know if you need any help with it.
Sure, if I can bother you to look at #226 😉 (unrelated to this issue, but I think it deserves some attention too) |
Well I tried to, but then I discovered that a lot (maybe all) tests in Do you have a hint for me? |
ping @maiqueb |
Yeah, so now that you return an error when there's no config present (I agree this should happen), the tests should be re-written to ensure this configuration is available to the tests. Let's make sure @dougbtv is on board with the conceptual change first if you don't mind. I can guide you on adapting the tests later on. Stay tuned. |
FWIW, the changes you need to do in the tests are quite small. Here's what you need to do (using as reference the first test, you need to do something similar for all the failing ones): var tmpDir string // this must be accessible from the tests
BeforeEach(func() {
var err error
tmpDir, err = os.MkdirTemp("", "whereabouts") // must create a tmp dir to store the configs
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
Expect(os.RemoveAll(tmpDir)).To(Succeed()) // must clean-up the generated configs
})
It("can load a basic config", func() {
conf := `...` // each test will have a different conf; leave the original configuration you have in each test
confPath := fmt.Sprintf("%s/%s", tmpDir, "whereabouts.conf")
Expect(os.WriteFile(confPath, []byte(conf), 0755)).To(Succeed()) // must persist the conf in the file-system
ipamconfig, _, err := LoadIPAMConfig([]byte(conf), "", confPath) // must pass the new conf-path to the func; it only knows about the default paths
Expect(err).NotTo(HaveOccurred())
... // further expectations, each test looks for different stuff
}) |
Hi, sounds allright, I will look into that in a week or so. |
f39b7d9
to
91907d6
Compare
I've updated my PR with a commit that fixes those tests. All is green on my side. I am recycling the filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have two minor comments. Other than that, looks good.
The control loop currently segfaults when none of the config files was found. This commit makes it error, providing the user with useful feedback. Also, L260 returned a `nil` disguised as a var named `err`, which could be done more explicit. Signed-off-by: Jorik Jonker <jorik.jonker@eu.equinix.com>
91907d6
to
d498b17
Compare
You have plenty of failed unit tests in You need to take care of them. |
You are right, I need to fix the unit tests on way more places than I did. I only tested |
d498b17
to
d802ba7
Compare
OK, we are almost there. There are still 5 unit tests failing in I think simply ignoring Also: I feel a bit awkward about both passing |
It is required per my previous commit, which seemed to break a couple of tests. Signed-off-by: Jorik Jonker <jorik.jonker@eu.equinix.com>
d802ba7
to
55b24e2
Compare
Yeah, that was the previous behavior. ... but IMO, the goal of this PR is to get rid of the previous behavior and ensure an error is thrown when a config is not provided. This must be reflected in the unit tests. IMO, you cannot just ignore the error; you should either do a proper setup of the tests, or mock the real component, providing an implementation that does what you want. Maybe the later is simpler.
The whole API could be improved to be honest ... If you choose to pursue that, please do it in a separate PR. |
I did something else: I EDIT: they pass locally. I'm working on getting them to pass in GH actions |
All is OK, all tests pass now config files are created. I'll save refactoring for DRY for another rainy day ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this change, and your willingness to jump through all the hurdles I kept setting for you.
you're welcome! |
Pull Request Test Coverage Report for Build 4871473391Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
What this PR does / why we need it:
The control loop currently segfaults when none of the config files was found. This commit makes it give an actual error, providing the user with useful feedback.
Which issue(s) this PR fixes
If needed, I'll raise an issue, please let me know.
Special notes for your reviewer (optional):