From 489dbfa5c247e69a843d9474ebcff10022480d51 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Jan 2024 22:10:00 +0100 Subject: [PATCH] Make API more consistent --- vfst/example_test.go | 16 ++++++++-------- vfst/vfst.go | 6 +++--- vfst/vfst_test.go | 31 ++++++++++++++++--------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/vfst/example_test.go b/vfst/example_test.go index 05ac5f2..0bb77ae 100644 --- a/vfst/example_test.go +++ b/vfst/example_test.go @@ -48,15 +48,15 @@ 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"), ), @@ -64,22 +64,22 @@ func ExampleNewTestFS_complex() { // 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"), ), @@ -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"), ), ) diff --git a/vfst/vfst.go b/vfst/vfst.go index a5a4c30..ac72993 100644 --- a/vfst/vfst.go +++ b/vfst/vfst.go @@ -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. @@ -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. diff --git a/vfst/vfst_test.go b/vfst/vfst_test.go index e33be29..52f9ec1 100644 --- a/vfst/vfst_test.go +++ b/vfst/vfst_test.go @@ -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"), ), @@ -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"), ), @@ -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), ), }, @@ -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"), @@ -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), @@ -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), ), @@ -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"), ),