Skip to content
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

Refactor main_test.go and add more coverage for main.go #4837

Open
vepatel opened this issue Dec 22, 2023 · 5 comments · Fixed by #5015
Open

Refactor main_test.go and add more coverage for main.go #4837

vepatel opened this issue Dec 22, 2023 · 5 comments · Fixed by #5015
Assignees
Labels
backlog Pull requests/issues that are backlog items chore Pull requests for routine tasks

Comments

@vepatel
Copy link
Contributor

vepatel commented Dec 22, 2023

  • main_test.go requires refactoring as almost all tests are covering flags.go,
  • main.go requires more test coverage.
@vepatel vepatel added chore Pull requests for routine tasks backlog Pull requests/issues that are backlog items labels Dec 22, 2023
@mrajagopal
Copy link
Contributor

So, as a start, would it be fair to say that main_test.go should be renamed flags_test.go with those tests intended for main_test.go moved into such a file?

@mrajagopal
Copy link
Contributor

@vepatel , I have a PR open for the renaming of the file to flags_test.go.
I reviewed the coverage for flags.go:

  • There are 12 functions in flags.go while flags_test.go has 6 defined
  • parseFlags, initialChecks, validateWatchedNamespaces, validationChecks, validateResourceName don't have a test
  • validateResourceName doesn't need one as invoked by validateNamespaceNames which has a test anyway
  • validateWatchedNamespaces doesn't need one as it invokes validateWatchedNamespaces
  • What remain are parseFlags, initialChecks, validationChecks which I think don't need a test either as they are amalgamation/glue procedures and don't take an input

Let me know your thoughts.

@haywoodsh haywoodsh linked a pull request Feb 1, 2024 that will close this issue
6 tasks
@j1m-ryan
Copy link
Member

j1m-ryan commented Feb 2, 2024

Reopening because the second part is not done yet

main.go requires more test coverage

@j1m-ryan j1m-ryan reopened this Feb 2, 2024
@mrajagopal
Copy link
Contributor

mrajagopal commented Feb 6, 2024

  • There are 28 functions in main.go.
  • taking getAndValidateSecret() as an example, there is k8s fake Clientset but this does not match the input to getAndValidateSecret() which requires
    Cannot use 'kubeClient' (type *"[k8s.io/client-go/kubernetes/fake](http://k8s.io/client-go/kubernetes/fake)".Clientset) as the type *"[k8s.io/client-go/kubernetes](http://k8s.io/client-go/kubernetes)".Clientset
  • I suspect some of this boils down to my unfamiliarity with the codebase
  • Let me know your/team’s thoughts and anything that I need to understand better to complete this task
main.go Test Required Yes/No Notes
func main No  
func createConfigAndKubeClient No No return parameter
func kubernetesVersionInfo No No return parameter
func validateIngressClass No No return parameter
func checkNamespaces No No return parameter
func checkNamespaceExists No No return parameter
func createCustomClients Yes  
func createPlusClient Yes  
func createTemplateExecutors Yes  
func createNginxManager Yes There is NewFakeManager but the intent of this is is different, not what I am thinking of
func getNginxVersionInfo Yes But NewFakeManager will need to implement non-empty Version()
func getAppProtectVersionInfo No? The function reads /opt/app_protect/VERSION file
func startApAgentsAndPlugins No This requires starting an external agent unless we mock that as well
func processDefaultServerSecret Yes  
func processWildcardSecret Yes Will need to be adapted to use fake.Clientset
func createGlobalConfigurationValidator No This seems to be tested already in globalconfiguration_test.go
func processNginxConfig No No return parameter; best tested at the individual module level
func handleTermination No  
func getSocketClient No  
func getAndValidateSecret Yes Conflicts with kubernetes.Clientset vs fake.Clientset
func handleTerminationWithAppProtect No Creates a golang CHAN waiting for SIGTERM signal
func ready No This returns a function
func createManagerAndControllerCollectors No This seems like an aggregator function, but we may be better off testing these individually
func createPlusAndLatencyCollectors Unsure Quite a busy function and starts a syslog listener
func createHealthProbeEndpoint No This calls getAndValidateSecret() locally which shall have a test, also calls RunHealthCheck() as a go routine
func processGlobalConfiguration Yes  
func processConfigMaps No This seems more like glue/aggregator function
func updateSelfWithVersionInfo No This seems more like glue/aggregator function

@danielnginx
Copy link
Collaborator

@mrajagopal We're going to revisit this issue when we have the structured log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Pull requests/issues that are backlog items chore Pull requests for routine tasks
Projects
Status: Todo ☑
Development

Successfully merging a pull request may close this issue.

5 participants