2019-05-10 11:33:45 +00:00
|
|
|
// Copyright (C) 2016 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2020-11-17 12:19:04 +00:00
|
|
|
"context"
|
2019-05-19 12:29:07 +00:00
|
|
|
"os"
|
2020-01-21 17:23:08 +00:00
|
|
|
"testing"
|
2019-05-18 06:52:50 +00:00
|
|
|
"time"
|
2019-05-10 11:33:45 +00:00
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/lib/config"
|
|
|
|
"github.com/syncthing/syncthing/lib/db"
|
2019-11-29 08:11:52 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/db/backend"
|
2019-08-15 14:29:37 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/events"
|
2019-05-10 11:33:45 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
2020-05-06 06:34:54 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/ignore"
|
2019-05-10 11:33:45 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2023-07-29 08:24:44 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol/mocks"
|
2020-02-12 06:47:05 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/rand"
|
2019-05-10 11:33:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-01-15 14:43:34 +00:00
|
|
|
myID, device1, device2 protocol.DeviceID
|
|
|
|
defaultCfgWrapper config.Wrapper
|
|
|
|
defaultCfgWrapperCancel context.CancelFunc
|
|
|
|
defaultFolderConfig config.FolderConfiguration
|
|
|
|
defaultCfg config.Configuration
|
|
|
|
defaultAutoAcceptCfg config.Configuration
|
2023-07-29 08:24:44 +00:00
|
|
|
device1Conn = &mocks.Connection{}
|
|
|
|
device2Conn = &mocks.Connection{}
|
2019-05-10 11:33:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
myID, _ = protocol.DeviceIDFromString("ZNWFSWE-RWRV2BD-45BLMCV-LTDE2UR-4LJDW6J-R5BPWEB-TXD27XJ-IZF5RA4")
|
|
|
|
device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
|
|
|
|
device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
|
2023-07-29 08:24:44 +00:00
|
|
|
device1Conn.DeviceIDReturns(device1)
|
2023-09-06 10:52:01 +00:00
|
|
|
device1Conn.ConnectionIDReturns(rand.String(16))
|
2023-07-29 08:24:44 +00:00
|
|
|
device2Conn.DeviceIDReturns(device2)
|
2023-09-06 10:52:01 +00:00
|
|
|
device2Conn.ConnectionIDReturns(rand.String(16))
|
2019-05-10 11:33:45 +00:00
|
|
|
|
2023-05-03 08:25:36 +00:00
|
|
|
cfg := config.New(myID)
|
|
|
|
cfg.Options.MinHomeDiskFree.Value = 0 // avoids unnecessary free space checks
|
|
|
|
defaultCfgWrapper, defaultCfgWrapperCancel = newConfigWrapper(cfg)
|
2021-02-04 20:10:41 +00:00
|
|
|
|
2023-05-03 08:25:36 +00:00
|
|
|
defaultFolderConfig = newFolderConfig()
|
2019-05-10 11:33:45 +00:00
|
|
|
|
2021-01-15 14:43:34 +00:00
|
|
|
waiter, _ := defaultCfgWrapper.Modify(func(cfg *config.Configuration) {
|
2021-02-04 20:10:41 +00:00
|
|
|
cfg.SetDevice(newDeviceConfiguration(cfg.Defaults.Device, device1, "device1"))
|
2021-01-15 14:43:34 +00:00
|
|
|
cfg.SetFolder(defaultFolderConfig)
|
|
|
|
cfg.Options.KeepTemporariesH = 1
|
|
|
|
})
|
|
|
|
waiter.Wait()
|
2019-05-10 11:33:45 +00:00
|
|
|
|
|
|
|
defaultCfg = defaultCfgWrapper.RawCopy()
|
|
|
|
|
|
|
|
defaultAutoAcceptCfg = config.Configuration{
|
2020-11-09 14:33:32 +00:00
|
|
|
Version: config.CurrentVersion,
|
2019-05-10 11:33:45 +00:00
|
|
|
Devices: []config.DeviceConfiguration{
|
|
|
|
{
|
|
|
|
DeviceID: myID, // self
|
|
|
|
},
|
|
|
|
{
|
|
|
|
DeviceID: device1,
|
|
|
|
AutoAcceptFolders: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
DeviceID: device2,
|
|
|
|
AutoAcceptFolders: true,
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 20:10:41 +00:00
|
|
|
Defaults: config.Defaults{
|
|
|
|
Folder: config.FolderConfiguration{
|
2023-05-03 08:25:36 +00:00
|
|
|
FilesystemType: fs.FilesystemTypeFake,
|
|
|
|
Path: rand.String(32),
|
2021-02-04 20:10:41 +00:00
|
|
|
},
|
2019-05-10 11:33:45 +00:00
|
|
|
},
|
2023-05-03 08:25:36 +00:00
|
|
|
Options: config.OptionsConfiguration{
|
|
|
|
MinHomeDiskFree: config.Size{}, // avoids unnecessary free space checks
|
|
|
|
},
|
2019-05-10 11:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-03 08:25:36 +00:00
|
|
|
func newConfigWrapper(cfg config.Configuration) (config.Wrapper, context.CancelFunc) {
|
|
|
|
wrapper := config.Wrap("", cfg, myID, events.NoopLogger)
|
2021-03-11 13:51:00 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go wrapper.Serve(ctx)
|
|
|
|
return wrapper, cancel
|
2021-01-15 14:43:34 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 08:25:36 +00:00
|
|
|
func newDefaultCfgWrapper() (config.Wrapper, config.FolderConfiguration, context.CancelFunc) {
|
|
|
|
w, cancel := newConfigWrapper(defaultCfgWrapper.RawCopy())
|
|
|
|
fcfg := newFolderConfig()
|
2021-01-15 14:43:34 +00:00
|
|
|
_, _ = w.Modify(func(cfg *config.Configuration) {
|
|
|
|
cfg.SetFolder(fcfg)
|
|
|
|
})
|
|
|
|
return w, fcfg, cancel
|
2019-05-10 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 08:25:36 +00:00
|
|
|
func newFolderConfig() config.FolderConfiguration {
|
2021-02-04 20:10:41 +00:00
|
|
|
cfg := newFolderConfiguration(defaultCfgWrapper, "default", "default", fs.FilesystemTypeFake, rand.String(32)+"?content=true")
|
2020-02-12 06:47:05 +00:00
|
|
|
cfg.FSWatcherEnabled = false
|
|
|
|
cfg.Devices = append(cfg.Devices, config.FolderDeviceConfiguration{DeviceID: device1})
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2021-01-15 14:43:34 +00:00
|
|
|
func setupModelWithConnection(t testing.TB) (*testModel, *fakeConnection, config.FolderConfiguration, context.CancelFunc) {
|
2020-12-21 11:59:22 +00:00
|
|
|
t.Helper()
|
2023-05-03 08:25:36 +00:00
|
|
|
w, fcfg, cancel := newDefaultCfgWrapper()
|
2020-12-21 11:59:22 +00:00
|
|
|
m, fc := setupModelWithConnectionFromWrapper(t, w)
|
2021-01-15 14:43:34 +00:00
|
|
|
return m, fc, fcfg, cancel
|
2019-05-10 11:33:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 11:59:22 +00:00
|
|
|
func setupModelWithConnectionFromWrapper(t testing.TB, w config.Wrapper) (*testModel, *fakeConnection) {
|
|
|
|
t.Helper()
|
|
|
|
m := setupModel(t, w)
|
2019-05-10 11:33:45 +00:00
|
|
|
|
2021-05-16 15:23:27 +00:00
|
|
|
fc := addFakeConn(m, device1, "default")
|
2019-05-10 11:33:45 +00:00
|
|
|
fc.folder = "default"
|
|
|
|
|
|
|
|
_ = m.ScanFolder("default")
|
|
|
|
|
|
|
|
return m, fc
|
|
|
|
}
|
|
|
|
|
2020-12-21 11:59:22 +00:00
|
|
|
func setupModel(t testing.TB, w config.Wrapper) *testModel {
|
|
|
|
t.Helper()
|
2023-09-06 10:52:01 +00:00
|
|
|
m := newModel(t, w, myID, nil)
|
2019-05-10 11:33:45 +00:00
|
|
|
m.ServeBackground()
|
2020-11-17 12:19:04 +00:00
|
|
|
<-m.started
|
2019-05-10 11:33:45 +00:00
|
|
|
|
|
|
|
m.ScanFolders()
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:19:04 +00:00
|
|
|
type testModel struct {
|
|
|
|
*model
|
2021-03-07 12:43:22 +00:00
|
|
|
t testing.TB
|
2020-11-17 12:19:04 +00:00
|
|
|
cancel context.CancelFunc
|
|
|
|
evCancel context.CancelFunc
|
|
|
|
stopped chan struct{}
|
|
|
|
}
|
|
|
|
|
2023-09-06 10:52:01 +00:00
|
|
|
func newModel(t testing.TB, cfg config.Wrapper, id protocol.DeviceID, protectedFiles []string) *testModel {
|
2020-12-21 11:59:22 +00:00
|
|
|
t.Helper()
|
2019-08-15 14:29:37 +00:00
|
|
|
evLogger := events.NewLogger()
|
2020-12-21 11:59:22 +00:00
|
|
|
ldb, err := db.NewLowlevel(backend.OpenMemory(), evLogger)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-09-06 10:52:01 +00:00
|
|
|
m := NewModel(cfg, id, ldb, protectedFiles, evLogger, protocol.NewKeyGenerator()).(*model)
|
2020-11-17 12:19:04 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go evLogger.Serve(ctx)
|
|
|
|
return &testModel{
|
|
|
|
model: m,
|
|
|
|
evCancel: cancel,
|
|
|
|
stopped: make(chan struct{}),
|
2021-03-07 12:43:22 +00:00
|
|
|
t: t,
|
2020-11-17 12:19:04 +00:00
|
|
|
}
|
2019-05-19 12:29:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 12:19:04 +00:00
|
|
|
func (m *testModel) ServeBackground() {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
m.cancel = cancel
|
|
|
|
go func() {
|
|
|
|
m.model.Serve(ctx)
|
|
|
|
close(m.stopped)
|
|
|
|
}()
|
|
|
|
<-m.started
|
|
|
|
}
|
|
|
|
|
2021-03-07 12:43:22 +00:00
|
|
|
func (m *testModel) testAvailability(folder string, file protocol.FileInfo, block protocol.BlockInfo) []Availability {
|
|
|
|
av, err := m.model.Availability(folder, file, block)
|
|
|
|
must(m.t, err)
|
|
|
|
return av
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *testModel) testCurrentFolderFile(folder string, file string) (protocol.FileInfo, bool) {
|
|
|
|
f, ok, err := m.model.CurrentFolderFile(folder, file)
|
|
|
|
must(m.t, err)
|
|
|
|
return f, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *testModel) testCompletion(device protocol.DeviceID, folder string) FolderCompletion {
|
2021-06-05 15:01:23 +00:00
|
|
|
comp, err := m.Completion(device, folder)
|
2021-03-07 12:43:22 +00:00
|
|
|
must(m.t, err)
|
|
|
|
return comp
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:19:04 +00:00
|
|
|
func cleanupModel(m *testModel) {
|
|
|
|
if m.cancel != nil {
|
|
|
|
m.cancel()
|
|
|
|
<-m.stopped
|
|
|
|
}
|
|
|
|
m.evCancel()
|
2019-05-19 12:29:07 +00:00
|
|
|
m.db.Close()
|
|
|
|
os.Remove(m.cfg.ConfigPath())
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:19:04 +00:00
|
|
|
func cleanupModelAndRemoveDir(m *testModel, dir string) {
|
2019-05-19 12:29:07 +00:00
|
|
|
cleanupModel(m)
|
|
|
|
os.RemoveAll(dir)
|
|
|
|
}
|
|
|
|
|
2019-05-18 06:52:50 +00:00
|
|
|
type alwaysChangedKey struct {
|
|
|
|
fs fs.Filesystem
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// alwaysChanges is an ignore.ChangeDetector that always returns true on Changed()
|
|
|
|
type alwaysChanged struct {
|
|
|
|
seen map[alwaysChangedKey]struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAlwaysChanged() *alwaysChanged {
|
|
|
|
return &alwaysChanged{
|
|
|
|
seen: make(map[alwaysChangedKey]struct{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *alwaysChanged) Remember(fs fs.Filesystem, name string, _ time.Time) {
|
|
|
|
c.seen[alwaysChangedKey{fs, name}] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *alwaysChanged) Reset() {
|
|
|
|
c.seen = make(map[alwaysChangedKey]struct{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *alwaysChanged) Seen(fs fs.Filesystem, name string) bool {
|
|
|
|
_, ok := c.seen[alwaysChangedKey{fs, name}]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2023-07-18 14:34:50 +00:00
|
|
|
func (*alwaysChanged) Changed() bool {
|
2019-05-18 06:52:50 +00:00
|
|
|
return true
|
|
|
|
}
|
2020-01-21 17:23:08 +00:00
|
|
|
|
|
|
|
func localSize(t *testing.T, m Model, folder string) db.Counts {
|
|
|
|
t.Helper()
|
|
|
|
snap := dbSnapshot(t, m, folder)
|
|
|
|
defer snap.Release()
|
|
|
|
return snap.LocalSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func globalSize(t *testing.T, m Model, folder string) db.Counts {
|
|
|
|
t.Helper()
|
|
|
|
snap := dbSnapshot(t, m, folder)
|
|
|
|
defer snap.Release()
|
|
|
|
return snap.GlobalSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func receiveOnlyChangedSize(t *testing.T, m Model, folder string) db.Counts {
|
|
|
|
t.Helper()
|
|
|
|
snap := dbSnapshot(t, m, folder)
|
|
|
|
defer snap.Release()
|
|
|
|
return snap.ReceiveOnlyChangedSize()
|
|
|
|
}
|
|
|
|
|
2021-06-05 15:01:23 +00:00
|
|
|
func needSizeLocal(t *testing.T, m Model, folder string) db.Counts {
|
2020-01-21 17:23:08 +00:00
|
|
|
t.Helper()
|
|
|
|
snap := dbSnapshot(t, m, folder)
|
|
|
|
defer snap.Release()
|
2020-05-11 13:07:06 +00:00
|
|
|
return snap.NeedSize(protocol.LocalDeviceID)
|
2020-01-21 17:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func dbSnapshot(t *testing.T, m Model, folder string) *db.Snapshot {
|
|
|
|
t.Helper()
|
|
|
|
snap, err := m.DBSnapshot(folder)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return snap
|
|
|
|
}
|
2020-05-06 06:34:54 +00:00
|
|
|
|
2021-03-07 12:43:22 +00:00
|
|
|
func fsetSnapshot(t *testing.T, fset *db.FileSet) *db.Snapshot {
|
|
|
|
t.Helper()
|
|
|
|
snap, err := fset.Snapshot()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
2020-05-06 06:34:54 +00:00
|
|
|
// Reach in and update the ignore matcher to one that always does
|
|
|
|
// reloads when asked to, instead of checking file mtimes. This is
|
|
|
|
// because we will be changing the files on disk often enough that the
|
|
|
|
// mtimes will be unreliable to determine change status.
|
2020-12-21 11:59:22 +00:00
|
|
|
func folderIgnoresAlwaysReload(t testing.TB, m *testModel, fcfg config.FolderConfiguration) {
|
|
|
|
t.Helper()
|
2020-05-06 06:34:54 +00:00
|
|
|
m.removeFolder(fcfg)
|
2022-01-31 09:12:52 +00:00
|
|
|
fset := newFileSet(t, fcfg.ID, m.db)
|
2022-04-10 18:55:05 +00:00
|
|
|
ignores := ignore.New(fcfg.Filesystem(nil), ignore.WithCache(true), ignore.WithChangeDetector(newAlwaysChanged()))
|
2020-05-06 06:34:54 +00:00
|
|
|
m.fmut.Lock()
|
|
|
|
m.addAndStartFolderLockedWithIgnores(fcfg, fset, ignores)
|
|
|
|
m.fmut.Unlock()
|
|
|
|
}
|
2020-10-21 09:51:53 +00:00
|
|
|
|
|
|
|
func basicClusterConfig(local, remote protocol.DeviceID, folders ...string) protocol.ClusterConfig {
|
|
|
|
var cc protocol.ClusterConfig
|
|
|
|
for _, folder := range folders {
|
|
|
|
cc.Folders = append(cc.Folders, protocol.Folder{
|
|
|
|
ID: folder,
|
|
|
|
Devices: []protocol.Device{
|
|
|
|
{
|
|
|
|
ID: local,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: remote,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return cc
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:19:04 +00:00
|
|
|
func localIndexUpdate(m *testModel, folder string, fs []protocol.FileInfo) {
|
2020-10-21 09:51:53 +00:00
|
|
|
m.fmut.RLock()
|
|
|
|
fset := m.folderFiles[folder]
|
|
|
|
m.fmut.RUnlock()
|
|
|
|
|
|
|
|
fset.Update(protocol.LocalDeviceID, fs)
|
|
|
|
seq := fset.Sequence(protocol.LocalDeviceID)
|
|
|
|
filenames := make([]string, len(fs))
|
|
|
|
for i, file := range fs {
|
|
|
|
filenames[i] = file.Name
|
|
|
|
}
|
|
|
|
m.evLogger.Log(events.LocalIndexUpdated, map[string]interface{}{
|
|
|
|
"folder": folder,
|
|
|
|
"items": len(fs),
|
|
|
|
"filenames": filenames,
|
|
|
|
"sequence": seq,
|
|
|
|
"version": seq, // legacy for sequence
|
|
|
|
})
|
|
|
|
}
|
2020-12-21 11:59:22 +00:00
|
|
|
|
2021-02-04 20:10:41 +00:00
|
|
|
func newDeviceConfiguration(defaultCfg config.DeviceConfiguration, id protocol.DeviceID, name string) config.DeviceConfiguration {
|
|
|
|
cfg := defaultCfg.Copy()
|
|
|
|
cfg.DeviceID = id
|
|
|
|
cfg.Name = name
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2022-01-31 09:12:52 +00:00
|
|
|
func newFileSet(t testing.TB, folder string, ldb *db.Lowlevel) *db.FileSet {
|
2020-12-21 11:59:22 +00:00
|
|
|
t.Helper()
|
2022-01-31 09:12:52 +00:00
|
|
|
fset, err := db.NewFileSet(folder, ldb)
|
2020-12-21 11:59:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return fset
|
|
|
|
}
|
2021-01-15 14:43:34 +00:00
|
|
|
|
|
|
|
func replace(t testing.TB, w config.Wrapper, to config.Configuration) {
|
|
|
|
t.Helper()
|
|
|
|
waiter, err := w.Modify(func(cfg *config.Configuration) {
|
|
|
|
*cfg = to
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
waiter.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func pauseFolder(t testing.TB, w config.Wrapper, id string, paused bool) {
|
|
|
|
t.Helper()
|
|
|
|
waiter, err := w.Modify(func(cfg *config.Configuration) {
|
|
|
|
_, i, _ := cfg.Folder(id)
|
|
|
|
cfg.Folders[i].Paused = paused
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
waiter.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func setFolder(t testing.TB, w config.Wrapper, fcfg config.FolderConfiguration) {
|
|
|
|
t.Helper()
|
|
|
|
waiter, err := w.Modify(func(cfg *config.Configuration) {
|
|
|
|
cfg.SetFolder(fcfg)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
waiter.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func pauseDevice(t testing.TB, w config.Wrapper, id protocol.DeviceID, paused bool) {
|
|
|
|
t.Helper()
|
|
|
|
waiter, err := w.Modify(func(cfg *config.Configuration) {
|
|
|
|
_, i, _ := cfg.Device(id)
|
|
|
|
cfg.Devices[i].Paused = paused
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
waiter.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func setDevice(t testing.TB, w config.Wrapper, device config.DeviceConfiguration) {
|
|
|
|
t.Helper()
|
|
|
|
waiter, err := w.Modify(func(cfg *config.Configuration) {
|
|
|
|
cfg.SetDevice(device)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
waiter.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func addDevice2(t testing.TB, w config.Wrapper, fcfg config.FolderConfiguration) {
|
|
|
|
waiter, err := w.Modify(func(cfg *config.Configuration) {
|
2021-02-04 20:10:41 +00:00
|
|
|
cfg.SetDevice(newDeviceConfiguration(cfg.Defaults.Device, device2, "device2"))
|
2021-01-15 14:43:34 +00:00
|
|
|
fcfg.Devices = append(fcfg.Devices, config.FolderDeviceConfiguration{DeviceID: device2})
|
|
|
|
cfg.SetFolder(fcfg)
|
|
|
|
})
|
|
|
|
must(t, err)
|
|
|
|
waiter.Wait()
|
|
|
|
}
|
2021-11-10 08:46:21 +00:00
|
|
|
|
|
|
|
func writeFile(t testing.TB, filesystem fs.Filesystem, name string, data []byte) {
|
|
|
|
t.Helper()
|
|
|
|
fd, err := filesystem.Create(name)
|
|
|
|
must(t, err)
|
|
|
|
defer fd.Close()
|
|
|
|
_, err = fd.Write(data)
|
|
|
|
must(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeFilePerm(t testing.TB, filesystem fs.Filesystem, name string, data []byte, perm fs.FileMode) {
|
|
|
|
t.Helper()
|
|
|
|
writeFile(t, filesystem, name, data)
|
|
|
|
must(t, filesystem.Chmod(name, perm))
|
|
|
|
}
|