Skip to content
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

Make API more consistent #69

Merged
merged 1 commit into from
Jan 22, 2024
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
16 changes: 8 additions & 8 deletions vfst/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ func ExampleNewTestFS_complex() {
tests := []interface{}{
// Test multiple properties of a single path with TestPath.
vfst.TestPath("/home",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o755),
),
vfst.TestPath("/home/user",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o755),
),
vfst.TestPath("/home/user/.bashrc",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("# contents of user's .bashrc\n"),
),
// Maps with string keys create sub tests with testing.T.Run. The key
// is used as the test name.
map[string]interface{}{
"home_user_empty": vfst.TestPath("/home/user/empty",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestSize(0),
),
"foo_bar_baz": vfst.TestPath("/home/user/foo/bar/baz",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("qux"),
),
"root": []interface{}{
vfst.TestPath("/root",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o700),
),
vfst.TestPath("/root/.bashrc",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("# contents of root's .bashrc\n"),
),
Expand Down Expand Up @@ -114,7 +114,7 @@ func ExampleNewTestFS() {

vfst.RunTests(t, fileSystem, "bashrc",
vfst.TestPath("/home/user/.bashrc",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestContentsString("# contents of user's .bashrc\n"),
),
)
Expand Down
6 changes: 3 additions & 3 deletions vfst/vfst.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ var testDoesNotExist = func(t *testing.T, fileSystem vfs.FS, path string) {

// TestDoesNotExist is a PathTest that verifies that a file or directory does
// not exist.
var TestDoesNotExist PathTest = testDoesNotExist
var TestDoesNotExist = func() PathTest { return testDoesNotExist }

// TestIsDir is a PathTest that verifies that the path is a directory.
var TestIsDir = TestModeType(fs.ModeDir)
var TestIsDir = func() PathTest { return TestModeType(fs.ModeDir) }

// TestModePerm returns a PathTest that verifies that the path's permissions
// are equal to wantPerm.
Expand All @@ -383,7 +383,7 @@ func TestModePerm(wantPerm fs.FileMode) PathTest {
}

// TestModeIsRegular is a PathTest that tests that the path is a regular file.
var TestModeIsRegular = TestModeType(0)
var TestModeIsRegular = func() PathTest { return TestModeType(0) }

// TestModeType returns a PathTest that verifies that the path's mode type is
// equal to wantModeType.
Expand Down
31 changes: 16 additions & 15 deletions vfst/vfst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func TestBuilderBuild(t *testing.T) {
},
tests: []vfst.Test{
vfst.TestPath("/foo",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o755),
),
vfst.TestPath("/foo/bar",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("baz"),
),
Expand All @@ -56,7 +56,7 @@ func TestBuilderBuild(t *testing.T) {
},
tests: []vfst.Test{
vfst.TestPath("/foo",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("bar"),
),
Expand All @@ -72,19 +72,19 @@ func TestBuilderBuild(t *testing.T) {
},
tests: []vfst.Test{
vfst.TestPath("/foo",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestSize(3),
vfst.TestContentsString("bar"),
),
vfst.TestPath("/baz",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o755),
vfst.TestSize(3),
vfst.TestContentsString("qux"),
),
vfst.TestPath("/dir",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o700),
),
},
Expand All @@ -97,11 +97,11 @@ func TestBuilderBuild(t *testing.T) {
},
tests: []vfst.Test{
vfst.TestPath("/foo",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o755),
),
vfst.TestPath("/foo/bar",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestSize(3),
vfst.TestContentsString("baz"),
Expand Down Expand Up @@ -158,14 +158,15 @@ func TestCoverage(t *testing.T) {
defer cleanup()
vfst.RunTests(t, fileSystem, "", []interface{}{
vfst.TestPath("/home",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o755),
),
vfst.TestPath("/notexist",
vfst.TestDoesNotExist),
vfst.TestDoesNotExist(),
),
map[string]vfst.Test{
"home_user_bashrc": vfst.TestPath("/home/user/.bashrc",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("# contents of user's .bashrc\n"),
vfst.TestMinSize(1),
Expand All @@ -174,7 +175,7 @@ func TestCoverage(t *testing.T) {
},
map[string]interface{}{
"home_user_empty": vfst.TestPath("/home/user/empty",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestSize(0),
),
Expand All @@ -184,18 +185,18 @@ func TestCoverage(t *testing.T) {
),
"foo_bar_baz": []vfst.Test{
vfst.TestPath("/home/user/foo/bar/baz",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("qux"),
),
},
"root": []interface{}{
vfst.TestPath("/root",
vfst.TestIsDir,
vfst.TestIsDir(),
vfst.TestModePerm(0o700),
),
vfst.TestPath("/root/.bashrc",
vfst.TestModeIsRegular,
vfst.TestModeIsRegular(),
vfst.TestModePerm(0o644),
vfst.TestContentsString("# contents of root's .bashrc\n"),
),
Expand Down
Loading