Skip to content

test: add glob pattern tests to sqlpath.Glob #2995

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 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 45 additions & 0 deletions internal/sql/sqlpath/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,48 @@ func TestFollowSymlinks(t *testing.T) {
t.Errorf("Expected no error, but got %v", err)
}
}

func TestGlobPattern(t *testing.T) {
// Arrange
tests := []struct {
pattern string
expected []string
}{
{
pattern: "testdata/glob/*/queries",
expected: []string{
"testdata/glob/sub1/queries/file1.sql",
"testdata/glob/sub2/queries/file2.sql",
"testdata/glob/sub3/queries/file3.sql",
"testdata/glob/sub3/queries/file4.sql",
},
},
{
pattern: "testdata/glob/sub3/queries/file?.sql",
expected: []string{
"testdata/glob/sub3/queries/file3.sql",
"testdata/glob/sub3/queries/file4.sql",
},
},
{
pattern: "testdata/glob/sub3/queries/file[1-5].sql",
expected: []string{
"testdata/glob/sub3/queries/file3.sql",
"testdata/glob/sub3/queries/file4.sql",
},
},
}

for _, test := range tests {
// Act
result, err := Glob([]string{test.pattern})

// Assert
if !cmp.Equal(result, test.expected) {
t.Errorf("Pattern %v: Expected %v, but got %v", test.pattern, test.expected, result)
}
if err != nil {
t.Errorf("Pattern %v: Expected no error, but got %v", test.pattern, err)
}
}
}
Empty file.
Empty file.
Empty file.
Empty file.