This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
fnutils and errutils test cases, inline docs, listall fnc fix #82
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8111ef9
added test cases for fnutils package
neo7337 92d483e
error utils test cases added #57
neo7337 f9878be
added inline docs for errutils and fnutils #56
neo7337 629f1c9
added vfs documentation
neo7337 10963ab
#80 ListAll fnc fix to read nested directories
neo7337 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package errutils | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestFmtError(t *testing.T) { | ||
t.Run("Testing execution of error utils", func(t *testing.T) { | ||
want := errors.New("testing error utils") | ||
got := FmtError("testing error utils") | ||
if got.Error() != want.Error() { | ||
t.Errorf("invalid error string generated") | ||
} | ||
}) | ||
|
||
t.Run("Testing execution of error utils with formatting", func(t *testing.T) { | ||
want := errors.New(fmt.Sprintf("expecting errors %d", 0)) | ||
got := FmtError("expecting errors %d", 0) | ||
if got.Error() != want.Error() { | ||
t.Errorf("invalid error string generated") | ||
} | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package fnutils | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestExecuteAfter(t *testing.T) { | ||
t.Run("Execution occurs after the specified timeout", func(t *testing.T) { | ||
executed := false | ||
fn := func() { | ||
executed = true | ||
} | ||
timeout := 5 * time.Second | ||
|
||
ExecuteAfter(fn, timeout) | ||
|
||
if !executed { | ||
t.Error("Expected execution to occur after the specified timeout") | ||
} | ||
}) | ||
|
||
t.Run("Execution occurs immediately when timeout is zero", func(t *testing.T) { | ||
executed := false | ||
fn := func() { | ||
executed = true | ||
} | ||
timeout := 0 * time.Second | ||
|
||
ExecuteAfter(fn, timeout) | ||
|
||
if !executed { | ||
t.Error("Expected execution to occur immediately") | ||
} | ||
}) | ||
|
||
t.Run("Execution occurs only once", func(t *testing.T) { | ||
counter := 0 | ||
fn := func() { | ||
counter++ | ||
} | ||
timeout := 1 * time.Second | ||
|
||
ExecuteAfter(fn, timeout) | ||
time.Sleep(2 * time.Second) | ||
|
||
if counter != 1 { | ||
t.Errorf("Expected execution to occur once, got %d times", counter) | ||
} | ||
}) | ||
// | ||
//t.Run("Multiple executions occur if the function takes longer than the timeout", func(t *testing.T) { | ||
// executionCount := 0 | ||
// fn := func() { | ||
// executionCount++ | ||
// time.Sleep(2 * time.Second) | ||
// } | ||
// timeout := 1 * time.Second | ||
// | ||
// go ExecuteAfter(fn, timeout) | ||
// time.Sleep(3 * time.Second) | ||
// | ||
// if executionCount != 2 { | ||
// t.Errorf("Expected execution to occur twice, got %d times", executionCount) | ||
// } | ||
//}) | ||
// | ||
//t.Run("No execution occurs if the function is nil", func(t *testing.T) { | ||
// _ = func() { | ||
// // This function should not be executed | ||
// t.Error("Function should not be executed") | ||
// } | ||
// timeout := 1 * time.Second | ||
// | ||
// ExecuteAfter(nil, timeout) | ||
//}) | ||
// | ||
//t.Run("No execution occurs if the timeout is set to 0 and the function is nil", func(t *testing.T) { | ||
// _ = func() { | ||
// // This function should not be executed | ||
// t.Error("Function should not be executed") | ||
// } | ||
// timeout := 0 * time.Second | ||
// | ||
// ExecuteAfter(nil, timeout) | ||
//}) | ||
// | ||
//t.Run("Execution does not occur when timeout is negative", func(t *testing.T) { | ||
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. @nandagopalan have a look at this condition if we need to cater for this in our logic |
||
// executed := false | ||
// fn := func() { | ||
// executed = true | ||
// } | ||
// timeout := -1 * time.Second | ||
// | ||
// ExecuteAfter(fn, timeout) | ||
// | ||
// if executed { | ||
// t.Error("Expected execution to not occur with negative timeout") | ||
// } | ||
//}) | ||
} | ||
|
||
func TestExecuteAfterSecs(t *testing.T) { | ||
t.Run("Execution after specific timeout (seconds)", func(t *testing.T) { | ||
executed := false | ||
fn := func() { | ||
executed = true | ||
} | ||
ExecuteAfterSecs(fn, 5) | ||
if !executed { | ||
t.Error("Expected execution to occur after the specified timeout") | ||
} | ||
}) | ||
} | ||
|
||
func TestExecuteAfterMs(t *testing.T) { | ||
t.Run("Execution after specific timeout (milliseconds)", func(t *testing.T) { | ||
executed := false | ||
fn := func() { | ||
executed = true | ||
} | ||
ExecuteAfterMs(fn, 50) | ||
if !executed { | ||
t.Error("Expected execution to occur after the specified timeout") | ||
} | ||
}) | ||
} | ||
|
||
func TestExecuteAfterMin(t *testing.T) { | ||
t.Run("Execution after specific timeout (minutes)", func(t *testing.T) { | ||
executed := false | ||
fn := func() { | ||
executed = true | ||
} | ||
ExecuteAfterMin(fn, 1) | ||
if !executed { | ||
t.Error("Expected execution to occur after the specified timeout") | ||
} | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,8 +1,47 @@ | ||
# Virtual File System (VFS) Package | ||
The VFS package provides a unified api for accessing multple file system. It is extensible and new implementation can be | ||
The VFS package provides a unified api for accessing multiple file system. It is extensible and new implementation can be | ||
easily plugged in. | ||
|
||
|
||
The default package has methods for local file system. | ||
|
||
--- | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
--- | ||
|
||
### Installation | ||
```bash | ||
go get go.nandlabs.io/commons/vfs | ||
``` | ||
|
||
### Usage | ||
A simple usage of the library to create a directory in the OS. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"go.nandlabs.io/commons/vfs" | ||
) | ||
|
||
var ( | ||
testManager = GetManager() | ||
) | ||
|
||
func GetRawPath(input string) (output string) { | ||
currentPath, _ := os.Getwd() | ||
u, _ := url.Parse(input) | ||
path := currentPath + u.Path | ||
output = u.Scheme + "://" + path | ||
return | ||
} | ||
|
||
func main() { | ||
u := GetRawPath("file:///test-data") | ||
_, err := testManager.MkdirRaw(u) | ||
if err != nil { | ||
fmt.Errorf("MkdirRaw() error = %v", err) | ||
} | ||
} | ||
``` |
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
Oops, something went wrong.
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.
@nandagopalan same here, if we need to handle this condition in our logic
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.
I think we may have to put a nil check in the code.
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.
I am approving this PR we will add that as a separate issue.