10000 Enhance `sqlpath.Glob` to actually support glob wildcard by iamwavecut · Pull Request #2955 · sqlc-dev/sqlc · GitHub
[go: up one dir, main page]

Skip to content

Enhance sqlpath.Glob to actually support glob wildcard #2955

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

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: improve tests, minor change one expected error message
  • Loading branch information
Valeriy Selitskiy committed Nov 7, 2023
commit a69b0d4b1aabb2b01dbbbc364cb3a0ba5e9fc61a
30 changes: 23 additions & 7 deletions internal/sql/sqlpath/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func TestReturnsErrorWhenPathDoesNotExist(t *testing.T) {
if err == nil {
t.Errorf("Expected an error, but got nil")
} else {
expectedError := fmt.Errorf("path non_existent_path does not exist")
expectedError := fmt.Errorf(`failed to stat path "non_existent_path": ` +
`lstat non_existent_path: no such file or directory`)
if !cmp.Equal(err.Error(), expectedError.Error()) {
t.Errorf("Expected error %v, but got %v", expectedError, err)
}
Expand Down Expand Up @@ -153,24 +154,39 @@ func TestDoesNotIncludesSQLFilesWithUppercaseExtension(t *testing.T) {
}
}

func TestIncludesSQLFilesWithLeadingDotsInDirectoryName(t *testing.T) {
func TestNotIncludesHiddenFilesAnyPath(t *testing.T) {
// Arrange
paths := []string{"./testdata/.hiddendir/file1.sql"}
paths := []string{
"./testdata/.hiddendir/file1.sql", // pass
"./testdata/.hidden.sql", // skip
}

// Act
result, err := Glob(paths)

// Assert
expected := []string{"./testdata/.hiddendir/file1.sql"}
if !cmp.Equal(result, expected) {
t.Errorf("Expected %v, but got %v", expected, result)
expectedAny := [][]string{
{"./testdata/.hiddendir/file1.sql"},
{"testdata/.hiddendir/file1.sql"},
}

match := false
for _, expected := range expectedAny {
if cmp.Equal(result, expected) {
match = true
break
}
}
if !match {
t.Errorf("Expected any of %v, but got %v", expectedAny, result)
}

if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
}

func TestPathIsSymlink(t *testing.T) {
func TestFollowSymlinks(t *testing.T) {
// Arrange
paths := []string{"testdata/symlink", "testdata/file1.symlink.sql"}

Expand Down
0