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

Increase Analysers' test coverage #889

Open
arbreezy opened this issue Jan 24, 2024 · 4 comments
Open

Increase Analysers' test coverage #889

arbreezy opened this issue Jan 24, 2024 · 4 comments

Comments

@arbreezy
Copy link
Member

arbreezy commented Jan 24, 2024

K8sGPT analysers are the first step of K8sGPT analysis whereby we scan K8s clusters and identify issues with K8s resources.
To gain more confidence every analyser should come with its own unit testing of various use cases we aim to identify.

There are a few analysers that have either limited or absent unit tests. The goal of this work is to increase code coverage of K8sGPT analysers by mocking a K8s environment. e.g Statefulset analyser

Here is a non-exhaustive list but a rather good start of enhancing or adding unit testing.

  • validating webhook
  • pvc
  • replicaset
  • events
  • logs analyser
  • analyzers' wrapper functions
@AkashKumar7902
Copy link

Hey @arbreezy
I am interested in working on this project. My internship with the CNCF landscape project, keploy, has provided me with practical experience in enhancing test coverage. I would love to start understanding the codebase by solving few issues.

@Ishani217
Copy link

Hey @arbreezy

I was recently testing the statefulset.go file and running the statefulset_test.go gave me errors below:

# command-line-arguments [command-line-arguments.test]
./statefulset_test.go:38:25: undefined: StatefulSetAnalyzer
./statefulset_test.go:65:25: undefined: StatefulSetAnalyzer
./statefulset_test.go:130:25: undefined: StatefulSetAnalyzer
./statefulset_test.go:176:25: undefined: StatefulSetAnalyzer
FAIL    command-line-arguments [build failed]
FAIL

Could you please specify a procedure to run tests correctly (I mean to run the existing tests, if any)

@arbreezy
Copy link
Member Author

Heu @Ishani217 you can use the Makefile to run the tests, make test

@amitamrutiya
Copy link
Contributor

Hello everyone 👋,

I have a basic understanding of Linux, Docker, Helm, Kubernetes, Go, version control, and GitHub Actions. I participated in GSoC 2023 with CCExtractor, working on the open-source flood-mobile project. Now, I plan to join the k8sgpt project through the LFX Mentorship Program.

Issue #889 caught my attention as it aligns with my skills and offers a great opportunity to gain hands-on experience with real-world open-source codebases. I've started exploring the provided resources and reviewing the issue. I'm excited about the chance to make meaningful contributions.

Looking forward to learning from the k8sgpt community and contributing to this valuable project.

VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 3, 2024
This commit introduces comprehensive tests for the mutating webhook
analyzer defined in the `pkg/analyzer` package.

Addition of these tests increases the code coverage of the
`mutating_webhook.go` file to almost 95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 3, 2024
This commit introduces comprehensive tests for the mutating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`mutating_webhook.go` file to almost 95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 4, 2024
This commit introduces comprehensive tests for the validating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`validating_webhook.go` file to almost 95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 4, 2024
This commit introduces comprehensive tests for the validating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`validating_webhook.go` file to almost 95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 5, 2024
This commit introduces comprehensive tests for the ReplicaSet analyzer
defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`validating_webhook.go` file to  >95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 5, 2024
This commit introduces comprehensive tests for the ReplicaSet analyzer
defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `rs.go` file to
>95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 5, 2024
This commit introduces comprehensive tests for the validating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`validating_webhook.go` file to almost 95%.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 5, 2024
This commit introduces comprehensive tests for the mutating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`mutating_webhook.go` file to almost 95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 5, 2024
This commit introduces comprehensive tests for the ReplicaSet analyzer
defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `rs.go` file to
>95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 5, 2024
This commit introduces comprehensive tests for the ReplicaSet analyzer
defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `rs.go` file to
>95%.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests for the mutating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`mutating_webhook.go` file to almost 95%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests fro the PersistentVolumeClaim
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pvc.go` file to
>95%.

Also made minor modifications in the ReplicaSet test to make sure that
sure that all the expectations are met.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests for the
`PersistentVolumeClaim` analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pvc.go` file to
>95%.

