This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michael Hoang <mhoang@redhat.com>
- Loading branch information
1 parent
3593452
commit 919dfaf
Showing
10 changed files
with
1,545 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetCachedFilePathsFromRoot(t *testing.T) { | ||
missingPathErr := "no such file or directory" | ||
|
||
tests := []struct { | ||
name string | ||
root string | ||
ctx context.Context | ||
expectedFilePaths []string | ||
expectedError *string | ||
}{ | ||
{ | ||
name: "Case 1: Cached file paths exist", | ||
root: "path/to/root", | ||
ctx: context.WithValue(context.Background(), key("mapFilePathsFromRoot"), map[string][]string{ | ||
"path/to/root": {"f1.txt", "f2.txt"}, | ||
}), | ||
expectedFilePaths: []string{"f1.txt", "f2.txt"}, | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "Case 2: Invalid file path", | ||
root: "invalid/path", | ||
ctx: context.Background(), | ||
expectedFilePaths: []string{}, | ||
expectedError: &missingPathErr, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
filePaths, err := GetCachedFilePathsFromRoot(tt.root, &tt.ctx) | ||
|
||
if err != nil { | ||
assert.Regexp(t, *tt.expectedError, err.Error(), "Error message should match") | ||
} | ||
|
||
assert.EqualValues(t, tt.expectedFilePaths, filePaths) | ||
}) | ||
} | ||
} |
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.