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: Eliminate Global Variable to Enhance Testability #4685

Open
wants to merge 107 commits into
base: master
Choose a base branch
from

Conversation

andoriyaprashant
Copy link
Contributor

Fixes #4217

Proposed changes

This pull request refactors the codebase by removing a global variable to improve testability.

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

@andoriyaprashant
Copy link
Contributor Author

Hello @namkyu1999 Please review my pull request

@namkyu1999
Copy link
Member

can you check DCO?

@andoriyaprashant
Copy link
Contributor Author

@namkyu1999 Sir, as you instructed, I've tried to complete the checks. Could you please verify them? If there are any changes needed in the code, please let me know, and I'll try to fix them

@namkyu1999
Copy link
Member

Hi @andoriyaprashant, some checks are failing now (build-pipeline, CIFuzz). can you check them?

@andoriyaprashant
Copy link
Contributor Author

Hi @andoriyaprashant, some checks are failing now (build-pipeline, CIFuzz). can you check them?

i am working on those 👍🏻

@@ -32,8 +32,8 @@ type MongoOperations struct {
}

var (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this var block itself as well.

@@ -10,20 +10,20 @@ import (
)

// CreateConfig creates a new server config with unique key
func CreateConfig(ctx context.Context, config *ServerConfig) error {
err := mongodb.Operator.Create(ctx, mongodb.ServerConfigCollection, config)
func CreateConfig(ctx context.Context, config *ServerConfig, mongodbOperator mongodb.MongoOperator) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to create an interface and receivers here similar to what we have in other places?

@andoriyaprashant
Copy link
Contributor Author

Hello @Saranya-jena @Jonsy13 @namkyu1999
I made some changes to the files as @Jonsy13 suggested removing the var() block, so I removed it completely. Also, as per @Saranya-jena suggestion, I made some changes to the config file. Please review them, and if there are any errors or further changes needed, please let me know. I'll do my best to fix them.
Thank you

@Saranya-jena
Copy link
Contributor

The checks are failing can you fix those?

@Saranya-jena
Copy link
Contributor

@andoriyaprashant are you still working on this PR?

@andoriyaprashant
Copy link
Contributor Author

@andoriyaprashant are you still working on this PR?

Sorry @Saranya-jena I forgot to check the pull request checks. I'll fix them as soon as possible 👍🏻

@Saranya-jena
Copy link
Contributor

@andoriyaprashant the checks are still failing, PTAL.

@andoriyaprashant
Copy link
Contributor Author

@andoriyaprashant the checks are still failing, PTAL.

Ma'am @Saranya-jena , can you please help me or guide me in fixing the CIFuzz workflow error? I tried, but I am not able to understand it

dependabot bot and others added 10 commits September 7, 2024 14:16
updated-dependencies:
- dependency-name: github.com/99designs/gqlgen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: andoriyaprashant <[email protected]>
Bumps [github.com/vektah/gqlparser/v2](https://github.com/vektah/gqlparser) from 2.5.11 to 2.5.12.
- [Release notes](https://github.com/vektah/gqlparser/releases)
- [Commits](vektah/gqlparser@v2.5.11...v2.5.12)

---
updated-dependencies:
- dependency-name: github.com/vektah/gqlparser/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: Shubham Chaudhary <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
* upgrade go version in all the modules

Signed-off-by: Saranya-jena <[email protected]>

* upgrade go version in dockerfiles

Signed-off-by: Saranya-jena <[email protected]>

* upgrade go version in github actions

Signed-off-by: Saranya-jena <[email protected]>

* updated go sum

Signed-off-by: Saranya-jena <[email protected]>

* updated subscriber dockerfile

Signed-off-by: Saranya-jena <[email protected]>

---------

Signed-off-by: Saranya-jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
* Added env support to enable/disable gql introspection

Signed-off-by: Saranya-jena <[email protected]>

* resolved comments

Signed-off-by: Saranya-jena <[email protected]>

* fixed imports

Signed-off-by: Saranya-jena <[email protected]>

* fixed build issues

Signed-off-by: Saranya-jena <[email protected]>

---------

Signed-off-by: Saranya-jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Saranya-jena and others added 26 commits September 7, 2024 14:16
Signed-off-by: Saranya-jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: Jongwoo Han <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: Jongwoo Han <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
…os#4666)

* fix: Invalid version details in backend.

Signed-off-by: JanhaviAlekar <[email protected]>

* Checking CIVersion at start

Signed-off-by: JanhaviAlekar <[email protected]>

---------

Signed-off-by: JanhaviAlekar <[email protected]>
Co-authored-by: Vedant Shrotria <[email protected]>
Co-authored-by: Amit Kumar Das <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Bumps [github.com/99designs/gqlgen](https://github.com/99designs/gqlgen) from 0.17.47 to 0.17.49.
- [Release notes](https://github.com/99designs/gqlgen/releases)
- [Changelog](https://github.com/99designs/gqlgen/blob/master/CHANGELOG.md)
- [Commits](99designs/gqlgen@v0.17.47...v0.17.49)

---
updated-dependencies:
- dependency-name: github.com/99designs/gqlgen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: andoriyaprashant <[email protected]>
…uschaos#4692)

Signed-off-by: andoriyaprashant <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
…haos#4762)

Signed-off-by: Denish Tomar <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: JanhaviAlekar <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Co-authored-by: Sahil <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
…itmuschaos#4813)

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.25.0 to 0.26.0.
- [Commits](golang/crypto@v0.25.0...v0.26.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: andoriyaprashant <[email protected]>
Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.15.0 to 1.16.1.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](mongodb/mongo-go-driver@v1.15.0...v1.16.1)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: Suyeon Jung <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.15.1 to 1.16.1.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](mongodb/mongo-go-driver@v1.15.1...v1.16.1)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: hursit <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: JanhaviAlekar <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: JanhaviAlekar <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
…os#4779)

* Adding environment filter in Infrastructure selection modal

Signed-off-by: JanhaviAlekar <[email protected]>

* setting initialAllInfrastructureLength as 0 initially

Signed-off-by: JanhaviAlekar <[email protected]>

* making InitialAllInfrastructureLength consistent

Signed-off-by: JanhaviAlekar <[email protected]>

* Scroll env list and Pagination(infra)

Signed-off-by: JanhaviAlekar <[email protected]>

* added preSelectedEnvironmentID

Signed-off-by: JanhaviAlekar <[email protected]>

* Minor changes in code

Signed-off-by: JanhaviAlekar <[email protected]>

* Refactored code

Signed-off-by: JanhaviAlekar <[email protected]>

* Changing height of infralist section

Signed-off-by: JanhaviAlekar <[email protected]>

* Minor improvements

Signed-off-by: JanhaviAlekar <[email protected]>

---------

Signed-off-by: JanhaviAlekar <[email protected]>
Co-authored-by: Sahil <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: 잉퓨 <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Co-authored-by: Vedant Shrotria <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Bumps [github.com/tidwall/gjson](https://github.com/tidwall/gjson) from 1.17.1 to 1.17.3.
- [Commits](tidwall/gjson@v1.17.1...v1.17.3)

---
updated-dependencies:
- dependency-name: github.com/tidwall/gjson
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
* test: add fuzz test to GetChartsPath function in handler

Signed-off-by: Soyeon Park <[email protected]>

* test: add fuzz test to FuzzReadExperimentFile function in handler

* Removed the ./types.go example in unit test handler_test.go/TestReadExperimentFile because it returns a file does not exist error, not the file is not a yaml error that the test is intended to return.

Signed-off-by: Soyeon Park <[email protected]>

* * test: Add the FuzzReadExperimentYAMLFile test in the handler_fuzz_test.go file

Signed-off-by: Soyeon Park <[email protected]>

* test: add fuzz test to FuzzIsFileExisting function in handler

Signed-off-by: Soyeon Park <[email protected]>

* test: add fuzz test to FuzzGetExperimentData, FuzzUnzipRemoteHub function in handler

Signed-off-by: Soyeon Park <[email protected]>

* refactor: remove unused imported library

Signed-off-by: Soyeon Park <[email protected]>

* fix: check yaml: control characters are not allowed

Signed-off-by: Soyeon Park <[email protected]>

* refactor: save goimport order

Signed-off-by: Soyeon Park <[email protected]>

---------

Signed-off-by: Soyeon Park <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
* add handler_fuzz_test file

Signed-off-by: weeeeestern <[email protected]>

* add service_fuzz_test file

Signed-off-by: weeeeestern <[email protected]>

* test: add fuzz test

Signed-off-by: weeeeestern <[email protected]>

* test: add fuzz_test

Signed-off-by: weeeeestern <[email protected]>

* test: modify fuzz-test

Signed-off-by: weeeeestern <[email protected]>

* test: modify fuzz-test

Signed-off-by: weeeeestern <[email protected]>

---------

Signed-off-by: weeeeestern <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
…only a single namespace (litmuschaos#4680)

* Create a seperate function to get Namespace in subscriber

Signed-off-by: Calvin Audier <[email protected]>

* Update graphql server to include KubeNamespace call (model not generated)

Signed-off-by: Calvin Audier <[email protected]>

* Update graphqls to include KubeNamespace model
Update objectmodel and subscriber to incldue KubeNamespace

Signed-off-by: Calvin Audier <[email protected]>

* Fix issue in graphqls and adding KubeNamespace type.
Regenerating model with gqlgen.

Signed-off-by: Calvin Audier <[email protected]>

* Update model to includude missing field in KubeNamespaceData
Rename getKubeNamespace function that didn't match graphqls operation in Subscription
Add missing function for the graphql server to retrieve list of namespace

Signed-off-by: Calvin Audier <[email protected]>

* Add remaining function in k8s pkg and requests to return list of namespace

Signed-off-by: Calvin Audier <[email protected]>

* Update graphql/subscriber to transform KubeObject to not be a array since subscriber will only return one element.

Signed-off-by: Calvin Audier <[email protected]>

* Update web server to seperate call for KubeObject and KubeNamespace.

Signed-off-by: Calvin Audier <[email protected]>

* Fix import with goimports

Signed-off-by: Calvin Audier <[email protected]>

* Reverting upgrade of  webpack-dev-server so it's compatible with github workflow

Signed-off-by: Calvin Audier <[email protected]>

* Run gofmt with correct version.

Signed-off-by: Calvin Audier <[email protected]>

* Bumping ubi-minimal:8.8 to 8.10 to fix some HIGH CVE severity detected by trivy.

Signed-off-by: Calvin Audier <[email protected]>

* Updating chaos_infrastructure mock to include KubeNamespace.
Fix a comment

Signed-off-by: Calvin Audier <[email protected]>

* Fix issue from Codacy
Removing some unused code

Signed-off-by: Calvin Audier <[email protected]>

* Fix codacy issue:
- Add some trailing comma
- Trying transform subscription function to resolve "non-arrow functions are forbidden"
- Add null check

Signed-off-by: Calvin Audier <[email protected]>

* Continue fix Codacy issue
- Adding trailing comma
- Re-ordering by alphabetic order some parameters

Signed-off-by: Calvin Audier <[email protected]>

---------

Signed-off-by: Calvin Audier <[email protected]>
Signed-off-by: Calvinaud <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Signed-off-by: andoriyaprashant <[email protected]>
Signed-off-by: Prashant Andoriya <[email protected]>
@namkyu1999 namkyu1999 added the need-approvers-review Reminder label to the codeowners/maintainers for stale PRs that are more that 2 weeks old label Nov 15, 2024
@S-ayanide
Copy link
Member

S-ayanide commented Nov 22, 2024

Hi @andoriyaprashant , can you please rebase with main? The current commit history is incorrect which is why it's pulling a lot of extra commits too.

Signed-off-by: Prashant Andoriya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-approvers-review Reminder label to the codeowners/maintainers for stale PRs that are more that 2 weeks old
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: remove global variable for better unit testing