diff --git a/README.md b/README.md index 18ea63b..c130325 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ func writeConfigFile(fileSystem vfs.FS) error { // TestWriteConfigFile is our test function. func TestWriteConfigFile(t *testing.T) { // Create and populate an temporary directory with a home directory. - fileSystem, cleanup, err := vfst.NewTestFS(map[string]interface{}{ + fileSystem, cleanup, err := vfst.NewTestFS(map[string]any{ "/home/user/.bashrc": "# contents of user's .bashrc\n", }) diff --git a/vfst/contains_test.go b/vfst/contains_test.go index a447d23..7001242 100644 --- a/vfst/contains_test.go +++ b/vfst/contains_test.go @@ -18,12 +18,12 @@ func TestContains(t *testing.T) { } for _, tc := range []struct { name string - root interface{} + root any tests []test }{ { name: "core", - root: map[string]interface{}{ + root: map[string]any{ "/home/user/file": "contents", }, tests: []test{ @@ -91,7 +91,7 @@ func TestContains(t *testing.T) { }, { name: "nonexistant_prefix", - root: map[string]interface{}{ + root: map[string]any{ "/home/user/file": "contents", }, tests: []test{ @@ -109,11 +109,11 @@ func TestContains(t *testing.T) { }, { name: "symlink_dir", - root: []interface{}{ - map[string]interface{}{ + root: []any{ + map[string]any{ "/home/user/file": "contents", }, - map[string]interface{}{ + map[string]any{ "/home/symlink": &vfst.Symlink{Target: "user"}, }, }, @@ -172,7 +172,7 @@ func TestContains(t *testing.T) { }, { name: "loop", - root: map[string]interface{}{ + root: map[string]any{ "/home/user": &vfst.Symlink{Target: "user"}, }, tests: []test{ diff --git a/vfst/example_test.go b/vfst/example_test.go index 7865ca1..1ac52f1 100644 --- a/vfst/example_test.go +++ b/vfst/example_test.go @@ -12,7 +12,7 @@ func ExampleNewTestFS_complex() { // Describe the structure of the filesystem using a map from filenames to // file or directory contents. - root := map[string]interface{}{ + root := map[string]any{ // A string or []byte is sets a file's contents. "/home/user/.bashrc": "# contents of user's .bashrc\n", "/home/user/empty": []byte{}, @@ -22,8 +22,8 @@ func ExampleNewTestFS_complex() { Contents: []byte("echo hello\n"), }, // Directories can be nested. - "/home/user/foo": map[string]interface{}{ - "bar": map[string]interface{}{ + "/home/user/foo": map[string]any{ + "bar": map[string]any{ "baz": "qux", }, }, @@ -31,7 +31,7 @@ func ExampleNewTestFS_complex() { // &vfst.Dir. "/root": &vfst.Dir{ Perm: 0o700, - Entries: map[string]interface{}{ + Entries: map[string]any{ ".bashrc": "# contents of root's .bashrc\n", }, }, @@ -45,7 +45,7 @@ func ExampleNewTestFS_complex() { defer cleanup() // Create tests by creating data structures containing Tests. - tests := []interface{}{ + tests := []any{ // Test multiple properties of a single path with TestPath. vfst.TestPath("/home", vfst.TestIsDir(), @@ -62,7 +62,7 @@ func ExampleNewTestFS_complex() { ), // Maps with string keys create sub tests with testing.T.Run. The key // is used as the test name. - map[string]interface{}{ + map[string]any{ "home_user_empty": vfst.TestPath("/home/user/empty", vfst.TestModeIsRegular(), vfst.TestModePerm(0o644), @@ -73,7 +73,7 @@ func ExampleNewTestFS_complex() { vfst.TestModePerm(0o644), vfst.TestContentsString("qux"), ), - "root": []interface{}{ + "root": []any{ vfst.TestPath("/root", vfst.TestIsDir(), vfst.TestModePerm(0o700), @@ -104,7 +104,7 @@ func ExampleNewTestFS() { Test := func(t *testing.T) { t.Helper() - fileSystem, cleanup, err := vfst.NewTestFS(map[string]interface{}{ + fileSystem, cleanup, err := vfst.NewTestFS(map[string]any{ "/home/user/.bashrc": "# contents of user's .bashrc\n", }) if err != nil { diff --git a/vfst/fs_test.go b/vfst/fs_test.go index 044378d..ccbb566 100644 --- a/vfst/fs_test.go +++ b/vfst/fs_test.go @@ -12,7 +12,7 @@ import ( ) func TestWalk(t *testing.T) { - fileSystem, cleanup, err := vfst.NewTestFS(map[string]interface{}{ + fileSystem, cleanup, err := vfst.NewTestFS(map[string]any{ "/home/user/.bashrc": "# .bashrc contents\n", "/home/user/skip/foo": "bar", "/home/user/symlink": &vfst.Symlink{Target: "baz"}, diff --git a/vfst/testfs.go b/vfst/testfs.go index 7468ec1..7aabf48 100644 --- a/vfst/testfs.go +++ b/vfst/testfs.go @@ -28,7 +28,7 @@ func NewEmptyTestFS() (*TestFS, func(), error) { } // NewTestFS returns a new *TestFS populated with root and a cleanup function. -func NewTestFS(root interface{}, builderOptions ...BuilderOption) (*TestFS, func(), error) { +func NewTestFS(root any, builderOptions ...BuilderOption) (*TestFS, func(), error) { fileSystem, cleanup, err := NewEmptyTestFS() if err != nil { cleanup() diff --git a/vfst/vfst.go b/vfst/vfst.go index 06dd36d..9d01e7e 100644 --- a/vfst/vfst.go +++ b/vfst/vfst.go @@ -21,7 +21,7 @@ var umask fs.FileMode // A Dir is a directory with a specified permissions and zero or more Entries. type Dir struct { Perm fs.FileMode - Entries map[string]interface{} + Entries map[string]any } // A File is a file with a specified permissions and contents. @@ -78,9 +78,9 @@ func NewBuilder(options ...BuilderOption) *Builder { } // build is a recursive helper for Build. -func (b *Builder) build(fileSystem vfs.FS, path string, i interface{}) error { +func (b *Builder) build(fileSystem vfs.FS, path string, i any) error { switch i := i.(type) { - case []interface{}: + case []any: for _, element := range i { if err := b.build(fileSystem, path, element); err != nil { return err @@ -107,7 +107,7 @@ func (b *Builder) build(fileSystem vfs.FS, path string, i interface{}) error { } } return nil - case map[string]interface{}: + case map[string]any: if err := b.MkdirAll(fileSystem, path, 0o777); err != nil { return err } @@ -153,7 +153,7 @@ func (b *Builder) build(fileSystem vfs.FS, path string, i interface{}) error { } // Build populates fileSystem from root. -func (b *Builder) Build(fileSystem vfs.FS, root interface{}) error { +func (b *Builder) Build(fileSystem vfs.FS, root any) error { return b.build(fileSystem, "/", root) } @@ -274,7 +274,7 @@ func (b *Builder) WriteFile(fileSystem vfs.FS, path string, contents []byte, per } // runTests recursively runs tests on fileSystem. -func runTests(t *testing.T, fileSystem vfs.FS, name string, test interface{}) { +func runTests(t *testing.T, fileSystem vfs.FS, name string, test any) { t.Helper() prefix := "" if name != "" { @@ -302,11 +302,11 @@ func runTests(t *testing.T, fileSystem vfs.FS, name string, test interface{}) { test[testName](t, fileSystem) }) } - case []interface{}: + case []any: for _, u := range test { runTests(t, fileSystem, name, u) } - case map[string]interface{}: + case map[string]any: testNames := make([]string, 0, len(test)) for testName := range test { testNames = append(testNames, testName) @@ -322,7 +322,7 @@ func runTests(t *testing.T, fileSystem vfs.FS, name string, test interface{}) { } // RunTests recursively runs tests on fileSystem. -func RunTests(t *testing.T, fileSystem vfs.FS, name string, tests ...interface{}) { +func RunTests(t *testing.T, fileSystem vfs.FS, name string, tests ...any) { t.Helper() runTests(t, fileSystem, name, tests) } diff --git a/vfst/vfst_test.go b/vfst/vfst_test.go index ccd198b..ab5fb97 100644 --- a/vfst/vfst_test.go +++ b/vfst/vfst_test.go @@ -17,8 +17,8 @@ func TestBuilderBuild(t *testing.T) { for _, tc := range []struct { name string umask fs.FileMode - root interface{} - tests interface{} + root any + tests any }{ { name: "empty", @@ -28,10 +28,10 @@ func TestBuilderBuild(t *testing.T) { { name: "dir", umask: 0o22, - root: map[string]interface{}{ + root: map[string]any{ "foo": &vfst.Dir{ Perm: 0o755, - Entries: map[string]interface{}{ + Entries: map[string]any{ "bar": "baz", }, }, @@ -65,7 +65,7 @@ func TestBuilderBuild(t *testing.T) { { name: "map_string_empty_interface", umask: 0o22, - root: map[string]interface{}{ + root: map[string]any{ "foo": "bar", "baz": &vfst.File{Perm: 0o755, Contents: []byte("qux")}, "dir": &vfst.Dir{Perm: 0o700}, @@ -111,7 +111,7 @@ func TestBuilderBuild(t *testing.T) { { name: "symlink", umask: 0o22, - root: map[string]interface{}{ + root: map[string]any{ "foo": &vfst.Symlink{Target: "bar"}, }, tests: []vfst.Test{ @@ -134,7 +134,7 @@ func TestBuilderBuild(t *testing.T) { // TestCoverage exercises as much functionality as possible to increase test // coverage. func TestCoverage(t *testing.T) { - fileSystem, cleanup, err := vfst.NewTestFS(map[string]interface{}{ + fileSystem, cleanup, err := vfst.NewTestFS(map[string]any{ "/home/user/.bashrc": "# contents of user's .bashrc\n", "/home/user/empty": []byte{}, "/home/user/symlink": &vfst.Symlink{Target: "empty"}, @@ -142,21 +142,21 @@ func TestCoverage(t *testing.T) { Perm: 0o755, Contents: []byte("echo hello\n"), }, - "/home/user/foo": map[string]interface{}{ - "bar": map[string]interface{}{ + "/home/user/foo": map[string]any{ + "bar": map[string]any{ "baz": "qux", }, }, "/root": &vfst.Dir{ Perm: 0o700, - Entries: map[string]interface{}{ + Entries: map[string]any{ ".bashrc": "# contents of root's .bashrc\n", }, }, }) assert.NoError(t, err) defer cleanup() - vfst.RunTests(t, fileSystem, "", []interface{}{ + vfst.RunTests(t, fileSystem, "", []any{ vfst.TestPath("/home", vfst.TestIsDir(), vfst.TestModePerm(0o755), @@ -173,7 +173,7 @@ func TestCoverage(t *testing.T) { vfst.TestSysNlink(1), ), }, - map[string]interface{}{ + map[string]any{ "home_user_empty": vfst.TestPath("/home/user/empty", vfst.TestModeIsRegular(), vfst.TestModePerm(0o644), @@ -190,7 +190,7 @@ func TestCoverage(t *testing.T) { vfst.TestContentsString("qux"), ), }, - "root": []interface{}{ + "root": []any{ vfst.TestPath("/root", vfst.TestIsDir(), vfst.TestModePerm(0o700), @@ -256,13 +256,13 @@ func TestErrors(t *testing.T) { assert.NoError(t, err) defer cleanup() b := vfst.NewBuilder(vfst.BuilderVerbose(true)) - root := []interface{}{ - map[string]interface{}{ + root := []any{ + map[string]any{ "/home/user/.bashrc": "# bashrc\n", "/home/user/empty": []byte{}, "/home/user/foo": &vfst.Dir{Perm: 0o755}, }, - map[string]interface{}{ + map[string]any{ "/home/user/symlink": &vfst.Symlink{Target: "empty"}, }, } @@ -273,7 +273,7 @@ func TestErrors(t *testing.T) { } func TestGlob(t *testing.T) { - fileSystem, cleanup, err := vfst.NewTestFS(map[string]interface{}{ + fileSystem, cleanup, err := vfst.NewTestFS(map[string]any{ "/home/user/.bash_profile": "# contents of .bash_profile\n", "/home/user/.bashrc": "# contents of .bashrc\n", "/home/user/.zshrc": "# contents of .zshrc\n", @@ -358,7 +358,7 @@ func TestIdempotency(t *testing.T) { assert.NoError(t, err) defer cleanup() b := vfst.NewBuilder(vfst.BuilderVerbose(true)) - root := map[string]interface{}{ + root := map[string]any{ "/home/user/.bashrc": "# bashrc\n", "/home/user/symlink": &vfst.Symlink{Target: ".bashrc"}, }