-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ refactor with afero (#184)
* refactor: ♻️ replace built-in file related func with afero the afero is more friendly for writing ut also fix a bug of RecursivelySize * refactor: ♻️ refactor dive func with afero.Fs the afero is more friendly for writing ut * test: ✅ add ut * docs(contributing): 📝 update CONTRIBUTING.md * ci(Github actions): 👷 bump workflow go version * chore: 🎨 format code * docs(ReleaseWorkflow): ⬆️ bump deps
- Loading branch information
1 parent
5c8ba99
commit 85f8f8a
Showing
47 changed files
with
547 additions
and
377 deletions.
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
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
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
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,47 @@ | ||
package cli | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/Equationzhao/g/internal/filter" | ||
"github.com/Equationzhao/g/internal/item" | ||
"github.com/Equationzhao/g/internal/util" | ||
"github.com/panjf2000/ants/v2" | ||
"github.com/spf13/afero" | ||
"github.com/zeebo/assert" | ||
) | ||
|
||
func Test_dive(t *testing.T) { | ||
afs := afero.NewMemMapFs() | ||
// create files and dirs | ||
_ = afs.MkdirAll("a/b/c", 0o755) | ||
_ = afero.WriteFile(afs, "a/b/c/d", util.GenRandomData(10), 0o644) | ||
_ = afero.WriteFile(afs, "a/b/e", util.GenRandomData(10), 0o644) | ||
_ = afero.WriteFile(afs, "a/f", util.GenRandomData(10), 0o644) | ||
_ = afero.WriteFile(afs, "a/g", util.GenRandomData(10), 0o644) | ||
_ = afero.WriteFile(afs, "a/h", util.GenRandomData(10), 0o644) | ||
_ = afero.WriteFile(afs, "i", util.GenRandomData(10), 0o644) | ||
|
||
var err error | ||
pool, err = ants.NewPool(ants.DefaultAntsPoolSize) | ||
assert.NoError(t, err) | ||
|
||
// test | ||
uslice := util.NewSlice[*item.FileInfo](10) | ||
errSlice := util.NewSlice[error](1) | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
filters := filter.NewItemFilter() | ||
dive(".", 1, -1, uslice, errSlice, &wg, filters, afs) | ||
wg.Wait() | ||
if uslice.Len() != 9 { | ||
t.Errorf("expect 7, got %d", uslice.Len()) | ||
for _, info := range *uslice.GetRaw() { | ||
t.Logf("%s", info.FullPath) | ||
} | ||
} | ||
if errSlice.Len() != 0 { | ||
t.Errorf("expect 0, got %d", errSlice.Len()) | ||
} | ||
} |
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
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
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
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
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
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
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
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.