MCPcopy
hub / github.com/syncthing/syncthing / TestNames

Function TestNames

lib/fs/basicfs_test.go:241–278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func 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
280func TestGlob(t *testing.T) {
281 // Tests that all names are without the root directory.

Callers

nothing calls this directly

Calls 7

setupFunction · 0.85
CreateMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65
StatMethod · 0.65
MkdirMethod · 0.65

Tested by

no test coverage detected