-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Recursively Find Validator Database File In Slashing Protection Commands #8518
Merged
rauljordan
merged 13 commits into
prysmaticlabs:develop
from
ahadda5:findValidatorAutomatically
Feb 26, 2021
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9304177
issue/feature 8500 find validator.db automatically
ahadda5 1ec1463
gazelle build
ahadda5 1f9f63d
remove less! why there?
ahadda5 14562b6
fixed errors import
ahadda5 8f37f6a
fixed errors import
ahadda5 9e682a0
unit tested
ahadda5 c9f91bd
Merge branch 'develop' into findValidatorAutomatically
ahadda5 65be74b
Merge branch 'develop' into findValidatorAutomatically
rauljordan ee6c238
Merge branch 'develop' into findValidatorAutomatically
rauljordan e985953
Merge branch 'develop' into findValidatorAutomatically
rauljordan 7e796b6
adding the find validator.db fileutil func to export and import slashing
ahadda5 c98c982
deleted the comment
ahadda5 e9c3a41
Merge branch 'develop' into findValidatorAutomatically
ahadda5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,57 @@ func TestDirFiles(t *testing.T) { | |
} | ||
} | ||
|
||
func TestRecursiveFileFind(t *testing.T) { | ||
tmpDir, _ := tmpDirWithContentsForRecursiveFind(t) | ||
tests := []struct { | ||
name string | ||
root string | ||
path string | ||
found bool | ||
}{ | ||
{ | ||
name: "file1", | ||
root: tmpDir, | ||
path: "subfolder1/subfolder11/file1", | ||
found: true, | ||
}, | ||
{ | ||
name: "file2", | ||
root: tmpDir, | ||
path: "subfolder2/file2", | ||
found: true, | ||
}, | ||
{ | ||
name: "file1", | ||
root: tmpDir + "/subfolder1", | ||
path: "subfolder11/file1", | ||
found: true, | ||
}, | ||
{ | ||
name: "file3", | ||
root: tmpDir, | ||
path: "file3", | ||
found: true, | ||
}, | ||
{ | ||
name: "file4", | ||
root: tmpDir, | ||
path: "", | ||
found: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
found, _, err := fileutil.RecursiveFileFind(tt.name, tt.root) | ||
require.NoError(t, err) | ||
|
||
assert.DeepEqual(t, tt.found, found) | ||
//assert.DeepEqual(t, tt.path, fpath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok will do. |
||
}) | ||
} | ||
} | ||
|
||
func deepCompare(t *testing.T, file1, file2 string) bool { | ||
sf, err := os.Open(file1) | ||
assert.NoError(t, err) | ||
|
@@ -281,6 +332,24 @@ func tmpDirWithContents(t *testing.T) (string, []string) { | |
return dir, fnames | ||
} | ||
|
||
// tmpDirWithContentsForRecursiveFind returns path to temporary directory having some folders/files in it. | ||
// Directory is automatically removed by internal testing cleanup methods. | ||
func tmpDirWithContentsForRecursiveFind(t *testing.T) (string, []string) { | ||
dir := t.TempDir() | ||
fnames := []string{ | ||
"subfolder1/subfolder11/file1", | ||
"subfolder2/file2", | ||
"file3", | ||
} | ||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "subfolder1", "subfolder11"), 0777)) | ||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "subfolder2"), 0777)) | ||
for _, fname := range fnames { | ||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, fname), []byte(fname), 0777)) | ||
} | ||
sort.Strings(fnames) | ||
return dir, fnames | ||
} | ||
|
||
func TestHasReadWritePermissions(t *testing.T) { | ||
type args struct { | ||
itemPath string | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the best way to check if its a file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep this is a fine approach