MCPcopy
hub / github.com/syncthing/syncthing / TestIgnores

Function TestIgnores

lib/model/model_test.go:1558–1623  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1556}
1557
1558func TestIgnores(t *testing.T) {
1559 w, cancel := newConfigWrapper(defaultCfg)
1560 defer cancel()
1561 ffs := w.FolderList()[0].Filesystem()
1562 m := setupModel(t, w)
1563 defer cleanupModel(m)
1564
1565 // Assure a clean start state
1566 must(t, ffs.MkdirAll(config.DefaultMarkerName, 0o644))
1567 writeFile(t, ffs, ".stignore", []byte(".*\nquux\n"))
1568
1569 folderIgnoresAlwaysReload(t, m, defaultFolderConfig)
1570
1571 // Make sure the initial scan has finished (ScanFolders is blocking)
1572 m.ScanFolders()
1573
1574 expected := []string{
1575 ".*",
1576 "quux",
1577 }
1578
1579 changeIgnores(t, m, expected)
1580
1581 _, _, err := m.LoadIgnores("doesnotexist")
1582 if err == nil {
1583 t.Error("No error")
1584 }
1585
1586 err = m.SetIgnores("doesnotexist", expected)
1587 if err == nil {
1588 t.Error("No error")
1589 }
1590
1591 // Invalid path, treated like no patterns at all.
1592 fcfg := config.FolderConfiguration{
1593 ID: "fresh", Path: "XXX",
1594 FilesystemType: config.FilesystemTypeFake,
1595 }
1596 ignores := ignore.New(fcfg.Filesystem(), ignore.WithCache(m.cfg.Options().CacheIgnoredFiles))
1597 m.mut.Lock()
1598 m.folderCfgs[fcfg.ID] = fcfg
1599 m.folderIgnores[fcfg.ID] = ignores
1600 m.mut.Unlock()
1601
1602 _, _, err = m.LoadIgnores("fresh")
1603 if err != nil {
1604 t.Error("Got error for inexistent folder path")
1605 }
1606
1607 // Repeat tests with paused folder
1608 pausedDefaultFolderConfig := defaultFolderConfig
1609 pausedDefaultFolderConfig.Paused = true
1610
1611 m.restartFolder(defaultFolderConfig, pausedDefaultFolderConfig, false)
1612 // Here folder initialization is not an issue as a paused folder isn't
1613 // added to the model and thus there is no initial scan happening.
1614
1615 changeIgnores(t, m, expected)

Callers

nothing calls this directly

Calls 15

FilesystemMethod · 0.95
NewFunction · 0.92
WithCacheFunction · 0.92
newConfigWrapperFunction · 0.85
setupModelFunction · 0.85
cleanupModelFunction · 0.85
mustFunction · 0.85
changeIgnoresFunction · 0.85
UnlockMethod · 0.80
restartFolderMethod · 0.80
writeFileFunction · 0.70

Tested by

no test coverage detected