-
Notifications
You must be signed in to change notification settings - Fork 2
Implement unit-tests for the codebase #192
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
base: main
Are you sure you want to change the base?
Conversation
* This is a exploratory exercise on writing unit-test for data_collector.go and nic_job_list.go * The nic_job_list_test.go works but data_collector_test.go does not * The tests themselves are basic to establish a familiarity in writing tests
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove redundant TODO. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove redundant comment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removed custom fake types; use fake.NewSimpleClientset instead Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove redundant mock-logger code. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove irrelevant comment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Pull Request Overview
Implements comprehensive unit tests for the nginx-supportpkg-for-k8s codebase, covering job execution, data collection, and CRD functionality.
- Unit tests for all job lists (NIM, NIC, NGX, NGF, Common)
- Data collector functionality and client initialization tests
- CRD package validation tests
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pkg/data_collector/data_collector.go | Refactors client interface type and method accessibility for testability |
pkg/data_collector/data_collector_test.go | Tests DataCollector initialization, tarball creation, and namespace validation |
pkg/jobs/common_job_list.go | Updates deprecated API calls to use Discovery() method |
pkg/jobs/common_job_list_test.go | Tests common Kubernetes resource collection jobs |
pkg/jobs/job_test.go | Tests core job execution patterns and edge cases |
pkg/jobs/nic_job_list_test.go | Tests NGINX Ingress Controller specific job execution |
pkg/jobs/ngf_job_list_test.go | Tests NGINX Gateway Fabric job functionality |
pkg/jobs/ngx_job_list_test.go | Tests NGINX specific job execution |
pkg/jobs/nim_job_list_test.go | Tests NGINX Instance Manager job execution with exclude flags |
pkg/crds/crd_test.go | Validates CRD list structure and content |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
LogFile *os.File | ||
K8sRestConfig *rest.Config | ||
K8sCoreClientSet *kubernetes.Clientset | ||
K8sCoreClientSet kubernetes.Interface |
Copilot
AI
Sep 4, 2025
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.
The change from concrete type *kubernetes.Clientset
to interface kubernetes.Interface
is good for testability. However, ensure this change doesn't break existing code that might rely on concrete type methods not available in the interface.
K8sCoreClientSet kubernetes.Interface | |
K8sCoreClientSet *kubernetes.Clientset |
Copilot uses AI. Check for mistakes.
Taking the address of a slice element from a function call creates a pointer to a temporary value. Store the slice in a variable first, then take the address: jobs := CommonJobList(); podListJob = &jobs[i] Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Introduce a mock form helm, metrics clients
* Also update go.mod and go.sum
Proposed changes
This PR address Issue 40 - Create Unit-tests.
Checklist
Before creating a PR, run through this checklist and mark each as complete.