Add unit test coverage for service principal validation (dynamic validator and operator)
m1kola opened this issue · comments
We can solve the following todo items:
by mocking aad.GetToken
in a similar we mock time.Now()
from go standard library.
Example code:
ARO-RP/pkg/util/clientauthorizer/arm_test.go
Line 124 in 57e4bf0
Example test:
ARO-RP/pkg/util/clientauthorizer/arm.go
Line 55 in 57e4bf0
Hi @m1kola
I have experience with Golang, but not much in writing Unit tests.
This issue might be a good starting point for me.
I would like to take it up.
Could you assist me with it?
@kitarp29 unfortunately I'm not sure whether I can provide enough assistance in learning unit testing to external contributors at the moment.
But I'll try to give you some pointers. I recommend checking out this tutorial on unit testing from Go website (it is a part of a bigger tutorial). Also take a look at documentation for testing
package from standard library. Apart from very good overview of the testing
package it also has some examples. Another commonly used package for unit testing is gomock. We use it in our codebase for generating mocks from interfaces and a lot of other go projects use this package.
Apart from go specific things it might be a good idea to look something up on different types of tests. And find an answer to the question "what is a good unit tests?". Unit tests are often unintentionally turned into tests which test multiple units. Think about the reasons why it is not good.
Once you are more comfortable with the basics - take a look at the real world examples (in our codebase, in upstream Kubernetes or in some other go project) and try to write more complex tests yourself.
Hello @kitarp29, as complementary material to the good resources that @m1kola has suggested, I think that Learn Go with tests could help you as it covers the basics of unit testing in Go. Cheers!
Issue resolved in PR #2488