-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package aghos | ||
package aghos_test | ||
|
||
import ( | ||
"testing" | ||
|
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,54 @@ | ||
package aghos | ||
|
||
import ( | ||
"io/fs" | ||
"path" | ||
"testing" | ||
"testing/fstest" | ||
|
||
"github.com/AdguardTeam/golibs/errors" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type errFS struct { | ||
fs.GlobFS | ||
} | ||
|
||
const errErrFSOpen errors.Error = "this error is always returned" | ||
|
||
func (efs *errFS) Open(name string) (fs.File, error) { | ||
return nil, errErrFSOpen | ||
} | ||
|
||
func TestWalkerFunc_CheckFile(t *testing.T) { | ||
emptyFS := fstest.MapFS{} | ||
|
||
t.Run("non-existing", func(t *testing.T) { | ||
_, ok, err := checkFile(emptyFS, nil, "lol") | ||
require.NoError(t, err) | ||
|
||
assert.True(t, ok) | ||
}) | ||
|
||
t.Run("invalid_argument", func(t *testing.T) { | ||
_, ok, err := checkFile(&errFS{}, nil, "") | ||
require.ErrorIs(t, err, errErrFSOpen) | ||
|
||
assert.False(t, ok) | ||
}) | ||
|
||
t.Run("ignore_dirs", func(t *testing.T) { | ||
const dirName = "dir" | ||
|
||
testFS := fstest.MapFS{ | ||
path.Join(dirName, "file"): &fstest.MapFile{Data: []byte{}}, | ||
} | ||
|
||
patterns, ok, err := checkFile(testFS, nil, dirName) | ||
require.NoError(t, err) | ||
|
||
assert.Empty(t, patterns) | ||
assert.True(t, ok) | ||
}) | ||
} |
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