diff options
| author | Shang Ding <rifflegrass@gmail.com> | 2024-02-17 12:21:54 -0600 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-02-20 14:59:55 +0000 |
| commit | ff0b46cfbb0995ea4445c476cf7e0c7643763222 (patch) | |
| tree | 417d82116d035091fade74a04436ac5a12c8207f /src | |
| parent | a3c35430fc0a67b5c8af6d57d21e2881929076ac (diff) | |
| download | go-ff0b46cfbb0995ea4445c476cf7e0c7643763222.tar.xz | |
testing/fstest: return base name from mapfs FileInfo.Name
Change-Id: I5a68389a68875dbb2f6875de3f64f63dd7ca1af7
Reviewed-on: https://go-review.googlesource.com/c/go/+/565055
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/testing/fstest/mapfs.go | 2 | ||||
| -rw-r--r-- | src/testing/fstest/mapfs_test.go | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/testing/fstest/mapfs.go b/src/testing/fstest/mapfs.go index 1409d6202d..f7f8ccd9ec 100644 --- a/src/testing/fstest/mapfs.go +++ b/src/testing/fstest/mapfs.go @@ -150,7 +150,7 @@ type mapFileInfo struct { f *MapFile } -func (i *mapFileInfo) Name() string { return i.name } +func (i *mapFileInfo) Name() string { return path.Base(i.name) } func (i *mapFileInfo) Size() int64 { return int64(len(i.f.Data)) } func (i *mapFileInfo) Mode() fs.FileMode { return i.f.Mode } func (i *mapFileInfo) Type() fs.FileMode { return i.f.Mode.Type() } diff --git a/src/testing/fstest/mapfs_test.go b/src/testing/fstest/mapfs_test.go index c64dc8db5a..6381a2e56c 100644 --- a/src/testing/fstest/mapfs_test.go +++ b/src/testing/fstest/mapfs_test.go @@ -45,3 +45,15 @@ a/b.txt: -rw-rw-rw- t.Errorf("MapFS modes want:\n%s\ngot:\n%s\n", want, got) } } + +func TestMapFSFileInfoName(t *testing.T) { + m := MapFS{ + "path/to/b.txt": &MapFile{}, + } + info, _ := m.Stat("path/to/b.txt") + want := "b.txt" + got := info.Name() + if want != got { + t.Errorf("MapFS FileInfo.Name want:\n%s\ngot:\n%s\n", want, got) + } +} |
