]> Cypherpunks repositories - gostls13.git/commitdiff
testing/fstest: return base name from mapfs FileInfo.Name
authorShang Ding <rifflegrass@gmail.com>
Sat, 17 Feb 2024 18:21:54 +0000 (12:21 -0600)
committerGopher Robot <gobot@golang.org>
Tue, 20 Feb 2024 14:59:55 +0000 (14:59 +0000)
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>
src/testing/fstest/mapfs.go
src/testing/fstest/mapfs_test.go

index 1409d6202dd2d06363a3752bc51ce3d5f1d9477d..f7f8ccd9ec890ae020eec5b64fa41b4d0fcc1378 100644 (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() }
index c64dc8db5a8ed97eab57a37fd9009fe6cc07bd35..6381a2e56c99b3f084874500ce89a4494ccd1492 100644 (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)
+       }
+}