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

fix unable to record custom name test cases #1189

Merged
merged 9 commits into from
Dec 14, 2023

Conversation

AkashKumar7902
Copy link
Member

Related Issue

  • Info about Issue or bug

Closes: #1188

Describe the changes you've made

the findlastindex must be called only when no custom test case name is provided. so I have changed the order of function call

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

Please describe the tests(if any). Provide instructions how its affecting the coverage.

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

A clear and concise description of it.

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)

Original Updated
image image

AkashKumar7902 and others added 2 commits December 11, 2023 20:11
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Copy link

sweep-ai bot commented Dec 11, 2023

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

@AkashKumar7902 AkashKumar7902 changed the title fix bug fix unable to record custom name test cases Dec 11, 2023
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
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 resolve the comments

@@ -68,7 +68,7 @@ func findLastIndex(path string, Logger *zap.Logger) (int, error) {
fileNameWithoutExt := fileName[:len(fileName)-len(filepath.Ext(fileName))]
if len(strings.Split(fileNameWithoutExt, "-")) < 2 {
Logger.Error("failed to decode the last sequence number from yaml test", zap.Any("for the file", fileName), zap.Any("at path", path))
Copy link
Member

Choose a reason for hiding this comment

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

error log should also be removed right because we don't care what is the name of the file if it match "test-x" then only we should count it.

@@ -68,7 +68,7 @@ func findLastIndex(path string, Logger *zap.Logger) (int, error) {
fileNameWithoutExt := fileName[:len(fileName)-len(filepath.Ext(fileName))]
if len(strings.Split(fileNameWithoutExt, "-")) < 2 {
Logger.Error("failed to decode the last sequence number from yaml test", zap.Any("for the file", fileName), zap.Any("at path", path))
return 0, errors.New("failed to decode the last sequence number from yaml test")
continue
}
indxStr := strings.Split(fileNameWithoutExt, "-")[1]
indx, err := strconv.Atoi(indxStr)
Copy link
Member

Choose a reason for hiding this comment

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

even for this error we shouldn't throw any log or return error.

if tc.Name == "" {
// finds the recently generated testcase to derive the sequence number for the current testcase
Copy link
Member

Choose a reason for hiding this comment

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

Please test all the cases once for this feature.

  1. record tests normally and run test mode. Don't use this feature and don't change any test case name.
  2. record tests normally and record using this feature somewhere in the middle and run in test mode.
  3. Along with second case rename test case manually in between recording and run in test mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

here are the test-reports for all the specified scenarios:

  1. https://pastebin.com/9nXVC3UL
  2. https://pastebin.com/VrkciP8D
  3. https://pastebin.com/VBKjrFLw

in the 3rd case, if we just rename the test case file and if we try running only that particular file (refer PR 1165
), then it will result in an error:

🐰 Keploy: 2023-12-12T17:59:27+05:30    ERROR   test/test.go:465        failed to fetch test results    {"error": "🐰 Keploy:%!(EXTRA string=found no test results for test report with id: %v, string=report-24)"}

we need to go inside the test case file and change the name parameter as well.

Copy link
Member

Choose a reason for hiding this comment

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

why does this happen any analysis..? I mean we just get the file and run the content right. Do we do any validation like checking if parameter in the file is equal to file name..?

Copy link
Member Author

@AkashKumar7902 AkashKumar7902 Dec 14, 2023

Choose a reason for hiding this comment

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

in line 555 of test.go, we are iterating through initialisedValues.Tcs which contains information about the testcase from inside the files. so to run a particular testcase, the value of the name field present in the files will be compared to the testcase name you provided. renaming alone won't work as the comparison is done with the name field not the filename.

the error will arise if there are several testcases and you want to run something that does not match with the name of any testcase present. This error is caused because in FetchTestReport , the error condition (passed + failed == 0) is true, as no testcase ran.

Copy link
Member

Choose a reason for hiding this comment

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

Through this feature like renaming using header we will change the tc.name also right along with file name...? leave about renaming manually we can skip it.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

AkashKumar7902 and others added 4 commits December 12, 2023 18:06
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
@charankamarapu
Copy link
Member

Is the PR ready for review..?

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

if tc.Name == "" {
// finds the recently generated testcase to derive the sequence number for the current testcase
Copy link
Member

Choose a reason for hiding this comment

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

why does this happen any analysis..? I mean we just get the file and run the content right. Do we do any validation like checking if parameter in the file is equal to file name..?

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.

Ship it!

@charankamarapu charankamarapu merged commit 1a6d446 into keploy:main Dec 14, 2023
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
@AkashKumar7902 AkashKumar7902 deleted the custom-test-cases-bug branch December 14, 2023 08:49
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.

[bug]: unable to record custom name test cases
2 participants