From ff0b46cfbb0995ea4445c476cf7e0c7643763222 Mon Sep 17 00:00:00 2001 From: Shang Ding Date: Sat, 17 Feb 2024 12:21:54 -0600 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Than McIntosh --- src/testing/fstest/mapfs.go | 2 +- src/testing/fstest/mapfs_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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) + } +} -- 2.48.1