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

[Feature]: Create a normalisation command in keploy CLI #1589

Merged
merged 42 commits into from
May 2, 2024

Conversation

Akash-Singh04
Copy link
Contributor

@Akash-Singh04 Akash-Singh04 commented Feb 17, 2024

Related Issue

  • New CLI Command Feature

Closes: #1538

Describe the changes you've made

Added keploy normalise command to the Keploy CLI to allow users to normalise their test cases. The Function of the command is as follows:

  • The command checks for test-sets , test-cases and test-run flags from the CLI
  • The command reads YAML files containing test data and unmarshals it..
  • The command iterates over each failed test case in the test data and retrieves the corresponding test data from the struct.
  • The command then updates the expected response in the test case file with the actual response obtained
  • Finally, the program writes the updated YAML data back to the original testcase files.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Please let us know if any test cases are added

NIL

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

NA

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Screenshots (if any)

image
image

Akash-Singh04 and others added 6 commits February 16, 2024 20:47
Signed-off-by: Akash <akashsingh2210670@gmail.com>
Signed-off-by: Akash <akashsingh2210670@gmail.com>
Signed-off-by: Akash <akashsingh2210670@gmail.com>
…e doesnt match yaml file

Signed-off-by: Akash <akashsingh2210670@gmail.com>
Signed-off-by: Akash <akashsingh2210670@gmail.com>
@Akash-Singh04
Copy link
Contributor Author

@charankamarapu Kindly review this PR and let me know if this implementation works!

@charankamarapu
Copy link
Member

From the screenshot I can say there is a bit of feature missing. User should give the testcases and testSet name which user want to normalise.

Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

Please address the comment

@Akash-Singh04
Copy link
Contributor Author

From the screenshot I can say there is a bit of feature missing. User should give the testcases and testSet name which user want to normalise.

Alright, if that is how we would want to implement this feature it should not be a problem at all. Will update asap and revert!

@Akash-Singh04
Copy link
Contributor Author

@charankamarapu Let me know if this implementation is ready to go or there is a need to further include more features in this!

@Akash-Singh04
Copy link
Contributor Author

@charankamarapu If the CI pipeline will require time to fix, this PR is ready to be merged

@charankamarapu
Copy link
Member

cool will do a review and let you know.

@Akash-Singh04
Copy link
Contributor Author

@charankamarapu I have addressed the review comments. Looking forward to your review on them

Akash-Singh04 and others added 5 commits March 29, 2024 19:13
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

please address the comments

cli/normalise.go Outdated Show resolved Hide resolved
@@ -155,6 +155,10 @@ func (c *CmdConfigurator) AddFlags(cmd *cobra.Command, cfg *config.Config) error
switch cmd.Name() {
case "update":
return nil
case "normalise":
Copy link
Member

Choose a reason for hiding this comment

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

Actually we should give option to the user to provide the test-run also so the flags would test-run, test-set, test-case. regarding path flag it should be normal path flag which we get in record and replay commands. It shouldn't be specific to reports. We have a config file which will be used for provided info like path etc without flags. There is a package for it named config.

@@ -377,6 +381,35 @@ func (c CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command)
}
}
}
case "Normalise":
path := viper.GetString("path")
Copy link
Member

Choose a reason for hiding this comment

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

You need not do this if add things in config please go through test and record command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored

@@ -283,3 +287,113 @@ func (t *Tools) CreateConfig(_ context.Context, filePath string, configData stri
t.logger.Info("Config file generated successfully")
return nil
}

// Normalise initiates the normalise process for normalising the test cases.
func (t *Tools) Normalise(_ context.Context) error {
Copy link
Member

Choose a reason for hiding this comment

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

You should use yaml functions to edit the test-cases. You should how it is done in record and replay via interfaces of DBs . you can add this function in record or replay service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it to replay service

Akash-Singh04 and others added 3 commits April 8, 2024 03:10
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

Please address the comments

// Normalise initiates the normalise process for normalising the test cases.
func (r *Replayer) Normalise(_ context.Context, cfg *config.Config) error {
path := cfg.Path
testSets := viper.GetString("test-sets")
Copy link
Member

Choose a reason for hiding this comment

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

These are not needed use config struct instead of getting them like this. Please refer to how test or record command are accessing these kind of flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into this

if strings.HasSuffix(file.Name(), ".yaml") {
filePath := filepath.Join(testRunPath, file.Name())
// Read the YAML file
yamlData, err := os.ReadFile(filePath)
Copy link
Member

Choose a reason for hiding this comment

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

why are you not using the test or report dbs..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into this

@shivamsouravjha
Copy link
Contributor

shivamsouravjha commented Apr 29, 2024

@Akash-Singh04 if the comments are resolved feel free to resolve them, @charankamarapu would review the updated PR

@Akash-Singh04
Copy link
Contributor Author

@shivamsouravjha Need some time to properly look into the refactored codebase to resolve the comments,

@shivamsouravjha
Copy link
Contributor

Sure thing @Akash-Singh04 in the meanwhile you can move it as a draft,

@charankamarapu charankamarapu changed the base branch from main to normalise May 2, 2024 11:21
@charankamarapu charankamarapu merged commit cbaee01 into keploy:normalise May 2, 2024
13 of 14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: Create a normalisation command in keploy CLI
4 participants