I also made minor modifications to the ReplicaSet test to ensure all
expectations were met.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests for the
`PersistentVolumeClaim` analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pvc.go` file to
>95%.

I also made minor modifications to the ReplicaSet test to ensure all
expectations were met.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests for the
`PersistentVolumeClaim` analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pvc.go` file to
>95%.

I also made minor modifications to the ReplicaSet test to ensure all
expectations were met.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests for the `PodDisruptionBudget`
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pdb.go` file to
>96%.

Additionally, a potential crash in case of empty or nil PDB status
conditions has been addressed.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 6, 2024
This commit introduces comprehensive tests for the `PodDisruptionBudget`
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pdb.go` file to
>96%.

Additionally, a potential crash in case of empty or nil PDB status
conditions has been addressed.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 8, 2024
This commit introduces comprehensive tests for the mutating webhook
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the
`mutating_webhook.go` file to almost 95%.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 8, 2024
This commit introduces comprehensive tests for the `PodDisruptionBudget`
analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pdb.go` file to
>96%.

Additionally, a potential crash in case of empty or nil PDB status
conditions has been addressed.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 8, 2024
This commit introduces comprehensive tests for the
`PersistentVolumeClaim` analyzer defined in the `pkg/analyzer` package.

Adding these tests increases the code coverage of the `pvc.go` file to
>95%.

I also made minor modifications to the ReplicaSet test to ensure all
expectations were met.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 14, 2024
* Added new tests for the `Service` analyzer defined in the
  `pkg/analyzer` package.

* The addition of these new tests has increased the code coverage of the
  service.go file to over 97%.

* Additionally addressed some flaky tests related to the `ReplicaSet`and
  `PersisentVolumeClaim` analyzers.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 14, 2024
* Added new tests for the `Node` analyzer defined in the `pkg/analyzer`
  package.

* The addition of these new tests has increased the code coverage of the
  node.go file to over 96%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 14, 2024
- Added a network policy allowing traffic to all pods. Resulting in
  additional failures in the results.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 14, 2024
With the addition of the latest changes, the missing test case when an
event happened after the currently set latest event has been covered.

Partially Addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 14, 2024
With the addition of the latest changes, the missing test case when an
event happens after the currently set latest event has been covered.

Partially Addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones added a commit that referenced this issue Mar 15, 2024
- Added a network policy allowing traffic to all pods. Resulting in
  additional failures in the results.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 16, 2024
- Fixed a small bug where pre-analysis was incorrectly appended to the
  results every time at the end of the for loop. This caused the result
  for a single cronjob failure to be appended multiple times in the
  final results.

- Added missing test cases to ensure proper testing of the CronJob
  analyzer. The addition of these missing test cases has increased the
  code coverage of this analyzer to over 96%.

Partially Addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 16, 2024
With the addition of the latest changes, the missing test case when an
event happens after the currently set latest event has been covered.

Partially Addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 16, 2024
* Added new tests for `LogAnalyzer` defined in the `pkg/analyzer`
  package. Increased the code coverage of the `log.go` file to >90%

* Added `fake logs` string to the `errorPattern` to enable the discovery
  of error logs during the tests.

TODO: Find a method to edit logs of the containers defined in the
Kubernetes client config.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 17, 2024
- Added missing test cases to ensure proper testing of the Ingress
  analyzer. The addition of these missing test cases has increased the
  code coverage of this analyzer to over 97%.

Partially Addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 17, 2024
- Fixed a small bug where failures were being appended multiple times
  for CrashLoopBackOff and ContainerCreating container status reasons.

- Added missing test cases to ensure proper testing of the Pod analyzer.
  The addition of these missing test cases has increased the code
  coverage of this analyzer to 92%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones added a commit that referenced this issue Mar 20, 2024
* Added new tests for the `Node` analyzer defined in the `pkg/analyzer`
  package.

* The addition of these new tests has increased the code coverage of the
  node.go file to over 96%.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
AlexsJones added a commit that referenced this issue Mar 21, 2024
- Added missing test cases to ensure proper testing of the Ingress
  analyzer. The addition of these missing test cases has increased the
  code coverage of this analyzer to over 97%.

Partially Addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
AlexsJones added a commit that referenced this issue Mar 21, 2024
With the addition of the latest changes, the missing test case when an
event happens after the currently set latest event has been covered.

Partially Addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 21, 2024
- Fixed a small bug where pre-analysis was incorrectly appended to the
  results every time at the end of the for loop. This caused the result
  for a single cronjob failure to be appended multiple times in the
  final results.

- Added missing test cases to ensure proper testing of the CronJob
  analyzer. The addition of these missing test cases has increased the
  code coverage of this analyzer to over 96%.

Partially Addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Mar 21, 2024
* test: added missing tests for the CronJob analyzer

- Fixed a small bug where pre-analysis was incorrectly appended to the
  results every time at the end of the for loop. This caused the result
  for a single cronjob failure to be appended multiple times in the
  final results.

- Added missing test cases to ensure proper testing of the CronJob
  analyzer. The addition of these missing test cases has increased the
  code coverage of this analyzer to over 96%.

Partially Addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>

* test: removed failure strings matching from tests

It is possible that the error or failure strings might change in the
future, causing the tests to fail. This commit addresses that issue by
removing the matching of failure text from various analyzer tests.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>

---------

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 22, 2024
* Added new tests for `LogAnalyzer` defined in the `pkg/analyzer`
  package. Increased the code coverage of the `log.go` file to >90%

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 23, 2024
- Fixed a small bug where failures were being appended multiple times
  for CrashLoopBackOff and ContainerCreating container status reasons.

- Added missing test cases to ensure proper testing of the Pod analyzer.
  The addition of these missing test cases has increased the code
  coverage of this analyzer to 92%.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Mar 24, 2024
- Fixed a small bug where failures were being appended multiple times
  for CrashLoopBackOff and ContainerCreating container status reasons.

- Added missing test cases to ensure proper testing of the Pod analyzer.
  The addition of these missing test cases has increased the code
  coverage of this analyzer to 98%.

- Added checks for init containers in a pod.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Apr 13, 2024
* Added new tests for `LogAnalyzer` defined in the `pkg/analyzer`
  package. Increased the code coverage of the `log.go` file to >90%

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Apr 13, 2024
- Fixed a small bug where failures were being appended multiple times
  for CrashLoopBackOff and ContainerCreating container status reasons.

- Added missing test cases to ensure proper testing of the Pod analyzer.
  The addition of these missing test cases has increased the code
  coverage of this analyzer to 98%.

- Added checks for init containers in a pod.

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue Apr 13, 2024
- Fixed a small bug where failures were being appended multiple times
  for CrashLoopBackOff and ContainerCreating container status reasons.

- Added missing test cases to ensure proper testing of the Pod analyzer.
  The addition of these missing test cases has increased the code
  coverage of this analyzer to 98%.

- Added checks for init containers in a pod.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue Apr 20, 2024
* Added new tests for `LogAnalyzer` defined in the `pkg/analyzer`
  package. Increased the code coverage of the `log.go` file to >90%

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
VaibhavMalik4187 added a commit to VaibhavMalik4187/k8sgpt that referenced this issue May 8, 2024
* Added new tests for `LogAnalyzer` defined in the `pkg/analyzer`
  package. Increased the code coverage of the `log.go` file to >90%

Partially addresses: k8sgpt-ai#889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
AlexsJones pushed a commit that referenced this issue May 9, 2024
* Added new tests for `LogAnalyzer` defined in the `pkg/analyzer`
  package. Increased the code coverage of the `log.go` file to >90%

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Proposed
Development

No branches or pull requests

4 participants