mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 15:20:56 +00:00
lib/model: Use functions to generate config (#5513)
This commit is contained in:
parent
93b4597d1a
commit
7bac927ac8
@ -346,7 +346,7 @@ func setupROFolder() *Model {
|
||||
cfg := defaultCfg.Copy()
|
||||
cfg.Folders = append(cfg.Folders, fcfg)
|
||||
|
||||
wrp := config.Wrap("/dev/null", cfg)
|
||||
wrp := createTmpWrapper(cfg)
|
||||
|
||||
db := db.OpenMemory()
|
||||
m := NewModel(wrp, myID, "syncthing", "dev", db, nil)
|
||||
|
@ -51,24 +51,17 @@ func init() {
|
||||
|
||||
defaultFs = fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata")
|
||||
|
||||
defaultFolderConfig = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, "testdata")
|
||||
defaultFolderConfig.Devices = []config.FolderDeviceConfiguration{
|
||||
{DeviceID: myID},
|
||||
{DeviceID: device1},
|
||||
}
|
||||
defaultFolderConfig.FSWatcherEnabled = false
|
||||
defaultCfg = config.Configuration{
|
||||
Version: config.CurrentVersion,
|
||||
Folders: []config.FolderConfiguration{defaultFolderConfig},
|
||||
Devices: []config.DeviceConfiguration{
|
||||
config.NewDeviceConfiguration(myID, "myID"),
|
||||
config.NewDeviceConfiguration(device1, "device1"),
|
||||
},
|
||||
Options: config.OptionsConfiguration{
|
||||
// Don't remove temporaries directly on startup
|
||||
KeepTemporariesH: 1,
|
||||
},
|
||||
}
|
||||
defaultFolderConfig = testFolderConfig("testdata")
|
||||
|
||||
defaultCfgWrapper = createTmpWrapper(config.New(myID))
|
||||
defaultCfgWrapper.SetDevice(config.NewDeviceConfiguration(device1, "device1"))
|
||||
defaultCfgWrapper.SetFolder(defaultFolderConfig)
|
||||
opts := defaultCfgWrapper.Options()
|
||||
opts.KeepTemporariesH = 1
|
||||
defaultCfgWrapper.SetOptions(opts)
|
||||
|
||||
defaultCfg = defaultCfgWrapper.RawCopy()
|
||||
|
||||
defaultAutoAcceptCfg = config.Configuration{
|
||||
Devices: []config.DeviceConfiguration{
|
||||
{
|
||||
@ -139,8 +132,6 @@ func TestMain(m *testing.M) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defaultCfgWrapper = createTmpWrapper(defaultCfg)
|
||||
|
||||
exitCode := m.Run()
|
||||
|
||||
os.Remove(defaultCfgWrapper.ConfigPath())
|
||||
@ -2591,7 +2582,7 @@ func TestIssue2782(t *testing.T) {
|
||||
|
||||
db := db.OpenMemory()
|
||||
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
|
||||
m.AddFolder(config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, "~/"+testName+"/synclink/"))
|
||||
m.AddFolder(testFolderConfig("~/" + testName + "/synclink/"))
|
||||
m.StartFolder("default")
|
||||
m.ServeBackground()
|
||||
defer m.Stop()
|
||||
@ -3826,7 +3817,7 @@ func TestRequestLimit(t *testing.T) {
|
||||
dev, _ := wrapper.Device(device1)
|
||||
dev.MaxRequestKiB = 1
|
||||
wrapper.SetDevice(dev)
|
||||
m, _, wrapper := setupModelWithConnectionManual(wrapper.RawCopy())
|
||||
m, _ := setupModelWithConnectionFromWrapper(wrapper)
|
||||
defer m.Stop()
|
||||
defer testOs.Remove(wrapper.ConfigPath())
|
||||
|
||||
|
@ -330,15 +330,11 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
|
||||
testOs := &fatalOs{t}
|
||||
|
||||
tmpDir := createTmpDir()
|
||||
cfg := defaultCfgWrapper.RawCopy()
|
||||
cfg.Folders[0] = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
|
||||
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
|
||||
{DeviceID: myID},
|
||||
{DeviceID: device1},
|
||||
}
|
||||
cfg.Folders[0].Type = ft
|
||||
m, fc, w := setupModelWithConnectionManual(cfg)
|
||||
w := createTmpWrapper(defaultCfgWrapper.RawCopy())
|
||||
fcfg, tmpDir := testFolderConfigTmp()
|
||||
fcfg.Type = ft
|
||||
w.SetFolder(fcfg)
|
||||
m, fc := setupModelWithConnectionFromWrapper(w)
|
||||
defer func() {
|
||||
m.Stop()
|
||||
testOs.RemoveAll(tmpDir)
|
||||
@ -350,7 +346,7 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
// because we might be changing the files on disk often enough that the
|
||||
// mtimes will be unreliable to determine change status.
|
||||
m.fmut.Lock()
|
||||
m.folderIgnores["default"] = ignore.New(cfg.Folders[0].Filesystem(), ignore.WithChangeDetector(newAlwaysChanged()))
|
||||
m.folderIgnores["default"] = ignore.New(fcfg.Filesystem(), ignore.WithChangeDetector(newAlwaysChanged()))
|
||||
m.fmut.Unlock()
|
||||
|
||||
if err := m.SetIgnores("default", []string{"*ignored*"}); err != nil {
|
||||
@ -723,25 +719,30 @@ func TestRequestSymlinkWindows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setupModelWithConnection() (*Model, *fakeConnection, string, *config.Wrapper) {
|
||||
func testFolderConfigTmp() (config.FolderConfiguration, string) {
|
||||
tmpDir := createTmpDir()
|
||||
cfg := defaultCfgWrapper.RawCopy()
|
||||
cfg.Folders[0] = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
|
||||
cfg.Folders[0].FSWatcherEnabled = false
|
||||
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
|
||||
{DeviceID: myID},
|
||||
{DeviceID: device1},
|
||||
}
|
||||
m, fc, w := setupModelWithConnectionManual(cfg)
|
||||
return testFolderConfig(tmpDir), tmpDir
|
||||
}
|
||||
|
||||
func testFolderConfig(path string) config.FolderConfiguration {
|
||||
cfg := config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, path)
|
||||
cfg.FSWatcherEnabled = false
|
||||
cfg.Devices = append(cfg.Devices, config.FolderDeviceConfiguration{DeviceID: device1})
|
||||
return cfg
|
||||
}
|
||||
|
||||
func setupModelWithConnection() (*Model, *fakeConnection, string, *config.Wrapper) {
|
||||
w := createTmpWrapper(defaultCfgWrapper.RawCopy())
|
||||
fcfg, tmpDir := testFolderConfigTmp()
|
||||
w.SetFolder(fcfg)
|
||||
m, fc := setupModelWithConnectionFromWrapper(w)
|
||||
return m, fc, tmpDir, w
|
||||
}
|
||||
|
||||
func setupModelWithConnectionManual(cfg config.Configuration) (*Model, *fakeConnection, *config.Wrapper) {
|
||||
w := createTmpWrapper(cfg)
|
||||
|
||||
func setupModelWithConnectionFromWrapper(w *config.Wrapper) (*Model, *fakeConnection) {
|
||||
db := db.OpenMemory()
|
||||
m := NewModel(w, myID, "syncthing", "dev", db, nil)
|
||||
m.AddFolder(cfg.Folders[0])
|
||||
m.AddFolder(w.FolderList()[0])
|
||||
m.ServeBackground()
|
||||
m.StartFolder("default")
|
||||
|
||||
@ -750,7 +751,7 @@ func setupModelWithConnectionManual(cfg config.Configuration) (*Model, *fakeConn
|
||||
|
||||
m.ScanFolder("default")
|
||||
|
||||
return m, fc, w
|
||||
return m, fc
|
||||
}
|
||||
|
||||
func createTmpDir() string {
|
||||
|
Loading…
Reference in New Issue
Block a user