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

Search test data directory path dynamically #2005

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

weiihann
Copy link
Contributor

Description

This PR modifies the implementation of finding the target test data directory. The issue with the existing implementation is that if a user changes the repository's name from juno to whatever, the tests will fail. Also, any tests that rely on NewTestClient in cmd/juno will fail because the base directory extracted will be ../juno/cmd/juno instead of ../juno.

Copy link

codecov bot commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.40%. Comparing base (2dd8037) to head (2fd1c2e).

Files Patch % Lines
clients/feeder/feeder.go 55.55% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2005      +/-   ##
==========================================
- Coverage   75.45%   75.40%   -0.05%     
==========================================
  Files         100      100              
  Lines        8968     8983      +15     
==========================================
+ Hits         6767     6774       +7     
- Misses       1601     1604       +3     
- Partials      600      605       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kirugan kirugan force-pushed the weiihann/fix-create-test-server branch from 0de1a56 to 0a52825 Compare July 31, 2024 21:32
@weiihann weiihann force-pushed the weiihann/fix-create-test-server branch from 0a52825 to 120ac22 Compare August 1, 2024 12:11
Comment on lines 453 to 471
func findTargetDirectory(targetRelPath string) (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}

for root := wd; ; root = filepath.Dir(root) {
if _, err := os.Stat(filepath.Join(root, targetRelPath)); err == nil {
return filepath.Join(root, targetRelPath), nil
} else if !os.IsNotExist(err) {
return "", err
} else if newRoot := filepath.Dir(root); newRoot == root {
return "", os.ErrNotExist
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the function can be simplified as follows:

Suggested change
func findTargetDirectory(targetRelPath string) (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}
for root := wd; ; root = filepath.Dir(root) {
if _, err := os.Stat(filepath.Join(root, targetRelPath)); err == nil {
return filepath.Join(root, targetRelPath), nil
} else if !os.IsNotExist(err) {
return "", err
} else if newRoot := filepath.Dir(root); newRoot == root {
return "", os.ErrNotExist
}
}
}
func findTargetDirectory(targetRelPath string) (string, error) {
root, err := os.Getwd()
if err != nil {
return "", err
}
for {
targetPath := filepath.Join(root, targetRelPath)
if _, err := os.Stat(targetPath); err == nil {
return targetPath, nil
} else if !os.IsNotExist(err) {
return "", err
}
newRoot := filepath.Dir(root)
if newRoot == root {
return "", os.ErrNotExist
}
root = newRoot
}
}

@weiihann weiihann force-pushed the weiihann/fix-create-test-server branch from 120ac22 to 2fd1c2e Compare August 2, 2024 07:51
@kirugan kirugan merged commit 0a92c98 into main Aug 2, 2024
9 of 10 checks passed
@kirugan kirugan deleted the weiihann/fix-create-test-server branch August 2, 2024 08:12
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.

3 participants