| 239 | } |
| 240 | |
| 241 | func TestNames(t *testing.T) { |
| 242 | // Tests that all names are without the root directory. |
| 243 | fs, _ := setup(t) |
| 244 | |
| 245 | expected := "file" |
| 246 | fd, err := fs.Create(expected) |
| 247 | if err != nil { |
| 248 | t.Error(err) |
| 249 | } |
| 250 | defer fd.Close() |
| 251 | |
| 252 | if fd.Name() != expected { |
| 253 | t.Errorf("incorrect %s != %s", fd.Name(), expected) |
| 254 | } |
| 255 | if stat, err := fd.Stat(); err != nil || stat.Name() != expected { |
| 256 | t.Errorf("incorrect %s != %s (%v)", stat.Name(), expected, err) |
| 257 | } |
| 258 | |
| 259 | if err := fs.Mkdir("dir", 0o777); err != nil { |
| 260 | t.Error(err) |
| 261 | } |
| 262 | |
| 263 | expected = filepath.Join("dir", "file") |
| 264 | fd, err = fs.Create(expected) |
| 265 | if err != nil { |
| 266 | t.Error(err) |
| 267 | } |
| 268 | defer fd.Close() |
| 269 | |
| 270 | if fd.Name() != expected { |
| 271 | t.Errorf("incorrect %s != %s", fd.Name(), expected) |
| 272 | } |
| 273 | |
| 274 | // os.fd.Stat() returns just base, so do we. |
| 275 | if stat, err := fd.Stat(); err != nil || stat.Name() != filepath.Base(expected) { |
| 276 | t.Errorf("incorrect %s != %s (%v)", stat.Name(), filepath.Base(expected), err) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func TestGlob(t *testing.T) { |
| 281 | // Tests that all names are without the root directory. |