Skip to content

Conversation

mrajagopal
Copy link
Collaborator

Proposed changes

This PR address Issue 40 - Create Unit-tests.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING guide
  • I have proven my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have ensured the README is up to date
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch on my own fork

* 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
@mrajagopal mrajagopal self-assigned this Sep 4, 2025
Copilot

This comment was marked as outdated.

mrajagopal and others added 2 commits September 4, 2025 16:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove redundant TODO.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mrajagopal mrajagopal requested a review from Copilot September 4, 2025 04:39
Copilot

This comment was marked as outdated.

mrajagopal and others added 3 commits September 4, 2025 16:42
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>
@mrajagopal mrajagopal requested a review from Copilot September 4, 2025 05:14
Copilot

This comment was marked as outdated.

Remove irrelevant comment

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mrajagopal mrajagopal requested a review from Copilot September 4, 2025 05:27
Copy link
Contributor

@Copilot Copilot AI left a 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
Copy link

Copilot AI Sep 4, 2025

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.

Suggested change
K8sCoreClientSet kubernetes.Interface
K8sCoreClientSet *kubernetes.Clientset

Copilot uses AI. Check for mistakes.

mrajagopal and others added 4 commits September 4, 2025 17:31
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
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.

1 participant