diff options
| author | Shulhan <ms@kilabit.info> | 2021-10-09 19:06:21 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-10-09 22:22:02 +0700 |
| commit | 7e255b79c1c1afaffb1b6f8790f7d77b382acb69 (patch) | |
| tree | cef6f0c1e02ef7d7192fe5bc9f9fa01ef217fef5 /lib/memfs/memfs_test.go | |
| parent | aea6a7b344975770dc5ea03851856b825716b06b (diff) | |
| download | pakakeh.go-7e255b79c1c1afaffb1b6f8790f7d77b382acb69.tar.xz | |
lib/memfs: prefix all error when the method or function names
One of the hardest when multiple packages is used is to detect where
there error happened. For example, if a program return an error io.EOF,
it's hard to detect the exact method or function that caused its,
especially when processing multiple files with network connection.
Diffstat (limited to 'lib/memfs/memfs_test.go')
| -rw-r--r-- | lib/memfs/memfs_test.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/memfs/memfs_test.go b/lib/memfs/memfs_test.go index e45fa330..65da48af 100644 --- a/lib/memfs/memfs_test.go +++ b/lib/memfs/memfs_test.go @@ -66,7 +66,7 @@ func TestNew(t *testing.T) { opts: Options{ Root: afile, }, - expErr: fmt.Sprintf("memfs.New: mount: createRoot %s: must be a directory", afile), + expErr: fmt.Sprintf("New: mount: createRoot: %s must be a directory", afile), }, { desc: "With directory", opts: Options{ @@ -139,14 +139,16 @@ func TestNew(t *testing.T) { }} for _, c := range cases { + t.Log(c.desc) + mfs, err := New(&c.opts) if err != nil { - test.Assert(t, c.desc+": error", c.expErr, err.Error()) + test.Assert(t, "error", c.expErr, err.Error()) continue } gotListNames := mfs.ListNames() - test.Assert(t, c.desc+": names", c.expMapKeys, gotListNames) + test.Assert(t, "ListNames", c.expMapKeys, gotListNames) } } @@ -163,7 +165,7 @@ func TestMemFS_AddFile(t *testing.T) { desc: "With external path is not exist", intPath: "internal/file", extPath: "is/not/exist", - expError: "memfs.AddFile: stat is/not/exist: no such file or directory", + expError: "AddFile: stat is/not/exist: no such file or directory", }, { desc: "With file exist", intPath: "internal/file", @@ -201,9 +203,11 @@ func TestMemFS_AddFile(t *testing.T) { } for _, c := range cases { + t.Log(c.desc) + got, err := mfs.AddFile(c.intPath, c.extPath) if err != nil { - test.Assert(t, c.desc+": error", c.expError, err.Error()) + test.Assert(t, "error", c.expError, err.Error()) continue } |
