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>
This commit is contained in:
Shang Ding 2024-02-17 12:21:54 -06:00 committed by Gopher Robot
parent a3c35430fc
commit ff0b46cfbb
2 changed files with 13 additions and 1 deletions

View File

@ -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() }

View File

@ -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)
}
}